Implements generic numeric (potentially infinite) range.
| 17 | * Implements generic numeric (potentially infinite) range. |
| 18 | */ |
| 19 | public class Range extends ASeq implements IChunkedSeq, IReduce { |
| 20 | |
| 21 | private static final long serialVersionUID = -71973733672395145L; |
| 22 | |
| 23 | private static final int CHUNK_SIZE = 32; |
| 24 | |
| 25 | // Invariants guarantee this is never an "empty" seq |
| 26 | // assert(start != end && step != 0) |
| 27 | final Object end; |
| 28 | final Object start; |
| 29 | final Object step; |
| 30 | final BoundsCheck boundsCheck; |
| 31 | private volatile IChunk _chunk; // lazy |
| 32 | private volatile ISeq _chunkNext; // lazy |
| 33 | private volatile ISeq _next; // cached |
| 34 | |
| 35 | private static interface BoundsCheck extends Serializable { |
| 36 | boolean exceededBounds(Object val); |
| 37 | } |
| 38 | |
| 39 | private static BoundsCheck positiveStep(final Object end) { |
| 40 | return new BoundsCheck() { |
| 41 | public boolean exceededBounds(Object val){ |
| 42 | return Numbers.gte(val, end); |
| 43 | } |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | private static BoundsCheck negativeStep(final Object end) { |
| 48 | return new BoundsCheck() { |
| 49 | public boolean exceededBounds(Object val){ |
| 50 | return Numbers.lte(val, end); |
| 51 | } |
| 52 | }; |
| 53 | } |
| 54 | |
| 55 | private Range(Object start, Object end, Object step, BoundsCheck boundsCheck){ |
| 56 | this.end = end; |
| 57 | this.start = start; |
| 58 | this.step = step; |
| 59 | this.boundsCheck = boundsCheck; |
| 60 | } |
| 61 | |
| 62 | private Range(Object start, Object end, Object step, BoundsCheck boundsCheck, IChunk chunk, ISeq chunkNext){ |
| 63 | this.end = end; |
| 64 | this.start = start; |
| 65 | this.step = step; |
| 66 | this.boundsCheck = boundsCheck; |
| 67 | this._chunk = chunk; |
| 68 | this._chunkNext = chunkNext; |
| 69 | } |
| 70 | |
| 71 | private Range(IPersistentMap meta, Object start, Object end, Object step, BoundsCheck boundsCheck, IChunk chunk, ISeq chunkNext){ |
| 72 | super(meta); |
| 73 | this.end = end; |
| 74 | this.start = start; |
| 75 | this.step = step; |
| 76 | this.boundsCheck = boundsCheck; |
nothing calls this directly
no outgoing calls
no test coverage detected