Skip to content

Instantly share code, notes, and snippets.

@ntakouris
Created May 13, 2018 18:06
Show Gist options
  • Save ntakouris/35d5603e2dc4d80b0d6ca3944528822a to your computer and use it in GitHub Desktop.
Save ntakouris/35d5603e2dc4d80b0d6ca3944528822a to your computer and use it in GitHub Desktop.
public class PedestalledLeanLinkedList<T extends ContradictableType> {
LinkedList<T> types = new LinkedList<>();
public void insert(T type) {
boolean first = true;
for (Iterator<T> iterator = types.iterator(); iterator.hasNext(); ) {
ContradictableType current = iterator.next();
if (first) {
first = false;
continue;
}
if (current.equivalentTo(type)) {
return;
}
if (current.cancelsOutWith(type)) {
iterator.remove();
return;
}
}
types.add(type);
}
public T poll() {
return types.pollFirst();
}
public T peek() {
return types.peekFirst();
}
public boolean isEmpty() {
return peek() == null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment