00001 00066 package com.arcle.rmt.superwaba.util; 00067 00068 import waba.util.Vector; 00069 import com.arcle.rmt.xplat.util.List; 00070 import com.arcle.rmt.xplat.util.Iterator; 00071 00076 public class VectorListAdapter implements List { 00077 00078 public VectorListAdapter(int initialCapacity) { 00079 this(new Vector(initialCapacity)); 00080 } 00081 00082 00083 public VectorListAdapter(Vector v) { 00084 theVector = v; 00085 } 00086 00087 public VectorListAdapter() { 00088 // waba.util.Vector is a final class, so there is no point in using 00089 // a factory method to instantiate it. 00090 this(new Vector()); 00091 } 00092 00093 //----------------------------------------------------------------------- 00094 // Own implementation 00095 00099 public Vector getVector() { 00100 return theVector; 00101 } 00102 00103 //----------------------------------------------------------------------- 00104 // Factory Methods 00105 00106 protected Iterator createIterator() { 00107 return new IteratorImpl(this); 00108 } 00109 00110 00111 //----------------------------------------------------------------------- 00112 // Instance Variables 00113 00114 private Vector theVector; 00115 00116 //----------------------------------------------------------------------- 00117 // List implementations 00118 00119 00120 public int size() { 00121 return getVector().getCount(); 00122 } 00123 00124 00125 public boolean isEmpty() { 00126 return size() == 0; 00127 } 00128 00129 public boolean contains(Object o) { 00130 return indexOf(o) >= 0; 00131 } 00132 00133 public Iterator iterator() { 00134 return createIterator(); 00135 } 00136 00137 00138 public Object[] toArray() { 00139 return getVector().toObjectArray(); 00140 } 00141 00142 // Modification Operations 00143 00144 public boolean add(Object o) { 00145 getVector().add(o); 00146 return true; 00147 } 00148 00149 public boolean remove(Object o) { 00150 return getVector().del(o); 00151 } 00152 00153 00154 // Bulk Modification Operations 00155 00156 public void clear() { 00157 getVector().clear(); 00158 } 00159 00160 // Comparison and hashing 00161 00162 public boolean equals(Object o) { 00163 return getVector().equals(o); 00164 } 00165 00166 public int hashCode() { 00167 return getVector().hashCode(); 00168 } 00169 00170 // Positional Access Operations 00171 00172 public Object get(int index) { 00173 return getVector().get(index); 00174 } 00175 00176 00177 public Object set(int index, Object element) { 00178 Object prev = get(index); 00179 getVector().set(index, element); 00180 return prev; 00181 } 00182 00183 00184 public Object remove(int index) { 00185 Object prev = get(index); 00186 getVector().del(index); 00187 return prev; 00188 } 00189 00190 // Search Operations 00191 00192 public int indexOf(Object o) { 00193 return getVector().find(o); 00194 } 00195 00196 // List Iterators 00197 00198 // -- waba.ui.Vector does not support any of this 00199 00200 // View 00201 00202 // -- waba.ui.Vector does not support any of this 00203 00204 //----------------------------------------------------------------------- 00205 // Inner Classes 00206 00207 protected static class IteratorImpl implements Iterator { 00208 public IteratorImpl(VectorListAdapter v) { 00209 theList = v; 00210 curIndex = 0; 00211 } 00212 00213 public boolean hasNext() { 00214 return curIndex < theList.size(); 00215 } 00216 00217 public Object next() { 00218 Object cur = theList.get(curIndex); 00219 curIndex++; 00220 return cur; 00221 } 00222 00223 public void remove() { 00224 theList.remove(curIndex); 00225 } 00226 00227 private int curIndex; 00228 private VectorListAdapter theList; 00229 } 00230 }