Never mind, I think I can just cast int to long, instead of creating a new int stack.
On Sun, Aug 8, 2010 at 8:46 PM, Lang Yang <yangl...@gmail.com> wrote: > Hello Alexey, > > Thanks for the explanation. It happens that an int stack is also needed. It > just looks a little bit redundant to have two almost the same classes at > here though, the only difference is the datetype, one is long, the other one > is int ;) > > Regards, > > Lang > > On Fri, Aug 6, 2010 at 4:38 AM, Alexey Petrenko < > alexey.a.petre...@gmail.com> wrote: > >> I see at least two reasons: this class is not synchronized and it >> works with primitive types instead of objects. >> So it can be a bit faster on certain circumstances... >> >> Thanks. >> >> Alexey >> >> 2010/8/6 Lang Yang <yangl...@gmail.com>: >> > 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 >> > >> > >