I have a set of objects, each of which has an id value (int). I want to write a function which takes the object set as input, calculates a score (double) for each object, and returns a sorted array of object ids where the returned ids are stored in order of the "score" obtained.
I thought this would be easy, but I can't find a simple way of achieving this in less than 10 lines of code. (I'm using jdk 7)
Here's my code:
private ArrayList<Integer> getBlockIds(IndexKey key) {
ArrayList<Integer> blockIds;
Set<IndexKey> adjKeys = indexAPI.getAdjacentKeys(key, 1);
Comparator cmp = new Comparator("Levenshtein");
for ( IndexKey aKey : adjKeys ) {
if ( cmp.similarity(key.getValue(), aKey.getValue()) >= 0.75 ) {
blockIds.add(aKey.getBlockId);
}
}
return blockIds;
}
I want blockIds to be stored in order of score (highest first)