1 19 20 package org.sablecc.sablecc.util; 21 22 import java.util.HashSet ; 23 import java.util.LinkedHashSet ; 24 import java.util.Set ; 25 26 import org.sablecc.sablecc.exception.InternalException; 27 28 32 public class WorkSet<T> { 33 34 35 private final Set <T> done = new HashSet <T>(); 36 37 38 private final LinkedHashSet <T> toDo = new LinkedHashSet <T>(); 39 40 46 public boolean hasNext() { 47 48 return !this.toDo.isEmpty(); 49 } 50 51 56 public T next() { 57 58 T next = this.toDo.iterator().next(); 59 60 this.toDo.remove(next); 61 this.done.add(next); 62 63 return next; 64 } 65 66 74 public void add( 75 T element) { 76 77 if (element == null) { 78 throw new InternalException("element may not be null"); 79 } 80 81 if (!this.done.contains(element)) { 82 this.toDo.add(element); 83 } 84 } 85 } 86 | Popular Tags |