1 16 17 package org.apache.xerces.util; 18 19 28 public final class IntStack { 29 30 34 35 private int fDepth; 36 37 38 private int[] fData; 39 40 44 45 public int size() { 46 return fDepth; 47 } 48 49 50 public void push(int value) { 51 ensureCapacity(fDepth + 1); 52 fData[fDepth++] = value; 53 } 54 55 56 public int peek() { 57 return fData[fDepth - 1]; 58 } 59 60 61 public int elementAt(int depth) { 62 return fData[depth]; 63 } 64 65 66 public int pop() { 67 return fData[--fDepth]; 68 } 69 70 71 public void clear() { 72 fDepth = 0; 73 } 74 75 77 78 public void print() { 79 System.out.print('('); 80 System.out.print(fDepth); 81 System.out.print(") {"); 82 for (int i = 0; i < fDepth; i++) { 83 if (i == 3) { 84 System.out.print(" ..."); 85 break; 86 } 87 System.out.print(' '); 88 System.out.print(fData[i]); 89 if (i < fDepth - 1) { 90 System.out.print(','); 91 } 92 } 93 System.out.print(" }"); 94 System.out.println(); 95 } 96 97 101 102 private void ensureCapacity(int size) { 103 if (fData == null) { 104 fData = new int[32]; 105 } 106 else if (fData.length <= size) { 107 int[] newdata = new int[fData.length * 2]; 108 System.arraycopy(fData, 0, newdata, 0, fData.length); 109 fData = newdata; 110 } 111 } 112 113 } | Popular Tags |