All Downloads are FREE. Search and download functionalities are using the official Maven repository.

webit.script.lang.iter.IntAscIter Maven / Gradle / Ivy

The newest version!
// Copyright (c) 2013-2014, Webit Team. All Rights Reserved.
package webit.script.lang.iter;

import java.util.NoSuchElementException;
import webit.script.lang.Iter;

/**
 *
 * @author Zqq
 */
public final class IntAscIter implements Iter {

    private final int from;
    private final int to;
    private int current;

    public IntAscIter(int int1, int int2) {
        if (int1 < int2) {
            from = int1;
            to = int2;
        } else {
            from = int2;
            to = int1;
        }
        current = from - 1;
    }

    public boolean hasNext() {
        return current < to;
    }

    public Integer next() {
        if (current < to) {
            return ++current;
        } else {
            throw new NoSuchElementException("no more next");
        }
    }

    public boolean isFirst() {
        return current == from;
    }

    public int index() {
        return current - from;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy