1 14 package org.wings.util; 15 16 23 public final class FastStack { 24 private Object [] elements; 25 private int pos; 26 27 public FastStack(int initialElements) { 28 pos = -1; 29 elements = new Object [initialElements]; 30 } 31 32 35 public void clear() { 36 pos = -1; 37 } 38 39 public boolean isEmpty() { 40 return pos == -1; 41 } 42 43 46 public void push(Object o) { 47 ++pos; 48 if (pos == elements.length) resize(); 49 54 elements[pos] = o; 55 } 56 57 public Object peek() { 58 return elements[pos]; 59 } 60 61 65 public void pop() { 66 --pos; 67 } 68 69 72 private void resize() { 73 Object [] newArray = new Object [elements.length * 2]; 74 System.arraycopy(elements, 0, newArray, 0, elements.length); 75 elements = newArray; 76 } 77 } 78 79 80 | Popular Tags |