| 15 | import java.io.Serializable; |
| 16 | |
| 17 | public final class ArrayChunk implements IChunk, Serializable { |
| 18 | |
| 19 | private static final long serialVersionUID = -8302142882294545702L; |
| 20 | |
| 21 | final Object[] array; |
| 22 | final int off; |
| 23 | final int end; |
| 24 | |
| 25 | public ArrayChunk(Object[] array){ |
| 26 | this(array, 0, array.length); |
| 27 | } |
| 28 | |
| 29 | public ArrayChunk(Object[] array, int off){ |
| 30 | this(array, off, array.length); |
| 31 | } |
| 32 | |
| 33 | public ArrayChunk(Object[] array, int off, int end){ |
| 34 | this.array = array; |
| 35 | this.off = off; |
| 36 | this.end = end; |
| 37 | } |
| 38 | |
| 39 | public Object nth(int i){ |
| 40 | return array[off + i]; |
| 41 | } |
| 42 | |
| 43 | public Object nth(int i, Object notFound){ |
| 44 | if(i >= 0 && i < count()) |
| 45 | return nth(i); |
| 46 | return notFound; |
| 47 | } |
| 48 | |
| 49 | public int count(){ |
| 50 | return end - off; |
| 51 | } |
| 52 | |
| 53 | public IChunk dropFirst(){ |
| 54 | if(off==end) |
| 55 | throw new IllegalStateException("dropFirst of empty chunk"); |
| 56 | return new ArrayChunk(array, off + 1, end); |
| 57 | } |
| 58 | |
| 59 | public Object reduce(IFn f, Object start) { |
| 60 | Object ret = f.invoke(start, array[off]); |
| 61 | if(RT.isReduced(ret)) |
| 62 | return ret; |
| 63 | for(int x = off + 1; x < end; x++) |
| 64 | { |
| 65 | ret = f.invoke(ret, array[x]); |
| 66 | if(RT.isReduced(ret)) |
| 67 | return ret; |
| 68 | } |
| 69 | return ret; |
| 70 | } |
| 71 | } |
nothing calls this directly
no outgoing calls
no test coverage detected