1 16 package org.apache.cocoon.components.flow.java; 17 18 import java.util.EmptyStackException ; 19 20 27 public class ContinuationStack implements java.io.Serializable { 28 29 private int[] istack; 30 private float[] fstack; 31 private double[] dstack; 32 private long[] lstack; 33 private Object [] astack; 34 private Object [] tstack; 35 private int iTop, fTop, dTop, lTop, aTop, tTop; 36 37 public ContinuationStack() { 38 istack = new int[10]; 39 lstack = new long[5]; 40 dstack = new double[5]; 41 fstack = new float[5]; 42 astack = new Object [10]; 43 tstack = new Object [5]; 44 } 45 46 public ContinuationStack(ContinuationStack parent) { 47 istack = new int[parent.istack.length]; 48 lstack = new long[parent.lstack.length]; 49 dstack = new double[parent.dstack.length]; 50 fstack = new float[parent.fstack.length]; 51 astack = new Object [parent.astack.length]; 52 tstack = new Object [parent.tstack.length]; 53 System.arraycopy(parent.istack, 0, istack, 0, parent.istack.length); 54 System.arraycopy(parent.lstack, 0, lstack, 0, parent.lstack.length); 55 System.arraycopy(parent.dstack, 0, dstack, 0, parent.dstack.length); 56 System.arraycopy(parent.fstack, 0, fstack, 0, parent.fstack.length); 57 System.arraycopy(parent.astack, 0, astack, 0, parent.astack.length); 58 System.arraycopy(parent.tstack, 0, tstack, 0, parent.tstack.length); 59 iTop = parent.iTop; 60 fTop = parent.fTop; 61 dTop = parent.dTop; 62 lTop = parent.lTop; 63 aTop = parent.aTop; 64 tTop = parent.tTop; 65 } 66 67 public double popDouble() { 68 if (dTop==0) 69 throw new EmptyStackException (); 70 double d = dstack[--dTop]; 71 return d; 73 } 74 75 public float popFloat() { 76 if (fTop==0) 77 throw new EmptyStackException (); 78 float f = fstack[--fTop]; 79 return f; 81 } 82 83 public int popInt() { 84 if (iTop==0) 85 throw new EmptyStackException (); 86 int i = istack[--iTop]; 87 return i; 89 } 90 91 public long popLong() { 92 if (lTop==0) 93 throw new EmptyStackException (); 94 long l = lstack[--lTop]; 95 return l; 97 } 98 99 public Object popObject() { 100 if (aTop==0) 101 throw new EmptyStackException (); 102 Object o = astack[--aTop]; 103 return o; 105 } 106 107 public Object popReference() { 108 if (tTop==0) 109 throw new EmptyStackException (); 110 Object o = tstack[--tTop]; 111 return o; 113 } 114 115 public void pushDouble(double d) { 116 dstack[dTop++] = d; 117 if (dTop == dstack.length) { 119 double[] hlp = new double[dstack.length + 10]; 120 System.arraycopy(dstack, 0, hlp, 0, dstack.length); 121 dstack = hlp; 122 } 123 } 124 125 public void pushFloat(float f) { 126 fstack[fTop++] = f; 127 if (fTop == fstack.length) { 129 float[] hlp = new float[fstack.length + 10]; 130 System.arraycopy(fstack, 0, hlp, 0, fstack.length); 131 fstack = hlp; 132 } 133 } 134 135 public void pushInt(int i) { 136 istack[iTop++] = i; 137 if (iTop == istack.length) { 139 int[] hlp = new int[istack.length + 10]; 140 System.arraycopy(istack, 0, hlp, 0, istack.length); 141 istack = hlp; 142 } 143 } 144 145 public void pushLong(long l) { 146 lstack[lTop++] = l; 147 if (lTop == lstack.length) { 149 long[] hlp = new long[lstack.length + 10]; 150 System.arraycopy(lstack, 0, hlp, 0, lstack.length); 151 lstack = hlp; 152 } 153 } 154 155 public void pushObject(Object o) { 156 astack[aTop++] = o; 157 if (aTop == astack.length) { 159 Object [] hlp = new Object [astack.length + 10]; 160 System.arraycopy(astack, 0, hlp, 0, astack.length); 161 astack = hlp; 162 } 163 } 164 165 public void pushReference(Object o) { 166 tstack[tTop++] = o; 167 if (tTop == tstack.length) { 169 Object [] hlp = new Object [tstack.length + 10]; 170 System.arraycopy(tstack, 0, hlp, 0, tstack.length); 171 tstack = hlp; 172 } 173 } 174 175 public String toString() { 176 return "i="+iTop + 177 ",l=" + lTop + 178 ",d=" + dTop + 179 ",f=" + fTop + 180 ",a=" + aTop + 181 ",t=" + tTop; 182 } 183 } 184 | Popular Tags |