AbstractTree implements Tree<K,V> { @Override public Tree<K,V> getByPath(List<K> path) { Tree<K,V> t = this; for (K key : path) { Tree<K,V> next = t.get(key); if (next == null) { return null; } t = next; } return t; }  @Override Tree<K,V> getByPath(List<K> path); @Override Tree<K,V> putByPath(List<K> path, V value); @Override Tree<K,V> putByPath(List<K> path, V value, V intermediaryValue);  }
@Test public void getByPath_noSubTree() { InMemoryTree<Integer,String> t = new InMemoryTree<Integer,String>("one"); t.put(2, "two").put(3, "three"); t.get(2).put(4, "four").put(5, "five"); assertNull(t.getByPath(new Path<Integer>(100))); assertNull(t.getByPath(new Path<Integer>(3))); assertNull(t.getByPath(new Path<Integer>(2, 4, 5, 6))); }
@Test public void getByPath() throws Exception { InMemoryTree<Integer,String> t = new InMemoryTree<Integer,String>("one"); t.put(2, "two").put(3, "three"); t.get(2).put(4, "four").put(5, "five"); assertEquals(t.getByPath(new Path<Integer>(2, 3)).getValue(), "three"); assertEquals(t.getByPath(new Path<Integer>(2, 4, 5)).getValue(), "five"); }