IndexedKeyTreeMap extends KeyTreeMap<T> { public void put(final T object, final int index) { final ArrayList<Key> keys = new ArrayList<>(); for (final Key additionalKey : object.keys()) { keys.add(additionalKey); } doForAll(index, new Callback<T>() { @Override public void callback(final T t) { t.setIndex(t.getIndex() + 1); } }); object.setIndex(index); super.put(object); } IndexedKeyTreeMap(final KeyDefinition... keyIDs); void put(final T object,
                    final int index); @Override void put(final T object);  }
@Test public void testAddToMiddle() throws Exception { final Person smurf = new Person("Smurf", 55); map.put(smurf, 1); assertEquals(4, map.get(IndexKey.INDEX_ID).size()); assertEquals(toni, map.get(IndexKey.INDEX_ID).get(new Value(0)).iterator().next()); assertEquals(smurf, map.get(IndexKey.INDEX_ID).get(new Value(1)).iterator().next()); assertEquals(eder, map.get(IndexKey.INDEX_ID).get(new Value(2)).iterator().next()); assertEquals(michael, map.get(IndexKey.INDEX_ID).get(new Value(3)).iterator().next()); }