SegmentTrie { public static <T> SegmentTrie<T> create( Map<String, ? extends T> map, char separator, T defaultValue) { switch (map.size()) { case 0: return new EmptyTrie<T>(defaultValue); case 1: Map.Entry<String, ? extends T> e = map.entrySet().iterator().next(); return new SingletonTrie<T>(e.getKey(), e.getValue(), separator, defaultValue); default: return new SortedTrie<T>(map, separator, defaultValue); } } SegmentTrie(T defaultValue); static SegmentTrie<T> create(
      Map<String, ? extends T> map, char separator, T defaultValue); final T getDefaultValue(); abstract T find(String key); abstract Map<String, T> getEntryMap();  }
@Test public void testSingletonMap_nullkey() { Map<String, String> map = new HashMap<>(); map.put(null, "BAD"); try { @SuppressWarnings("unused") SegmentTrie<String> unused = SegmentTrie.create(map, '.', DEFAULT); fail("expected NullPointerException"); } catch (NullPointerException e) { } }
@Test public void testGeneralCaseMap_nullkeys() { Map<String, String> map = new HashMap<>(); map.put("foo", "FOO"); map.put(null, "BAD"); try { @SuppressWarnings("unused") SegmentTrie<String> unused = SegmentTrie.create(map, '.', DEFAULT); fail("expected NullPointerException"); } catch (NullPointerException e) { } }