PhraseTree { public boolean contains(String[] phraseParts) { int i = 0; PhraseTreeElement match = root.getChild(phraseParts[i]); while (match != null && i < phraseParts.length - 1) { i++; String childToken = phraseParts[i]; PhraseTreeElement child = match.getChild(childToken); match = child; } if (match != null) { return match.isEndElement(); } else { return false; } } PhraseTree(); void addPhrase(String[] phraseParts); boolean contains(String[] phraseParts); String[] getLongestMatch(String[] matchText);  }
@Test public void containsTest() throws Exception { assertFalse(phrases.contains("the".split(" "))); assertFalse(phrases.contains("the new".split(" "))); assertFalse(phrases.contains("the new BUNNY".split(" "))); assertFalse(phrases.contains("the red dog barks".split(" "))); assertTrue(phrases.contains("a".split(" "))); assertTrue(phrases.contains("the red dog".split(" "))); assertTrue(phrases.contains("the red".split(" "))); assertTrue(phrases.contains("the new kid".split(" "))); }