src/main/java/org/organicdesign/fp/collections/RangeOfInt.java
@Override public UnmodListIterator<Integer> listIterator(final int startIdx) {
        if( (startIdx < 0) || (startIdx > size) ) {
            // To match ArrayList and other java.util.List expectations
            throw new IndexOutOfBoundsException("Index: " + startIdx);
        }
        return new UnmodListIterator<Integer>() {
            int val = start + startIdx;
            @Override public boolean hasNext() { return val < end; }
            @Override public Integer next() {
                if (val >= end) {
                    // To match ArrayList and other java.util.List expectations
                    throw new NoSuchElementException();
                }
                Integer t = val;
                val = val + 1;
                return t;
            }
            @Override public boolean hasPrevious() { return val > start; }
            @Override public Integer previous() {
                if (val <= start) {
                    // To match ArrayList and other java.util.List expectations
                    throw new NoSuchElementException();
                }
                val = val - 1;
                return val;
            }
            @Override public int nextIndex() { return val - start; }
        };
    }
@Override public UnmodListIterator<Integer> listIterator(final int startIdx) {
        if( (startIdx < 0) || (startIdx > size) ) {
            // To match ArrayList and other java.util.List expectations
            throw new IndexOutOfBoundsException("Index: " + startIdx);
        }
        return new UnmodListIterator<Integer>() {
            int val = start + startIdx;
            @Override public boolean hasNext() { return val < end; }
            @Override public Integer next() {
                if (val >= end) {
                    // To match ArrayList and other java.util.List expectations
                    throw new NoSuchElementException();
                }
                Integer t = val;
                val = val + 1;
                return t;
            }
            @Override public boolean hasPrevious() { return val > start; }
            @Override public Integer previous() {
                if (val <= start) {
                    // To match ArrayList and other java.util.List expectations
                    throw new NoSuchElementException();
                }
                val = val - 1;
                return val;
            }
            @Override public int nextIndex() { return val - start; }
        };
    }
@ Override public UnmodListIterator < Integer > listIterator ( final int startIdx ) { if ( ( startIdx < 0 ) || ( startIdx > size ) ) { // To match ArrayList and other java.util.List expectations throw new IndexOutOfBoundsException ( "Index: " + startIdx ) ; } return new UnmodListIterator < Integer > ( ) { int val = start + startIdx ; @ Override public boolean hasNext ( ) { return val < end ; } @ Override public Integer next ( ) { if ( val >= end ) { // To match ArrayList and other java.util.List expectations throw new NoSuchElementException ( ) ; } Integer t = val ; val = val + 1 ; return t ; } @ Override public boolean hasPrevious ( ) { return val > start ; } @ Override public Integer previous ( ) { if ( val <= start ) { // To match ArrayList and other java.util.List expectations throw new NoSuchElementException ( ) ; } val = val - 1 ; return val ; } @ Override public int nextIndex ( ) { return val - start ; } } ; }
{@inheritDoc}
Iterates from start of range (inclusive) up-to, but excluding, the end of the range.
I'm not sure this is a good idea, but Python, Clojure, Scala, and just about everything in
Java expects similar behavior.
{