9 array = new Object[10];
12 public Vector(int size) {
13 capacityIncrement = 0;
15 array = new Object[size];
18 // used for internal cloning
19 private Vector(int size, int capacityIncrement, Object[] array) {
21 this.capacityIncrement = capacityIncrement;
22 this.array = new Object[array.length];
23 System.arraycopy(array, 0, this.array, 0, size);
26 public Vector clone() {
27 return new Vector(size, capacityIncrement, array);
30 public boolean isEmpty() {
36 array = new Object[10];
39 public int indexOf(Object elem) {
40 return indexOf(elem, 0);
43 public int indexOf(Object elem, int index) {
44 for (int i = index; i < size; i++) {
45 if (elem.equals(array[i]))
51 public boolean contains(Object e) {
52 return indexOf(e) != -1;
55 public boolean remove(Object o) {
65 public Object elementAt(int index) {
66 if (index < 0 | index >= size) {
67 System.printString("Illegal Vector.elementAt\n");
74 public void setElementAt(Object obj, int index) {
78 System.printString("Illegal Vector.setElementAt\n");
83 private void ensureCapacity(int minCapacity) {
84 if (minCapacity > array.length) {
86 if (capacityIncrement <= 0)
87 newsize = array.length * 2;
89 newsize = array.length + capacityIncrement;
90 if (newsize < minCapacity)
91 newsize = minCapacity;
92 Object[] newarray = new Object[newsize];
93 for (int i = 0; i < size; i++)
94 newarray[i] = array[i];
103 public Enumeration elements() {
104 System.printString("Vector.elements not implemented\n");
108 public void addElement(Object obj) {
109 if (size == array.length) {
110 ensureCapacity(size + 1);
115 public void insertElementAt(Object obj, int index) {
116 if (index < 0 || index > size) {
117 System.printString("Illegal Vector.insertElementAt\n");
121 if (size == array.length) {
122 ensureCapacity(size + 1);
125 for (int i = size - 1; i > index; --i) {
126 array[i] = array[i - 1];
131 public void removeElementAt(int index) {
132 if (index < 0 || index >= size) {
133 System.printString("Illegal Vector.removeElementAt\n");
136 removeElement(array, index, size);
141 public static native void removeElement(Object[] array, int index, int size);
143 public void removeAllElements() {
145 for (int i = 0; i < s; ++i) {