Hello guys,
I was reviewing ImageIO, and found this class:
javax.imageio.stream.ImageInputStreamImpl:
private static class PositionStack {
private static final int SIZE = 10;
private long[] values = new long[SIZE];
private int pos = 0;
void push(long v) {
if (pos >= values.length) {
ensure(pos + 1);
}
values[pos++] = v;
}
long pop() {
return values[--pos];
}
boolean isEmpty() {
return pos == 0;
}
private void ensure(int size) {
long[] arr = new long[Math.max(2 * values.length, size)];
System.arraycopy(values, 0, arr, 0, values.length);
values = arr;
}
}
Essentially, it's just a stack, but why do we create this class rather than
just use the standard Stack<Long> class?
Regards,
Lang