protected Iterator createIterator()

in core/src/main/java/org/apache/commons/functor/range/LongRange.java [167:202]


    protected Iterator<Long> createIterator() {
        return new Iterator<Long>() {
            private long currentValue;

            {
                currentValue = leftEndpoint.getValue();

                if (leftEndpoint.getBoundType() == BoundType.OPEN) {
                    this.currentValue += step;
                }
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }

            public Long next() {
                final long step = getStep();
                final long r = currentValue;
                currentValue += step;
                return Long.valueOf(r);
            }

            public boolean hasNext() {
                final int cmp = Long.valueOf(currentValue).compareTo(rightEndpoint.getValue());

                if (cmp == 0) {
                    return rightEndpoint.getBoundType() == BoundType.CLOSED;
                }
                if (step > 0L) {
                    return cmp < 0;
                }
                return cmp > 0;
            }
        };
    }