title: Java: Data structure for sorting objects/maintaining a key in that order?
body: <p>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.</p>
  
  <p>I have a function <code>compareOdp(Odp o1, Odp o2)</code> 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 <code>foo</code> in the collection?" or "Of these several collections of Odp objects, how close are they to each other?"</p>
  
  <p>What is the best way to do this? TreeMap? HashBiMap? </p>
  
  <p><strong>Related Question:</strong></p>
  
  <p>Let's say I have the following set of objects: <code>o1</code>, <code>o2</code>, <code>o3</code> contained in collection <code>col</code>. Their sort order is </p>
  
  <pre><code>o2
  o3
  o1
  </code></pre>
  
  <p>I want to ask <code>col</code>: "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.</p>