1 11 package org.eclipse.jdt.internal.compiler.util; 12 13 public final class ObjectVector { 14 15 static int INITIAL_SIZE = 10; 16 17 public int size; 18 int maxSize; 19 Object [] elements; 20 21 public ObjectVector() { 22 this(INITIAL_SIZE); 23 } 24 25 public ObjectVector(int initialSize) { 26 this.maxSize = initialSize > 0 ? initialSize : INITIAL_SIZE; 27 this.size = 0; 28 this.elements = new Object [this.maxSize]; 29 } 30 31 public void add(Object newElement) { 32 33 if (this.size == this.maxSize) System.arraycopy(this.elements, 0, (this.elements = new Object [this.maxSize *= 2]), 0, this.size); 35 this.elements[this.size++] = newElement; 36 } 37 38 public void addAll(Object [] newElements) { 39 40 if (this.size + newElements.length >= this.maxSize) { 41 maxSize = this.size + newElements.length; System.arraycopy(this.elements, 0, (this.elements = new Object [this.maxSize]), 0, this.size); 43 } 44 System.arraycopy(newElements, 0, this.elements, size, newElements.length); 45 this.size += newElements.length; 46 } 47 48 public void addAll(ObjectVector newVector) { 49 50 if (this.size + newVector.size >= this.maxSize) { 51 maxSize = this.size + newVector.size; System.arraycopy(this.elements, 0, (this.elements = new Object [this.maxSize]), 0, this.size); 53 } 54 System.arraycopy(newVector.elements, 0, this.elements, size, newVector.size); 55 this.size += newVector.size; 56 } 57 58 61 public boolean containsIdentical(Object element) { 62 63 for (int i = this.size; --i >= 0;) 64 if (element == this.elements[i]) 65 return true; 66 return false; 67 } 68 69 72 public boolean contains(Object element) { 73 74 for (int i = this.size; --i >= 0;) 75 if (element.equals(this.elements[i])) 76 return true; 77 return false; 78 } 79 80 public void copyInto(Object [] targetArray){ 81 82 this.copyInto(targetArray, 0); 83 } 84 85 public void copyInto(Object [] targetArray, int index){ 86 87 System.arraycopy(this.elements, 0, targetArray, index, this.size); 88 } 89 90 public Object elementAt(int index) { 91 92 return this.elements[index]; 93 } 94 95 public Object find(Object element) { 96 97 for (int i = this.size; --i >= 0;) 98 if (element.equals(this.elements[i])) 99 return element; 100 return null; 101 } 102 103 public Object remove(Object element) { 104 105 for (int i = this.size; --i >= 0;) 107 if (element.equals(this.elements[i])) { 108 System.arraycopy(this.elements, i + 1, this.elements, i, --this.size - i); 110 this.elements[this.size] = null; 111 return element; 112 } 113 return null; 114 } 115 116 public void removeAll() { 117 118 for (int i = this.size; --i >= 0;) 119 this.elements[i] = null; 120 this.size = 0; 121 } 122 123 public int size(){ 124 125 return this.size; 126 } 127 128 public String toString() { 129 130 String s = ""; for (int i = 0; i < this.size; i++) 132 s += this.elements[i].toString() + "\n"; return s; 134 } 135 } 136 | Popular Tags |