package me.nallar.tickthreading.collections;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.ConcurrentLinkedQueue;

@SuppressWarnings ("ConstantConditions")
public class ListIteratorRemoveQueue<T> extends ConcurrentLinkedQueue<T> implements List<T> {
	@Override
	public Iterator<T> iterator() {
		return new Iterator<T>() {
			private T next;

			@Override
			public boolean hasNext() {
				if (next != null) {
					throw new IllegalStateException("iterator.remove() not called.");
				}
				next = ListIteratorRemoveQueue.this.poll();
				return next != null;
			}

			@Override
			public T next() {
				if (next == null) {
					throw new IllegalStateException("iterator.next() called without .hasNext()");
				}
				return next;
			}

			@Override
			public void remove() {
				next = null;
			}
		};
	}

	@Override
	public boolean addAll(Collection<? extends T> c) {
		return c == this || super.addAll(c);
	}

	@Override
	public boolean addAll(int index, Collection c) {
		throw new UnsupportedOperationException();
	}

	@Override
	public T get(int index) {
		if (index == 0) {
			return this.peek();
		}
		throw new UnsupportedOperationException();
	}

	@Override
	public T set(int index, Object element) {
		throw new UnsupportedOperationException();
	}

	@Override
	public void add(int index, Object element) {
		throw new UnsupportedOperationException();
	}

	@Override
	public T remove(int index) {
		if (index == 0) {
			return this.poll();
		}
		throw new UnsupportedOperationException();
	}

	@Override
	public int indexOf(Object o) {
		throw new UnsupportedOperationException();
	}

	@Override
	public int lastIndexOf(Object o) {
		throw new UnsupportedOperationException();
	}

	@Override
	public ListIterator<T> listIterator() {
		throw new UnsupportedOperationException();
	}

	@Override
	public ListIterator<T> listIterator(int index) {
		throw new UnsupportedOperationException();
	}

	@Override
	public List<T> subList(int fromIndex, int toIndex) {
		throw new UnsupportedOperationException();
	}
}

@@ -493,112 +493,8 @@
  %7B%0D%0A
-%09%09%09%09if (next != null) %7B%0D%0A%09%09%09%09%09throw new IllegalStateException(%22iterator.remove() not called.%22);%0D%0A%09%09%09%09%7D%0D%0A
 %09%09%09%09
@@ -526,27 +526,27 @@
 Queue.this.p
-oll
+eek
 ();%0D%0A%09%09%09%09ret
@@ -799,20 +799,123 @@
 %09%09%09%09
-next = null;
+if (ListIteratorRemoveQueue.this.poll() != next) %7B%0D%0A%09%09%09%09%09throw new IllegalStateException(%22Already removed%22);%0D%0A%09%09%09%09%7D
 %0D%0A%09%09
@@ -975,16 +975,17 @@
 llection
+ 
 %3C? exten

Fix ListIteratorRemoveQueue logic