jkteater
asked on
I want to add a third element to my ArrayList
Right Now I am getting a selected object from the user.
selectedDataset
I am then traversing the object and getting another object
selectedRevision
I have written a method that adds them to a ArrayList
This is where I am creating the instance to the ArrayList
This is the RevDataset Class
I am wanting to add another element, which will be a string value called revComment to the arrayList as it builds.
So instead of the ArrayList looking like this.
ArrayList (tcRevision, selectedDataset)
I want it to look like this
ArrayList (tcRevision, selectedDataset, revComment)
revComment will have no value just a null String. I thought that adding the String revComment should be in the RevDataset class that I posted above. I'm just not sure how to go about making the changes.
selectedDataset
I am then traversing the object and getting another object
selectedRevision
I have written a method that adds them to a ArrayList
public void add(TCComponentItemRevision tcRevision, TCComponentDataset selectedDataset){
RevDataset pp = new RevDataset(tcRevision,selectedDataset);
if(!rds.contains(pp))rds.add(pp);
}// end add
This is where I am creating the instance to the ArrayList
static ArrayList<RevDataset> rds = new ArrayList<RevDataset>();
This is the RevDataset Class
public class RevDataset {
TCComponentItemRevision rev;
TCComponentDataset componentdataset;
//////////////////////////////////////////////////////////////////////////
// //
// Constructor //
// //
//////////////////////////////////////////////////////////////////////////
public RevDataset(TCComponentItemRevision tcRevision, TCComponentDataset selectedDataset) {
rev = tcRevision;
componentdataset = selectedDataset;
}// end Constructor
//////////////////////////////////////////////////////////////////////////
// //
// getDataset() //
// //
//////////////////////////////////////////////////////////////////////////
public TCComponent getDataset() {
return componentdataset;
}// end getDataset()
//////////////////////////////////////////////////////////////////////////
// //
// getRev() //
// //
//////////////////////////////////////////////////////////////////////////
public TCComponent getRev() {
return rev;
}//end getRev()
//////////////////////////////////////////////////////////////////////////
// //
// equals() //
// //
//////////////////////////////////////////////////////////////////////////
public boolean equals(Object o){
RevDataset p = (RevDataset) o;
if(rev.equals(p.getRev()) && componentdataset.equals(p.getDataset())) {
return true;
}
else {
return false;
}
}// end equals()
I am wanting to add another element, which will be a string value called revComment to the arrayList as it builds.
So instead of the ArrayList looking like this.
ArrayList (tcRevision, selectedDataset)
I want it to look like this
ArrayList (tcRevision, selectedDataset, revComment)
revComment will have no value just a null String. I thought that adding the String revComment should be in the RevDataset class that I posted above. I'm just not sure how to go about making the changes.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This what I tried please let me know if it is way of base and not good programming
In the class the users are selecting objects I created a String Varaible
then I added it to the method that is adding the selections to the arraylist
so in the method it self I added
then in the RevDataset class
Constructor
Then I created a method to get the value
Does this look OK?
In the class the users are selecting objects I created a String Varaible
String revComment;
then I added it to the method that is adding the selections to the arraylist
myModel.add(tcRevision,selectedDataset, revComment);
so in the method it self I added
public void add(TCComponentItemRevision tcRevision, TCComponentDataset selectedDataset, String revComment){
RevDataset pp = new RevDataset(tcRevision,selectedDataset,revComment);
if(!rds.contains(pp))rds.add(pp);
}// end add
then in the RevDataset class
String rComment;
Constructor
public RevDataset(TCComponentItemRevision tcRevision, TCComponentDataset selectedDataset, String revComment) {
rev = tcRevision;
componentdataset = selectedDataset;
rComment = revComment;
}// end Constructor
Then I created a method to get the value
public String getRevComment() {
return rComment;
}
Does this look OK?
>>Does this look OK?
Yes. That's exactly what i meant by my comment
Yes. That's exactly what i meant by my comment
:)
ASKER
The main problem I have, is I have not had a Java class or done any Java programming in about 8 years. I had been doing lotus notes programming, but the company is no longer using lotus. So I was given this large java project that was already half done. It is like re-learning Java but on a very fast paced schedule.
So I don't really always understand the suggestions that is given or how to phrase the question so where it makes sense to you guys.
All I really know is that I have to add a String value to my ArrayList (tcRevision, selectedDataset, revComment)
I really don't know the best way to add the value or where I should add it.