harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lang Yang <yangl...@gmail.com>
Subject [classlib][imageio]PositionStack
Date Fri, 06 Aug 2010 03:53:08 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message