1 16 19 package com.sun.org.apache.xml.internal.utils; 20 21 22 26 public final class BoolStack implements Cloneable 27 { 28 29 30 private boolean m_values[]; 31 32 33 private int m_allocatedSize; 34 35 36 private int m_index; 37 38 42 public BoolStack() 43 { 44 this(32); 45 } 46 47 52 public BoolStack(int size) 53 { 54 55 m_allocatedSize = size; 56 m_values = new boolean[size]; 57 m_index = -1; 58 } 59 60 65 public final int size() 66 { 67 return m_index + 1; 68 } 69 70 74 public final void clear() 75 { 76 m_index = -1; 77 } 78 79 86 public final boolean push(boolean val) 87 { 88 89 if (m_index == m_allocatedSize - 1) 90 grow(); 91 92 return (m_values[++m_index] = val); 93 } 94 95 102 public final boolean pop() 103 { 104 return m_values[m_index--]; 105 } 106 107 114 public final boolean popAndTop() 115 { 116 117 m_index--; 118 119 return (m_index >= 0) ? m_values[m_index] : false; 120 } 121 122 128 public final void setTop(boolean b) 129 { 130 m_values[m_index] = b; 131 } 132 133 140 public final boolean peek() 141 { 142 return m_values[m_index]; 143 } 144 145 151 public final boolean peekOrFalse() 152 { 153 return (m_index > -1) ? m_values[m_index] : false; 154 } 155 156 162 public final boolean peekOrTrue() 163 { 164 return (m_index > -1) ? m_values[m_index] : true; 165 } 166 167 173 public boolean isEmpty() 174 { 175 return (m_index == -1); 176 } 177 178 182 private void grow() 183 { 184 185 m_allocatedSize *= 2; 186 187 boolean newVector[] = new boolean[m_allocatedSize]; 188 189 System.arraycopy(m_values, 0, newVector, 0, m_index + 1); 190 191 m_values = newVector; 192 } 193 194 public Object clone() 195 throws CloneNotSupportedException 196 { 197 return super.clone(); 198 } 199 200 } 201 | Popular Tags |