Add all nodes in the tree that satisfy 'predicate' to the list 'matches' This node is checked first, followed by its children in order. If the node itself matches, the children are skipped.
(
Predicate<? super C> predicate, Collection<D> matches)
| 115 | * itself matches, the children are skipped. |
| 116 | */ |
| 117 | @SuppressWarnings("unchecked") |
| 118 | public <C extends TreeNode<NodeType>, D extends C> void collect( |
| 119 | Predicate<? super C> predicate, Collection<D> matches) { |
| 120 | // TODO: the semantics of this function are very strange. contains() |
| 121 | // checks using .equals() on the nodes. In the case of literals, slotrefs |
| 122 | // and maybe others, two different tree node objects can be equal and |
| 123 | // this function would only return one of them. This is not intuitive. |
| 124 | // We rely on these semantics to not have duplicate nodes. Investigate this. |
| 125 | if (predicate.apply((C) this) && !matches.contains(this)) { |
| 126 | matches.add((D) this); |
| 127 | return; |
| 128 | } |
| 129 | if (shouldCollectRecursively()) { |
| 130 | for (NodeType child: children_) child.collect(predicate, matches); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Add all nodes in the tree that are of class 'cl' to the list 'matches'. |