?
Solved

I want to add a third element to my ArrayList

Posted on 2011-10-28
5
Medium Priority
?
385 Views
Last Modified: 2012-05-12
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.






0
Comment
Question by:jkteater
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 37045052
If you consider the comment as intrinsic to RevDataset, then add it as a field of that class
0
 

Author Comment

by:jkteater
ID: 37045312
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.
0
 

Author Comment

by:jkteater
ID: 37045539
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?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37045909
>>Does this look OK?

Yes. That's exactly what i meant by my comment
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37046298
:)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question