1 16 19 package com.sun.org.apache.xml.internal.utils; 20 21 31 public class IntVector implements Cloneable 32 { 33 34 35 protected int m_blocksize; 36 37 38 protected int m_map[]; 40 41 protected int m_firstFree = 0; 42 43 44 protected int m_mapSize; 45 46 50 public IntVector() 51 { 52 53 m_blocksize = 32; 54 m_mapSize = m_blocksize; 55 m_map = new int[m_blocksize]; 56 } 57 58 63 public IntVector(int blocksize) 64 { 65 66 m_blocksize = blocksize; 67 m_mapSize = blocksize; 68 m_map = new int[blocksize]; 69 } 70 71 76 public IntVector(int blocksize, int increaseSize) 77 { 78 79 m_blocksize = increaseSize; 80 m_mapSize = blocksize; 81 m_map = new int[blocksize]; 82 } 83 84 89 public IntVector(IntVector v) 90 { 91 m_map = new int[v.m_mapSize]; 92 m_mapSize = v.m_mapSize; 93 m_firstFree = v.m_firstFree; 94 m_blocksize = v.m_blocksize; 95 System.arraycopy(v.m_map, 0, m_map, 0, m_firstFree); 96 } 97 98 103 public final int size() 104 { 105 return m_firstFree; 106 } 107 108 113 public final void setSize(int sz) 114 { 115 m_firstFree = sz; 116 } 117 118 119 124 public final void addElement(int value) 125 { 126 127 if ((m_firstFree + 1) >= m_mapSize) 128 { 129 m_mapSize += m_blocksize; 130 131 int newMap[] = new int[m_mapSize]; 132 133 System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1); 134 135 m_map = newMap; 136 } 137 138 m_map[m_firstFree] = value; 139 140 m_firstFree++; 141 } 142 143 148 public final void addElements(int value, int numberOfElements) 149 { 150 151 if ((m_firstFree + numberOfElements) >= m_mapSize) 152 { 153 m_mapSize += (m_blocksize+numberOfElements); 154 155 int newMap[] = new int[m_mapSize]; 156 157 System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1); 158 159 m_map = newMap; 160 } 161 162 for (int i = 0; i < numberOfElements; i++) 163 { 164 m_map[m_firstFree] = value; 165 m_firstFree++; 166 } 167 } 168 169 174 public final void addElements(int numberOfElements) 175 { 176 177 if ((m_firstFree + numberOfElements) >= m_mapSize) 178 { 179 m_mapSize += (m_blocksize+numberOfElements); 180 181 int newMap[] = new int[m_mapSize]; 182 183 System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1); 184 185 m_map = newMap; 186 } 187 188 m_firstFree += numberOfElements; 189 } 190 191 192 201 public final void insertElementAt(int value, int at) 202 { 203 204 if ((m_firstFree + 1) >= m_mapSize) 205 { 206 m_mapSize += m_blocksize; 207 208 int newMap[] = new int[m_mapSize]; 209 210 System.arraycopy(m_map, 0, newMap, 0, m_firstFree + 1); 211 212 m_map = newMap; 213 } 214 215 if (at <= (m_firstFree - 1)) 216 { 217 System.arraycopy(m_map, at, m_map, at + 1, m_firstFree - at); 218 } 219 220 m_map[at] = value; 221 222 m_firstFree++; 223 } 224 225 231 public final void removeAllElements() 232 { 233 234 for (int i = 0; i < m_firstFree; i++) 235 { 236 m_map[i] = java.lang.Integer.MIN_VALUE; 237 } 238 239 m_firstFree = 0; 240 } 241 242 253 public final boolean removeElement(int s) 254 { 255 256 for (int i = 0; i < m_firstFree; i++) 257 { 258 if (m_map[i] == s) 259 { 260 if ((i + 1) < m_firstFree) 261 System.arraycopy(m_map, i + 1, m_map, i - 1, m_firstFree - i); 262 else 263 m_map[i] = java.lang.Integer.MIN_VALUE; 264 265 m_firstFree--; 266 267 return true; 268 } 269 } 270 271 return false; 272 } 273 274 282 public final void removeElementAt(int i) 283 { 284 285 if (i > m_firstFree) 286 System.arraycopy(m_map, i + 1, m_map, i, m_firstFree); 287 else 288 m_map[i] = java.lang.Integer.MIN_VALUE; 289 290 m_firstFree--; 291 } 292 293 303 public final void setElementAt(int value, int index) 304 { 305 m_map[index] = value; 306 } 307 308 315 public final int elementAt(int i) 316 { 317 return m_map[i]; 318 } 319 320 327 public final boolean contains(int s) 328 { 329 330 for (int i = 0; i < m_firstFree; i++) 331 { 332 if (m_map[i] == s) 333 return true; 334 } 335 336 return false; 337 } 338 339 350 public final int indexOf(int elem, int index) 351 { 352 353 for (int i = index; i < m_firstFree; i++) 354 { 355 if (m_map[i] == elem) 356 return i; 357 } 358 359 return java.lang.Integer.MIN_VALUE; 360 } 361 362 372 public final int indexOf(int elem) 373 { 374 375 for (int i = 0; i < m_firstFree; i++) 376 { 377 if (m_map[i] == elem) 378 return i; 379 } 380 381 return java.lang.Integer.MIN_VALUE; 382 } 383 384 394 public final int lastIndexOf(int elem) 395 { 396 397 for (int i = (m_firstFree - 1); i >= 0; i--) 398 { 399 if (m_map[i] == elem) 400 return i; 401 } 402 403 return java.lang.Integer.MIN_VALUE; 404 } 405 406 411 public Object clone() 412 throws CloneNotSupportedException 413 { 414 return new IntVector(this); 415 } 416 417 } 418 | Popular Tags |