1 17 package org.apache.commons.collections.primitives; 18 19 import java.util.EmptyStackException ; 20 21 import org.apache.commons.collections.primitives.ArrayByteList; 22 23 32 public class ByteStack 33 { 34 35 private ArrayByteList list = new ArrayByteList() ; 36 37 38 41 public ByteStack() 42 { 43 } 44 45 46 51 public ByteStack( byte[] numbas ) 52 { 53 for ( int ii = 0; ii < numbas.length; ii++ ) 54 { 55 list.add( numbas[ii] ) ; 56 } 57 } 58 59 60 65 public boolean empty() 66 { 67 return list.isEmpty() ; 68 } 69 70 71 77 public byte peek() 78 { 79 if ( list.isEmpty() ) 80 { 81 throw new EmptyStackException () ; 82 } 83 84 return list.get( list.size() - 1 ) ; 85 } 86 87 88 97 public byte peek( int n ) 98 { 99 if ( list.isEmpty() ) 100 { 101 throw new EmptyStackException () ; 102 } 103 104 return list.get( list.size() - n - 1 ) ; 105 } 106 107 108 114 public byte pop() 115 { 116 if ( list.isEmpty() ) 117 { 118 throw new EmptyStackException () ; 119 } 120 121 return list.removeElementAt( list.size() - 1 ) ; 122 } 123 124 125 131 public byte push( byte item ) 132 { 133 list.add( item ) ; 134 return item ; 135 } 136 137 138 148 public int search( byte item ) 149 { 150 for ( int ii = list.size() - 1; ii >= 0; ii-- ) 151 { 152 if ( list.get( ii ) == item ) 153 { 154 return list.size() - ii ; 155 } 156 } 157 158 159 return -1 ; 160 } 161 162 163 171 public byte get( int index ) 172 { 173 return list.get( index ) ; 174 } 175 176 177 182 public int size() 183 { 184 return list.size() ; 185 } 186 187 188 191 public void clear() 192 { 193 list.clear() ; 194 } 195 } 196 | Popular Tags |