
Untitled
By: a guest on
Jul 15th, 2012 | syntax:
None | size: 1.07 KB | hits: 10 | expires: Never
TreeLeaf<E,T> extends ForwardingSet<T> {
private final Set<TreeLeaf<T>> children;
private final Set<T> leaves;
private final E node;
private Comparator<T> comparator;
TreeLeaf() {
super();
children = Sets.newHashSet();
leaves = Sets.newHashSet();
}
TreeLeaf(Comparator<T> comparator) {
super();
children = Sets.newHashSet();
leaves = Sets.newTreeSet(comparator);
this.comparator = comparator;
}
public TreeLeaf<T> createChild() {
TreeLeaf<T> ret;
if (comparator != null) {
ret = new TreeLeaf<T>(comparator);
} else {
ret = new TreeLeaf<T>();
}
children.add(ret);
return ret;
}
@Override
protected Set<T> delegate() {
return leaves;
}
Iterable<T> allElements() {
Iterator<T> ret = iterator();
for(TreeLeaf<T> child : children) {
ret = Iterators.concat(ret,child.allElements());
}
return ret;
}
}