com.google.security.fences.util.CountingIterator Maven / Gradle / Ivy
package com.google.security.fences.util;
import java.util.Iterator;
import com.google.common.base.Preconditions;
/**
* A single enumeration over a {@link CountingIterator}.
*/
public final class CountingIterator implements Iterator {
private int i;
private final int rightExclusive;
CountingIterator(int leftInclusive, int rightExclusive) {
Preconditions.checkArgument(i <= rightExclusive);
this.i = leftInclusive;
this.rightExclusive = rightExclusive;
}
@Override
public String toString() {
return "[" + i + ".." + rightExclusive + ")";
}
public boolean hasNext() {
return i < rightExclusive;
}
public synchronized Integer next() {
if (i >= rightExclusive) {
throw new IndexOutOfBoundsException(i + " >= " + rightExclusive);
}
return i++;
}
public void remove() {
throw new UnsupportedOperationException();
}
}