@Test public void testFirst() throws Exception { Assert.assertNull(tree.first(null)); Assert.assertNull(tree.first(new ArrayList<String>())); Assert.assertEquals("key1", tree.first(key1)); Assert.assertEquals("key1", tree.first(key2)); Assert.assertEquals("key1", tree.first(key3)); Assert.assertEquals("key1", tree.first(key4)); Assert.assertEquals("key5", tree.first(key5)); Assert.assertEquals("key1", tree.first(key6)); Assert.assertEquals("key1", tree.first(key7)); Assert.assertEquals("key1", tree.first(key8)); }
public V first(List<K> cascadingFactors) { if (value != null || CollectionValues.isNullOrEmpty(cascadingFactors)) { return value; } List<K> factors = Lists.newArrayList(cascadingFactors); SearchTree<K, V> g = children.get(factors.remove(0)); if (g == null) { return defaultChildrenValue; } return g.first(factors); }
SearchTree { public V first(List<K> cascadingFactors) { if (value != null || CollectionValues.isNullOrEmpty(cascadingFactors)) { return value; } List<K> factors = Lists.newArrayList(cascadingFactors); SearchTree<K, V> g = children.get(factors.remove(0)); if (g == null) { return defaultChildrenValue; } return g.first(factors); } }
SearchTree { public V first(List<K> cascadingFactors) { if (value != null || CollectionValues.isNullOrEmpty(cascadingFactors)) { return value; } List<K> factors = Lists.newArrayList(cascadingFactors); SearchTree<K, V> g = children.get(factors.remove(0)); if (g == null) { return defaultChildrenValue; } return g.first(factors); }  }
SearchTree { public V first(List<K> cascadingFactors) { if (value != null || CollectionValues.isNullOrEmpty(cascadingFactors)) { return value; } List<K> factors = Lists.newArrayList(cascadingFactors); SearchTree<K, V> g = children.get(factors.remove(0)); if (g == null) { return defaultChildrenValue; } return g.first(factors); }  V getValue(); void setValue(V value); V getDefaultChildrenValue(); void setDefaultChildrenValue(V defaultChildrenValue); V get(List<K> cascadingFactors); V first(List<K> cascadingFactors); void add(List<K> cascadingFactors, V value); void put(K childKey, SearchTree<K, V> searchTree); }
SearchTree { public V first(List<K> cascadingFactors) { if (value != null || CollectionValues.isNullOrEmpty(cascadingFactors)) { return value; } List<K> factors = Lists.newArrayList(cascadingFactors); SearchTree<K, V> g = children.get(factors.remove(0)); if (g == null) { return defaultChildrenValue; } return g.first(factors); }  V getValue(); void setValue(V value); V getDefaultChildrenValue(); void setDefaultChildrenValue(V defaultChildrenValue); V get(List<K> cascadingFactors); V first(List<K> cascadingFactors); void add(List<K> cascadingFactors, V value); void put(K childKey, SearchTree<K, V> searchTree);  }