@@ -0,0 +1,1033 @@
+/*%0A * SubIterator.java%0A *%0A * Author: Ming Tsang%0A * Copyright (c) 2015 Ming Tsang%0A * Refer to LICENSE for details%0A */%0A%0Apackage com.nkming.utils.type;%0A%0Aimport java.util.Iterator;%0Aimport java.util.NoSuchElementException;%0A%0A/**%0A * An Iterator that iterates a subset of another Iterator. For List, consider%0A * List#subList instead%0A *%0A * @param %3CT%3E%0A */%0Apublic class SubIterator%3CT%3E implements Iterator%3CT%3E%0A%7B%0A%09/**%0A%09 * Create an Iterator that iterate between %5Bstart, end) in @a it%0A%09 *%0A%09 * @param it%0A%09 * @param start%0A%09 * @param end%0A%09 */%0A%09public SubIterator(Iterator%3CT%3E it, int start, int end)%0A%09%7B%0A%09%09mIt = it;%0A%09%09for (int i = 0; i %3C start && mIt.hasNext(); ++i)%0A%09%09%7B%0A%09%09%09mIt.next();%0A%09%09%7D%0A%09%09mLeft = end - start;%0A%09%7D%0A%0A%09@Override%0A%09public boolean hasNext()%0A%09%7B%0A%09%09return (mIt.hasNext() && mLeft %3E 0);%0A%09%7D%0A%0A%09@Override%0A%09public T next()%0A%09%7B%0A%09%09if (!hasNext())%0A%09%09%7B%0A%09%09%09throw new NoSuchElementException();%0A%09%09%7D%0A%09%09else%0A%09%09%7B%0A%09%09%09--mLeft;%0A%09%09%09return mIt.next();%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public void remove()%0A%09%7B%0A%09%09mIt.remove();%0A%09%7D%0A%0A%09private Iterator%3CT%3E mIt;%0A%09private int mLeft;%0A%7D%0A

Add iterator that is a subpart of another iterator