title: Reranking items without changing ranks of all items
body: <p>I have a list of items, each of which has a rank associated to it. </p>
  
  <pre><code>Item 1, Rank=1
  Item 2, Rank=2
  Item 3, Rank=3
  Item 4, Rank=4
  Item 5, Rank=5
  </code></pre>
  
  <p>I want to design a method which handles re-ranking of items with minimal or no changes to the ranks of other items.</p>
  
  <p>One solution I thought of was to leverage decimals and use Java's double variable type. So for example if I move item5 between item2 and item3, this would be the output - </p>
  
  <pre><code>Item 1, Rank=1
  Item 2, Rank=2
  Item 5, Rank=2.5
  Item 3, Rank=3
  Item 4, Rank=4
  </code></pre>
  
  <p>And so on,</p>
  
  <pre><code>Item 1, Rank=1
  Item 2, Rank=2
  Item 4, Rank=2.25
  Item 5, Rank=2.5
  Item 3, Rank=3
  </code></pre>
  
  <p>This solutions works, but after some point (~55 moves at the same position, I reach the double variable limit and i will probably have to reset all ranks at that point)</p>
  
  <p>I was just wondering if there is some better way to solve this problem?</p>
  
  <p>A few things to keep in mind. </p>
  
  <ul>
  <li>I need to store this data structure in a database (Item, Rank) and I will be building a web service which gets all items in a sorted order based on rank so I would be making a DB call to get all items sorted by the rank field. </li>
  <li>I will be using Java so I can only deal with Java variables.</li>
  </ul>