• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem  RSS feed

 
vasu maj
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting a list of valueobjects from the caller of my method. The value objects are maps ( keys and values). I have to put all the columns of all valueobjects into an array (columnsArray) and the values into another (valuesArray). I am doing something like this..




After getting the arrayllists of columsn and values I am converting them into arrays like this ..



But in the resulting arrays I am finding that the values of the first vaule object are being repeated twice instead of the values from the second valueobject added after the first set of values are added.

For example the first ValueObject is like this :

("key1", "999999");
("key2", "11211");
("key3", "55552");
("key4", "11114");
("key5", "19000212123311");

and the second ValueObject is
("key1", "88888");
("key2", "22222");
("key3", "33333");
("key4", "444444");
("key5", "555555");

The resulting array of values at the end is showing up like this ..

("999999","11211","55552", "11114", "19000212123311","999999","11211","55552", "11114", "19000212123311") instead of

("999999","11211","55552", "11114", "19000212123311","88888","22222","33333"....etc)


the array of keys is ok with two sets of same keys repeated one set after the other.


Thanks,

Vasu

[ October 20, 2004: Message edited by: vasu maj ]
[ October 20, 2004: Message edited by: vasu maj ]
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would you mind posting some (or all) of the code for the ValueObject class? Also, in my experience, I've found that it's often best to not use parallel arrays. In such a case, you end up with corresponding data in two separate data containers. If one container changes, you are obliged to change the other in order to maintain the relationship. This simply leads to extra work on your part.

Instead, I often prefer to create a simple class that can contain both pieces of data and then store instances of those classes in a single array. That way, corresponding data is always kept together within a single, encapsulated, object.
 
vasu maj
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Thanks for the suggestion. I see what you are saying.



Vasu
 
vasu maj
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found the problem. Know what it is? The frikking caller is passing duplicate values, not different valuesobjects as suggested.


Thanks Corey. I am changing the design to have only one object now.


Vasu
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a case like this, if I'm making a class for the sole purpose of keeping associated data together, I'll sometimes make those fields public in the class. This has the effect of making the class nothing but a dumb data struct. Anyone see a problem with that? I've done it a number of times simply because it makes my life easy but there's something about not encapsulating my data properly that always makes me feel uneasy. If you're really worried about it, you can, of course, make the data fields private and generate getter and setter methods for them.
 
vasu maj
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!