• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

best way to sort several sets of data

 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I need to check several sets of data D1 (dataA, dataB, dataC ...),
D2 (dataD, dataE, dataF ...),
against several criterias: criteria1, criteria2, criteria3, criteria4 etc ...

The objective is to get the unique set of data which satisfies all the crierias OR is the nearest one to the criterias.

So my idea is to affect them a score:
If D1.dataA= criteria1 then I increase D1's score by 1
If D1.dataB= criteria2 then I increase D1's score by 1
and I add all the scores and give D1 a total score,etc

and at the end I select the set Dx which has the biggest score.


what solution do you recommend ?
I am looking for any kind of solution, and information on the implementation as well of course.
Hashmap ? TreeSet ? Comparable ?

If someone has already done something like that, please let me know.

Thanks in advance.
 
Thejesh G Nagarathna
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For sorting you can use Collections.sort (list, comparator)
where in comparator you can specify the on which you want to compare ( in your case the added score)
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know of a more detailed solution please ?
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Thejesh said, you can use Collections to store your information. Since you say your data is a set, you might want to use the TreeSet class, which implements both the Set and SortedSet interfaces.

In order to determine how the elements are ordered you will need to either implement the Comparable interface in your classes, or write separate Comparator classes.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That hint was sufficient to dig out the details. Look into the JavaDoc, find the Collections class, find the sort() method, follow the links to List and Comparator. Everything you need is there!

If your data is really held the way you showed it, so you can do neat tests like "if ( d1.dataA == criteria )" then you have a great start.
 
Megs Maquito
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could also try googling it "java sort tutorial" if you find it hard to understand the java docs
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic