Link to home
Start Free TrialLog in
Avatar of jkteater
jkteaterFlag for United States of America

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

 public void add(TCComponentItemRevision tcRevision, TCComponentDataset selectedDataset){
     	   RevDataset pp = new RevDataset(tcRevision,selectedDataset);
	   if(!rds.contains(pp))rds.add(pp); 
	  
   }// end add

Open in new window


This is where I am creating the instance to the ArrayList

static ArrayList<RevDataset> rds = new ArrayList<RevDataset>();

Open in new window


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()
   

Open in new window


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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jkteater

ASKER

I really don't consider it a instance.  I just need to get the string in to the ArrayList.  I just thought where RevDataset is kind of formatting the ArrayList that would be the place to add the value.  

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.
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

String revComment;

Open in new window


then I added it to the method that is adding the selections to the arraylist

myModel.add(tcRevision,selectedDataset, revComment);

Open in new window


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

Open in new window


then in the RevDataset class

String rComment;

Open in new window


Constructor

public RevDataset(TCComponentItemRevision tcRevision, TCComponentDataset selectedDataset, String revComment) {
      rev = tcRevision;
      componentdataset = selectedDataset;
      rComment = revComment;
      
   }// end Constructor

Open in new window


Then I created a method to get the value

public String getRevComment() {
      return rComment;
   }

Open in new window


Does this look OK?
>>Does this look OK?

Yes. That's exactly what i meant by my comment
:)