org.openl.util.AOpenIterator Maven / Gradle / Ivy
/*
* Created on May 18, 2003
*
* Developed by Intelligent ChoicePoint Inc. 2003
*/
package org.openl.util;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* @author snshor
*/
public abstract class AOpenIterator implements IOpenIterator {
static final class EmptyIterator extends AOpenIterator {
@Override
public boolean hasNext() {
return false;
}
@Override
public T next() {
throw new NoSuchElementException("EmptyIterator");
}
@Override
public int size() {
return 0;
}
}
abstract static class IteratorWrapper extends AOpenIterator {
protected final Iterator it;
IteratorWrapper(Iterator it) {
this.it = it;
}
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public abstract C next();
}
static class SimpleIteratorWrapper extends IteratorWrapper {
SimpleIteratorWrapper(Iterator it) {
super(it);
}
@Override
public T next() {
return it.next();
}
}
public static final EmptyIterator> EMPTY_ITERATOR = new EmptyIterator<>();
@SuppressWarnings("unchecked")
public static IOpenIterator empty() {
return (IOpenIterator) EMPTY_ITERATOR;
}
// ////////////////////////////// Some useful OpenIterators
// ///////////////////////////////////////////
@Override
public void remove() {
throw new IllegalStateException();
}
/**
* Calculates the remaining size of iterated collection without destroying itself(const in c++ terminology), -1 if
* it cannot be known in advance. Not every iterator is capable of doing it.
*/
@Override
public int size() {
return UNKNOWN_SIZE;
}
}