1 16 19 package com.sun.org.apache.xml.internal.utils; 20 21 31 public class ObjectVector implements Cloneable 32 { 33 34 35 protected int m_blocksize; 36 37 38 protected Object m_map[]; 39 40 41 protected int m_firstFree = 0; 42 43 44 protected int m_mapSize; 45 46 50 public ObjectVector() 51 { 52 53 m_blocksize = 32; 54 m_mapSize = m_blocksize; 55 m_map = new Object [m_blocksize]; 56 } 57 58 63 public ObjectVector(int blocksize) 64 { 65 66 m_blocksize = blocksize; 67 m_mapSize = blocksize; 68 m_map = new Object [blocksize]; 69 } 70 71 76 public ObjectVector(int blocksize, int increaseSize) 77 { 78 79 m_blocksize = increaseSize; 80 m_mapSize = blocksize; 81 m_map = new Object [blocksize]; 82 } 83 84 89 public ObjectVector(ObjectVector v) 90 { 91 m_map = new Object [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(Object value) 125 { 126 127 if ((m_firstFree + 1) >= m_mapSize) 128 { 129 m_mapSize += m_blocksize; 130 131 Object newMap[] = new Object [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(Object value, int numberOfElements) 149 { 150 151 if ((m_firstFree + numberOfElements) >= m_mapSize) 152 { 153 m_mapSize += (m_blocksize+numberOfElements); 154 155 Object newMap[] = new Object [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 Object newMap[] = new Object [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(Object value, int at) 202 { 203 204 if ((m_firstFree + 1) >= m_mapSize) 205 { 206 m_mapSize += m_blocksize; 207 208 Object newMap[] = new Object [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 228 public final void removeAllElements() 229 { 230 231 for (int i = 0; i < m_firstFree; i++) 232 { 233 m_map[i] = null; 234 } 235 236 m_firstFree = 0; 237 } 238 239 250 public final boolean removeElement(Object s) 251 { 252 253 for (int i = 0; i < m_firstFree; i++) 254 { 255 if (m_map[i] == s) 256 { 257 if ((i + 1) < m_firstFree) 258 System.arraycopy(m_map, i + 1, m_map, i - 1, m_firstFree - i); 259 else 260 m_map[i] = null; 261 262 m_firstFree--; 263 264 return true; 265 } 266 } 267 268 return false; 269 } 270 271 279 public final void removeElementAt(int i) 280 { 281 282 if (i > m_firstFree) 283 System.arraycopy(m_map, i + 1, m_map, i, m_firstFree); 284 else 285 m_map[i] = null; 286 287 m_firstFree--; 288 } 289 290 300 public final void setElementAt(Object value, int index) 301 { 302 m_map[index] = value; 303 } 304 305 312 public final Object elementAt(int i) 313 { 314 return m_map[i]; 315 } 316 317 324 public final boolean contains(Object s) 325 { 326 327 for (int i = 0; i < m_firstFree; i++) 328 { 329 if (m_map[i] == s) 330 return true; 331 } 332 333 return false; 334 } 335 336 347 public final int indexOf(Object elem, int index) 348 { 349 350 for (int i = index; i < m_firstFree; i++) 351 { 352 if (m_map[i] == elem) 353 return i; 354 } 355 356 return java.lang.Integer.MIN_VALUE; 357 } 358 359 369 public final int indexOf(Object elem) 370 { 371 372 for (int i = 0; i < m_firstFree; i++) 373 { 374 if (m_map[i] == elem) 375 return i; 376 } 377 378 return java.lang.Integer.MIN_VALUE; 379 } 380 381 391 public final int lastIndexOf(Object elem) 392 { 393 394 for (int i = (m_firstFree - 1); i >= 0; i--) 395 { 396 if (m_map[i] == elem) 397 return i; 398 } 399 400 return java.lang.Integer.MIN_VALUE; 401 } 402 403 408 public final void setToSize(int size) { 409 410 Object newMap[] = new Object [size]; 411 412 System.arraycopy(m_map, 0, newMap, 0, m_firstFree); 413 m_mapSize = size; 414 415 m_map = newMap; 416 417 } 418 419 424 public Object clone() 425 throws CloneNotSupportedException 426 { 427 return new ObjectVector(this); 428 } 429 } 430 | Popular Tags |