integeriterator.java
来自「该原代码是实现机器学习中条件随机场模型的Java代码」· Java 代码 · 共 57 行
JAVA
57 行
/**
*
*/
package lcrf.stuff;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* @author bgutmann
*
*/
public class IntegerIterator implements Iterator<Integer> {
private int next;
private int mininclusive;
private int maxexclusive;
public IntegerIterator(int maxexclusive) {
this(0, maxexclusive);
}
public IntegerIterator(int mininclusive, int maxexclusive) {
next = mininclusive;
this.mininclusive = mininclusive;
this.maxexclusive = maxexclusive;
}
public boolean hasNext() {
return next < maxexclusive;
}
public Integer next() {
if (next < maxexclusive) {
Integer result = new Integer(next);
next++;
return result;
}
throw new NoSuchElementException();
}
public void pushBack() {
if (next == mininclusive)
throw new IllegalStateException("Next was never called before.");
next--;
}
public void remove() {
throw new UnsupportedOperationException();
}
public void reset() {
next = mininclusive;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?