KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > core > util > ClassStack


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