Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 1.07 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. TreeLeaf<E,T> extends ForwardingSet<T> {
  2.  
  3.     private final Set<TreeLeaf<T>> children;
  4.     private final Set<T> leaves;
  5.     private final E node;
  6.     private Comparator<T> comparator;
  7.  
  8.     TreeLeaf() {
  9.         super();
  10.         children = Sets.newHashSet();
  11.         leaves = Sets.newHashSet();
  12.     }
  13.  
  14.     TreeLeaf(Comparator<T> comparator) {
  15.         super();
  16.         children = Sets.newHashSet();
  17.         leaves = Sets.newTreeSet(comparator);
  18.         this.comparator = comparator;
  19.     }
  20.  
  21.     public TreeLeaf<T> createChild() {
  22.         TreeLeaf<T> ret;
  23.         if (comparator != null) {
  24.             ret = new TreeLeaf<T>(comparator);
  25.         } else {
  26.             ret = new TreeLeaf<T>();
  27.         }
  28.         children.add(ret);
  29.         return ret;
  30.     }
  31.  
  32.     @Override
  33.     protected Set<T> delegate() {
  34.         return leaves;
  35.     }
  36.  
  37.  
  38.  
  39.     Iterable<T> allElements() {
  40.         Iterator<T> ret = iterator();
  41.         for(TreeLeaf<T> child : children) {
  42.             ret = Iterators.concat(ret,child.allElements());
  43.         }
  44.         return ret;
  45.     }
  46.  
  47.  
  48. }