1 package com.thoughtworks.xstream.core.util; 2 3 public final class ClassStack { 4 5 private Class [] stack; 6 private int pointer; 7 8 public ClassStack(int initialCapacity) { 9 stack = new Class [initialCapacity]; 10 } 11 12 public void push(Class value) { 13 if (pointer + 1 >= stack.length) { 14 resizeStack(stack.length * 2); 15 } 16 stack[pointer++] = value; 17 } 18 19 public void popSilently() { 20 pointer--; 21 } 22 23 public Class pop() { 24 return stack[--pointer]; 25 } 26 27 public Class peek() { 28 return pointer == 0 ? null : stack[pointer - 1]; 29 } 30 31 public int size() { 32 return pointer; 33 } 34 35 public Class get(int i) { 36 return stack[i]; 37 } 38 39 private void resizeStack(int newCapacity) { 40 Class [] newStack = new Class [newCapacity]; 41 System.arraycopy(stack, 0, newStack, 0, Math.min(stack.length, newCapacity)); 42 stack = newStack; 43 } 44 } 45 | Popular Tags |