1 public class Vector implements Set {
12 public Vector(int size) {
15 array=new Object[size];
18 public boolean isEmpty() {
27 public int indexOf(Object elem) {
28 return indexOf(elem, 0);
31 public int indexOf(Object elem, int index) {
32 for(int i=index; i<size; i++) {
33 if (elem.equals(array[i]))
39 public boolean contains(Object e) {
40 return indexOf(e)!=-1;
43 public void remove(Object o) {
49 public Object elementAt(int index) {
50 if (index<0 | index >=size) {
51 System.printString("Illegal Vector.elementAt\n");
58 public void setElementAt(Object obj, int index) {
62 System.printString("Illegal Vector.setElementAt\n");
67 private ensureCapacity(int minCapacity) {
68 if (minCapacity>array.length) {
70 if (capacityIncrement<=0)
71 newsize=array.length*2;
73 newsize=array.length+capacityIncrement;
74 if (newsize<minCapacity)
76 Object [] newarray=new Object[newsize];
77 for(int i=0; i<size; i++)
87 public Enumeration elements() {
88 System.printString("Vector.elements not implemented\n");
92 public void addElement(Object obj) {
93 if (size==array.length) {
94 ensureCapacity(size+1);
99 public boolean add(Object obj) {
100 if (size==array.length) {
101 ensureCapacity(size+1);
107 public void insertElementAt(Object obj, int index) {
108 if (index<0||index>size) {
109 System.printString("Illegal Vector.insertElementAt\n");
113 if (size==array.length) {
114 ensureCapacity(size+1);
117 for(int i=size-1; i>index; --i) {
118 array[i] = array[i-1];
123 public void removeElementAt(int index) {
124 if (index<0||index>=size) {
125 System.printString("Illegal Vector.removeElementAt\n");
128 removeElement(array, index, size);
133 public static native void removeElement(Object[] array, int index, int size);
135 public void removeAllElements() {
137 for(int i = 0; i<s; ++i ) {
142 public Object[] toArray() {
143 Object[] tarray = new Object[this.size];
144 for(int i = 0; i < this.size; i++) {
145 tarray[i] = this.array[i];
150 public Vector(Set s) {
151 Object[] sarray = s.toArray();
153 this.size=sarray.length;