@Test public void test_findShortestWord_1() throws Exception{ Trie t = trieWithWords("hello", "helloworld", "hi", "howsgoing", "hell", "helloworld2", "world"); String text = "The helloworld."; StringBuilder b = new StringBuilder(); int i = t.findShortestWord(text, 0, text.length(), b); Assert.assertEquals(4, i); Assert.assertEquals("hell", b.toString()); }
@Override public int findShortestWord(CharSequence chars, int start, int end, StringBuilder word) { for(int i = start; i < end; i++){ Iterator<String> it = commonPrefixSearch(chars.subSequence(i, end).toString()).iterator(); / int len = Integer.MIN_VALUE; String ret = null; while(it.hasNext()){ String w = it.next(); if(w.length() > len){ ret = w; len = w.length(); } } if(ret != null){ word.append(ret); return i; } } return -1; }
AbstractTrie implements Trie { @Override public int findShortestWord(CharSequence chars, int start, int end, StringBuilder word) { for(int i = start; i < end; i++){ Iterator<String> it = commonPrefixSearch(chars.subSequence(i, end).toString()).iterator(); / int len = Integer.MIN_VALUE; String ret = null; while(it.hasNext()){ String w = it.next(); if(w.length() > len){ ret = w; len = w.length(); } } if(ret != null){ word.append(ret); return i; } } return -1; } }
AbstractTrie implements Trie { @Override public int findShortestWord(CharSequence chars, int start, int end, StringBuilder word) { for(int i = start; i < end; i++){ Iterator<String> it = commonPrefixSearch(chars.subSequence(i, end).toString()).iterator(); / int len = Integer.MIN_VALUE; String ret = null; while(it.hasNext()){ String w = it.next(); if(w.length() > len){ ret = w; len = w.length(); } } if(ret != null){ word.append(ret); return i; } } return -1; }  }
AbstractTrie implements Trie { @Override public int findShortestWord(CharSequence chars, int start, int end, StringBuilder word) { for(int i = start; i < end; i++){ Iterator<String> it = commonPrefixSearch(chars.subSequence(i, end).toString()).iterator(); / int len = Integer.MIN_VALUE; String ret = null; while(it.hasNext()){ String w = it.next(); if(w.length() > len){ ret = w; len = w.length(); } } if(ret != null){ word.append(ret); return i; } } return -1; }  @Override int findWord(CharSequence chars, int start, int end, StringBuilder word); @Override int findShortestWord(CharSequence chars, int start, int end, StringBuilder word); @Override int findLongestWord(CharSequence chars, int start, int end, StringBuilder word); @Override void dump(Writer writer); @Override void trimToSize(); @Override void freeze(); @Override void insert(String word); }
AbstractTrie implements Trie { @Override public int findShortestWord(CharSequence chars, int start, int end, StringBuilder word) { for(int i = start; i < end; i++){ Iterator<String> it = commonPrefixSearch(chars.subSequence(i, end).toString()).iterator(); / int len = Integer.MIN_VALUE; String ret = null; while(it.hasNext()){ String w = it.next(); if(w.length() > len){ ret = w; len = w.length(); } } if(ret != null){ word.append(ret); return i; } } return -1; }  @Override int findWord(CharSequence chars, int start, int end, StringBuilder word); @Override int findShortestWord(CharSequence chars, int start, int end, StringBuilder word); @Override int findLongestWord(CharSequence chars, int start, int end, StringBuilder word); @Override void dump(Writer writer); @Override void trimToSize(); @Override void freeze(); @Override void insert(String word);  }