MCPcopy Create free account
hub / github.com/apache/groovy / IntRange

Class IntRange

src/main/java/groovy/lang/IntRange.java:58–575  ·  view source on GitHub ↗

Represents a list of Integer objects starting at and potentially including a specified from value up (or down) to and potentially including a given to value. Instances of this class may be either inclusive aware or non-inclusive aware. See the relevant constructors for creating e

Source from the content-addressed store, hash-verified

56 * changes to this class, you might consider making parallel changes to {@link ObjectRange}.
57 */
58public class IntRange extends AbstractList<Integer> implements Range<Integer>, Serializable {
59
60 @Serial private static final long serialVersionUID = -7827097587793510780L;
61
62 /**
63 * Iterates through each number in an <code>IntRange</code>.
64 */
65 private class IntRangeIterator implements Iterator<Integer> {
66 /**
67 * Counts from 0 up to size - 1.
68 */
69 private int index;
70
71 /**
72 * The number of values in the range.
73 */
74 private int size = size();
75
76 /**
77 * The next value to return.
78 */
79 private int value = isReverse() ? getTo() : getFrom();
80
81 /**
82 * {@inheritDoc}
83 */
84 @Override
85 public boolean hasNext() {
86 return index < size;
87 }
88
89 /**
90 * {@inheritDoc}
91 */
92 @Override
93 public Integer next() {
94 if (!hasNext()) {
95 throw new NoSuchElementException();
96 }
97 if (index++ > 0) {
98 if (isReverse()) {
99 --value;
100 } else {
101 ++value;
102 }
103 }
104 return value;
105 }
106
107 /**
108 * Not supported.
109 *
110 * @throws java.lang.UnsupportedOperationException always
111 */
112 @Override
113 public void remove() {
114 IntRange.this.remove(index);
115 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected