1 57 58 package com.sun.org.apache.xerces.internal.util; 59 60 69 public final class IntStack { 70 71 75 76 private int fDepth; 77 78 79 private int[] fData; 80 81 85 86 public int size() { 87 return fDepth; 88 } 89 90 91 public void push(int value) { 92 ensureCapacity(fDepth + 1); 93 fData[fDepth++] = value; 94 } 95 96 97 public int peek() { 98 return fData[fDepth - 1]; 99 } 100 101 102 public int elementAt(int depth) { 103 return fData[depth]; 104 } 105 106 107 public int pop() { 108 return fData[--fDepth]; 109 } 110 111 112 public void clear() { 113 fDepth = 0; 114 } 115 116 118 119 public void print() { 120 System.out.print('('); 121 System.out.print(fDepth); 122 System.out.print(") {"); 123 for (int i = 0; i < fDepth; i++) { 124 if (i == 3) { 125 System.out.print(" ..."); 126 break; 127 } 128 System.out.print(' '); 129 System.out.print(fData[i]); 130 if (i < fDepth - 1) { 131 System.out.print(','); 132 } 133 } 134 System.out.print(" }"); 135 System.out.println(); 136 } 137 138 142 143 private void ensureCapacity(int size) { 144 if (fData == null) { 145 fData = new int[32]; 146 } 147 else if (fData.length <= size) { 148 int[] newdata = new int[fData.length * 2]; 149 System.arraycopy(fData, 0, newdata, 0, fData.length); 150 fData = newdata; 151 } 152 } 153 154 } | Popular Tags |