1 16 19 package org.apache.xml.utils; 20 21 import java.util.EmptyStackException ; 22 23 32 public class ObjectStack extends ObjectVector 33 { 34 35 39 public ObjectStack() 40 { 41 super(); 42 } 43 44 49 public ObjectStack(int blocksize) 50 { 51 super(blocksize); 52 } 53 54 59 public ObjectStack (ObjectStack v) 60 { 61 super(v); 62 } 63 64 70 public Object push(Object i) 71 { 72 73 if ((m_firstFree + 1) >= m_mapSize) 74 { 75 m_mapSize += m_blocksize; 76 77 Object newMap[] = new Object [m_mapSize]; 78 79 System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1); 80 81 m_map = newMap; 82 } 83 84 m_map[m_firstFree] = i; 85 86 m_firstFree++; 87 88 return i; 89 } 90 91 97 public Object pop() 98 { 99 Object val = m_map[--m_firstFree]; 100 m_map[m_firstFree] = null; 101 102 return val; 103 } 104 105 108 109 public void quickPop(int n) 110 { 111 m_firstFree -= n; 112 } 113 114 121 public Object peek() 122 { 123 try { 124 return m_map[m_firstFree - 1]; 125 } 126 catch (ArrayIndexOutOfBoundsException e) 127 { 128 throw new EmptyStackException (); 129 } 130 } 131 132 139 public Object peek(int n) 140 { 141 try { 142 return m_map[m_firstFree-(1+n)]; 143 } 144 catch (ArrayIndexOutOfBoundsException e) 145 { 146 throw new EmptyStackException (); 147 } 148 } 149 150 157 public void setTop(Object val) 158 { 159 try { 160 m_map[m_firstFree - 1] = val; 161 } 162 catch (ArrayIndexOutOfBoundsException e) 163 { 164 throw new EmptyStackException (); 165 } 166 } 167 168 175 public boolean empty() 176 { 177 return m_firstFree == 0; 178 } 179 180 189 public int search(Object o) 190 { 191 192 int i = lastIndexOf(o); 193 194 if (i >= 0) 195 { 196 return size() - i; 197 } 198 199 return -1; 200 } 201 202 207 public Object clone() 208 throws CloneNotSupportedException 209 { 210 return (ObjectStack) super.clone(); 211 } 212 213 } 214 | Popular Tags |