1 23 24 39 40 package com.sun.enterprise.util.collection; 41 42 import java.util.ArrayList ; 43 44 56 public class ArrayListStack { 57 private int curIndex; 58 private ArrayList list; 59 60 61 public ArrayListStack(int size) { 62 curIndex = 0; 63 list = new ArrayList (size); 64 } 65 66 67 public ArrayListStack() { 68 this(20); 69 } 70 71 75 public int size() { 76 return curIndex; 77 } 78 79 85 public void push(Object obj) { 86 list.add(curIndex, obj); 87 curIndex += 1; 88 } 89 90 96 public Object pop() { 97 if (curIndex > 0) { 98 curIndex -= 1; 99 return list.remove(curIndex); 100 } 101 return null; 102 } 103 104 109 public boolean empty() { 110 return curIndex == 0; 111 } 112 113 119 public Object peek() { 120 Object top = null; 121 if (curIndex > 0) { 122 top = list.get(curIndex - 1); 123 } 124 return top; 125 } 126 } 127 | Popular Tags |