aspose file tools
The moose likes Java in General and the fly likes sorting a collection other collections should change Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "sorting a collection other collections should change" Watch "sorting a collection other collections should change" New topic
Author

sorting a collection other collections should change

swetha deshmukh
Greenhorn

Joined: Jul 19, 2005
Posts: 9
hi friends,
I'm very poor at collections can anyone help me in it?

I have a collection when sorted all other related collections have to be changed relatively

Thanks
bye
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

So you have the same data stored in several ordered collections and when one collection is sorted then all the other ordered collections should be sorted. Change everything to use just one common ordered collection.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
See if I got the problem. You might have three collections of the same objects or maybe even different objects. If they are the very same objects, use the suggestion above to put everything in one collection if you can. Let's say they are different objects and they are students. You can sort by name or age or student id number and so on. When you sort one collection you want the others to be sorted by the same key.

I don't think you'll find anything automated to do that. But you can build something to make it happen.

What first comes to mind is an Observable object that holds the current sort order, and an Observer for each collection. When you change the sort order the Observable notifies the Observers, and they update their particular collection. Are you familiar with the observer pattern and the Observer and Observable classes in Java?

I'm cursious how you'll do the sorting, too. Maybe a Comparator for name order, another for age order, and so on?
[ July 21, 2005: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: sorting a collection other collections should change
 
Similar Threads
Collections
Hello a collection problem
A forum for JAVA Collections
10 enteries per page?
why Map is not under Collection interface?