ParseTreeNode { public boolean containsWord(Predicate<WordToken> filter) { if (words != null && !words.isEmpty()) { final boolean result = words.stream().anyMatch(filter); if (result) { return true; } } if (children != null) { return children.stream().anyMatch(c -> c.containsWord(filter)); } return false; } ParseTreeNode(PhraseChunk chunk);  ParseTreeNode(List<ParseTreeNode> children); void traverseChildren(Consumer<List<ParseTreeNode>> consumer); void traverseParent(BiPredicate<ParseTreeNode, ParseTreeNode> consumer); boolean isRoot(); PhraseChunk getChunk(); void setParent(ParseTreeNode parent); List<ParseTreeNode> getChildren(); boolean hasChildren(); ParseTreeNode getParent(); void addChild(ParseTreeNode child); void addWords(Collection<WordToken> word); List<WordToken> getWords(); @Override String toString(); boolean containsWord(Predicate<WordToken> filter); void log(String indent);  }
@Test public void testContainsWord() { assertTrue(a.containsWord(w -> w.getCoveredText().equals("1"))); assertFalse(a.containsWord(w -> w.getCoveredText().equals("4"))); }