public int count() { try { long c = rangeCount(start, end, step); if(c > Integer.MAX_VALUE) { return Numbers.throwIntOverflow(); } else { return (int) c; } } catch(ArithmeticException e) { // rare case from large range or step, fall back to iterating and counting Iterator iter = this.iterator(); long count = 0; while(iter.hasNext()) { iter.next(); count++; } if(count > Integer.MAX_VALUE) return Numbers.throwIntOverflow(); else return (int)count; } }
public void forceChunk() { if(_chunk != null) return; long count; try { count = rangeCount(start, end, step); } catch(ArithmeticException e) { // size of total range is > Long.MAX_VALUE so must step to count // this only happens in pathological range cases like: // (range -9223372036854775808 9223372036854775807 9223372036854775807) count = steppingCount(start, end, step); } if (count > CHUNK_SIZE) { // not last chunk long nextStart = start + (step * CHUNK_SIZE); // cannot overflow, must be < end _chunkNext = new LongRange(nextStart, end, step, boundsCheck); _chunk = new LongChunk(start, step, CHUNK_SIZE); } else { // last chunk _chunk = new LongChunk(start, step, (int) count); // count must be <= CHUNK_SIZE } }
public int count() { try { long c = rangeCount(start, end, step); if(c > Integer.MAX_VALUE) { return Numbers.throwIntOverflow(); } else { return (int) c; } } catch(ArithmeticException e) { // rare case from large range or step, fall back to iterating and counting Iterator iter = this.iterator(); long count = 0; while(iter.hasNext()) { iter.next(); count++; } if(count > Integer.MAX_VALUE) return Numbers.throwIntOverflow(); else return (int)count; } }
public void forceChunk() { if(_chunk != null) return; long count; try { count = rangeCount(start, end, step); } catch(ArithmeticException e) { // size of total range is > Long.MAX_VALUE so must step to count // this only happens in pathological range cases like: // (range -9223372036854775808 9223372036854775807 9223372036854775807) count = steppingCount(start, end, step); } if (count > CHUNK_SIZE) { // not last chunk long nextStart = start + (step * CHUNK_SIZE); // cannot overflow, must be < end _chunk = new LongChunk(start, step, CHUNK_SIZE); _chunkNext = new LongRange(nextStart, end, step, boundsCheck); } else { // last chunk _chunk = new LongChunk(start, step, (int) count); // count must be <= CHUNK_SIZE } }