1 45 package org.openejb.util; 46 47 48 import java.util.ArrayList ; 49 import java.util.EmptyStackException ; 50 51 54 public final class ArrayStack extends ArrayList implements Stack{ 55 56 57 61 public void setSize(int newSize) { 62 if (newSize == 0) clear(); 63 else { 64 for (int i = size() - 1; i >= newSize; i--) remove(i); 65 } 66 } 67 68 71 public Object push(Object item) { 72 add(item); 73 return item; 74 } 75 76 83 public Object pop() { 84 Object obj; 85 obj = peek(); 86 87 int len = size(); 88 remove(len - 1); 89 90 return obj; 91 } 92 93 100 public Object peek() { 101 int len = size(); 102 103 if (len == 0) throw new EmptyStackException (); 104 105 return get(len - 1); 106 } 107 } 108 | Popular Tags |