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.

SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCBCD 5
Visit my blog

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)

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.

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.

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