I want to maintain a collection of objects of type Odp. Odp implements Comparable. I need to be able to refer to an object in the collection with its integer name. This integer must correspond to its sort order (not insertion order). Each integer only applies to one Odp, and vice versa.
I have a function compareOdp(Odp o1, Odp o2)
that returns a numeric value representing the similarity of the two arguments. I the Odp collection to be set up in such a way that it's easy to ask questions like "What is the closest Odp to foo
in the collection?" or "Of these several collections of Odp objects, how close are they to each other?"
What is the best way to do this? TreeMap? HashBiMap?
Related Question:
Let's say I have the following set of objects: o1
, o2
, o3
contained in collection col
. Their sort order is
o2
o3
o1
I want to ask col
: "what is the nth object in the list?" From what I can see, SortedSet and TreeMap don't have a way to do this. I guess I could iterate over, but it feels like there should be an easier way.