Loading src/main/java/me/brianlong/git/UniquePriorityFifoQueue.java +8 −11 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ public class UniquePriorityFifoQueue<T> implements Queue<T> { private final Counter counter = new SimpleCounter(); private final Counter fakeCounter = new FakeCounter(); private final TreeSet<PriorityFifoElement<T>> elements; // TreeSet does not check for uniqueness using hashCode, but using the comparator instead private final Set<PriorityFifoElement<T>> uelements; public UniquePriorityFifoQueue() { Loading @@ -24,11 +25,7 @@ public class UniquePriorityFifoQueue<T> implements Queue<T> { public UniquePriorityFifoQueue(Collection<? extends T> c) { this(); for (T e : c) { PriorityFifoElement<T> element = new PriorityFifoElement<T>(e, this.counter); this.elements.add(element); this.uelements.add(element); } this.addAll(c); } public UniquePriorityFifoQueue(final Comparator<? super T> comparator) { Loading @@ -46,18 +43,19 @@ public class UniquePriorityFifoQueue<T> implements Queue<T> { @Override public boolean add(T e) { PriorityFifoElement<T> element = new PriorityFifoElement<T>(e, this.counter); return this.elements.add(element) && this.uelements.add(element); return this.uelements.add(element) && this.elements.add(element); } @Override public boolean addAll(Collection<? extends T> c) { boolean anyAdded = false; if (c != null) for (T e : c) { PriorityFifoElement<T> element = new PriorityFifoElement<T>(e, this.counter); this.elements.add(element); this.uelements.add(element); if (this.uelements.add(element) && this.elements.add(element)) anyAdded = true; } return true; return anyAdded; } @Override Loading Loading @@ -117,8 +115,7 @@ public class UniquePriorityFifoQueue<T> implements Queue<T> { @Override public boolean offer(T e) { PriorityFifoElement<T> element = new PriorityFifoElement<T>(e, this.counter); return this.elements.add(element) && this.uelements.add(element); return this.add(e); } @Override Loading Loading
src/main/java/me/brianlong/git/UniquePriorityFifoQueue.java +8 −11 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ public class UniquePriorityFifoQueue<T> implements Queue<T> { private final Counter counter = new SimpleCounter(); private final Counter fakeCounter = new FakeCounter(); private final TreeSet<PriorityFifoElement<T>> elements; // TreeSet does not check for uniqueness using hashCode, but using the comparator instead private final Set<PriorityFifoElement<T>> uelements; public UniquePriorityFifoQueue() { Loading @@ -24,11 +25,7 @@ public class UniquePriorityFifoQueue<T> implements Queue<T> { public UniquePriorityFifoQueue(Collection<? extends T> c) { this(); for (T e : c) { PriorityFifoElement<T> element = new PriorityFifoElement<T>(e, this.counter); this.elements.add(element); this.uelements.add(element); } this.addAll(c); } public UniquePriorityFifoQueue(final Comparator<? super T> comparator) { Loading @@ -46,18 +43,19 @@ public class UniquePriorityFifoQueue<T> implements Queue<T> { @Override public boolean add(T e) { PriorityFifoElement<T> element = new PriorityFifoElement<T>(e, this.counter); return this.elements.add(element) && this.uelements.add(element); return this.uelements.add(element) && this.elements.add(element); } @Override public boolean addAll(Collection<? extends T> c) { boolean anyAdded = false; if (c != null) for (T e : c) { PriorityFifoElement<T> element = new PriorityFifoElement<T>(e, this.counter); this.elements.add(element); this.uelements.add(element); if (this.uelements.add(element) && this.elements.add(element)) anyAdded = true; } return true; return anyAdded; } @Override Loading Loading @@ -117,8 +115,7 @@ public class UniquePriorityFifoQueue<T> implements Queue<T> { @Override public boolean offer(T e) { PriorityFifoElement<T> element = new PriorityFifoElement<T>(e, this.counter); return this.elements.add(element) && this.uelements.add(element); return this.add(e); } @Override Loading