1 16 19 package com.sun.org.apache.xml.internal.serializer.utils; 20 21 22 35 public final class BoolStack 36 { 37 38 39 private boolean m_values[]; 40 41 42 private int m_allocatedSize; 43 44 45 private int m_index; 46 47 51 public BoolStack() 52 { 53 this(32); 54 } 55 56 61 public BoolStack(int size) 62 { 63 64 m_allocatedSize = size; 65 m_values = new boolean[size]; 66 m_index = -1; 67 } 68 69 74 public final int size() 75 { 76 return m_index + 1; 77 } 78 79 83 public final void clear() 84 { 85 m_index = -1; 86 } 87 88 95 public final boolean push(boolean val) 96 { 97 98 if (m_index == m_allocatedSize - 1) 99 grow(); 100 101 return (m_values[++m_index] = val); 102 } 103 104 111 public final boolean pop() 112 { 113 return m_values[m_index--]; 114 } 115 116 123 public final boolean popAndTop() 124 { 125 126 m_index--; 127 128 return (m_index >= 0) ? m_values[m_index] : false; 129 } 130 131 137 public final void setTop(boolean b) 138 { 139 m_values[m_index] = b; 140 } 141 142 149 public final boolean peek() 150 { 151 return m_values[m_index]; 152 } 153 154 160 public final boolean peekOrFalse() 161 { 162 return (m_index > -1) ? m_values[m_index] : false; 163 } 164 165 171 public final boolean peekOrTrue() 172 { 173 return (m_index > -1) ? m_values[m_index] : true; 174 } 175 176 182 public boolean isEmpty() 183 { 184 return (m_index == -1); 185 } 186 187 191 private void grow() 192 { 193 194 m_allocatedSize *= 2; 195 196 boolean newVector[] = new boolean[m_allocatedSize]; 197 198 System.arraycopy(m_values, 0, newVector, 0, m_index + 1); 199 200 m_values = newVector; 201 } 202 } 203 | Popular Tags |