1 16 19 package org.apache.xml.utils; 20 21 import java.util.EmptyStackException ; 22 23 32 public class IntStack extends IntVector 33 { 34 35 39 public IntStack() 40 { 41 super(); 42 } 43 44 49 public IntStack(int blocksize) 50 { 51 super(blocksize); 52 } 53 54 59 public IntStack (IntStack v) 60 { 61 super(v); 62 } 63 64 70 public int push(int i) 71 { 72 73 if ((m_firstFree + 1) >= m_mapSize) 74 { 75 m_mapSize += m_blocksize; 76 77 int newMap[] = new int[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 final int pop() 98 { 99 return m_map[--m_firstFree]; 100 } 101 102 105 106 public final void quickPop(int n) 107 { 108 m_firstFree -= n; 109 } 110 111 118 public final int peek() 119 { 120 try { 121 return m_map[m_firstFree - 1]; 122 } 123 catch (ArrayIndexOutOfBoundsException e) 124 { 125 throw new EmptyStackException (); 126 } 127 } 128 129 136 public int peek(int n) 137 { 138 try { 139 return m_map[m_firstFree-(1+n)]; 140 } 141 catch (ArrayIndexOutOfBoundsException e) 142 { 143 throw new EmptyStackException (); 144 } 145 } 146 147 154 public void setTop(int val) 155 { 156 try { 157 m_map[m_firstFree - 1] = val; 158 } 159 catch (ArrayIndexOutOfBoundsException e) 160 { 161 throw new EmptyStackException (); 162 } 163 } 164 165 172 public boolean empty() 173 { 174 return m_firstFree == 0; 175 } 176 177 186 public int search(int o) 187 { 188 189 int i = lastIndexOf(o); 190 191 if (i >= 0) 192 { 193 return size() - i; 194 } 195 196 return -1; 197 } 198 199 204 public Object clone() 205 throws CloneNotSupportedException 206 { 207 return (IntStack) super.clone(); 208 } 209 } 210 | Popular Tags |