@Test public void testIterator() { for (String test : tests) { MappingIterator<Character, String> it = trie.getMappingIterator(); for (char c : test.toCharArray()) { if (it.hasChild(c)) { it.move(c); } else { break; } } if (it.canExit()) { System.out.println(it.getValue()); } else { System.out.println("allow"); } } }
public MappingIterator<K, V> getMappingIterator() { return new MappingIterator<K, V>() { private Node pointer = root; @Override public V getValue() { if (!canExit()) { return null; } return pointer.getChild(endSymbol).value; } @Override public boolean hasChild(K data) { return pointer.containsKey(data); } @Override public boolean canExit() { return pointer.containsKey(endSymbol); } @Override public void move(K data) { pointer = pointer.getChild(data); } }; }
MappingTrie { public MappingIterator<K, V> getMappingIterator() { return new MappingIterator<K, V>() { private Node pointer = root; @Override public V getValue() { if (!canExit()) { return null; } return pointer.getChild(endSymbol).value; } @Override public boolean hasChild(K data) { return pointer.containsKey(data); } @Override public boolean canExit() { return pointer.containsKey(endSymbol); } @Override public void move(K data) { pointer = pointer.getChild(data); } }; } }
MappingTrie { public MappingIterator<K, V> getMappingIterator() { return new MappingIterator<K, V>() { private Node pointer = root; @Override public V getValue() { if (!canExit()) { return null; } return pointer.getChild(endSymbol).value; } @Override public boolean hasChild(K data) { return pointer.containsKey(data); } @Override public boolean canExit() { return pointer.containsKey(endSymbol); } @Override public void move(K data) { pointer = pointer.getChild(data); } }; } MappingTrie(K root, K endSymbol); }
MappingTrie { public MappingIterator<K, V> getMappingIterator() { return new MappingIterator<K, V>() { private Node pointer = root; @Override public V getValue() { if (!canExit()) { return null; } return pointer.getChild(endSymbol).value; } @Override public boolean hasChild(K data) { return pointer.containsKey(data); } @Override public boolean canExit() { return pointer.containsKey(endSymbol); } @Override public void move(K data) { pointer = pointer.getChild(data); } }; } MappingTrie(K root, K endSymbol); void add(List<K> data, V value); MappingIterator<K, V> getMappingIterator(); }
MappingTrie { public MappingIterator<K, V> getMappingIterator() { return new MappingIterator<K, V>() { private Node pointer = root; @Override public V getValue() { if (!canExit()) { return null; } return pointer.getChild(endSymbol).value; } @Override public boolean hasChild(K data) { return pointer.containsKey(data); } @Override public boolean canExit() { return pointer.containsKey(endSymbol); } @Override public void move(K data) { pointer = pointer.getChild(data); } }; } MappingTrie(K root, K endSymbol); void add(List<K> data, V value); MappingIterator<K, V> getMappingIterator();  }