1 47 48 package org.ozoneDB.collections; 49 50 import java.util.Collection ; 51 import java.util.Iterator ; 52 import java.util.ListIterator ; 53 54 87 public abstract class BaseSequentialListImpl extends AbstractOzoneList { 88 89 92 protected BaseSequentialListImpl() { 93 } 94 95 103 public abstract ListIterator listIterator(int index); 104 105 122 public void add(int index, Object o) { 123 listIterator(index).add(o); 124 } 125 126 153 public boolean addAll(int index, Collection c) { 154 Iterator ci = c.iterator(); 155 int size = c.size(); 156 ListIterator i = listIterator(index); 157 for (int pos = size; pos > 0; pos--) 158 i.add(ci.next()); 159 return size > 0; 160 } 161 162 170 public Object get(int index) { 171 if (index == size()) 173 throw new IndexOutOfBoundsException ("Index: " + index + ", Size:" 174 + size()); 175 return listIterator(index).next(); 176 } 177 178 184 public Iterator iterator() { 185 return listIterator(); 186 } 187 188 199 public Object remove(int index) { 200 if (index == size()) 202 throw new IndexOutOfBoundsException ("Index: " + index + ", Size:" 203 + size()); 204 ListIterator i = listIterator(index); 205 Object removed = i.next(); 206 i.remove(); 207 return removed; 208 } 209 210 225 public Object set(int index, Object o) { 226 if (index == size()) 228 throw new IndexOutOfBoundsException ("Index: " + index + ", Size:" 229 + size()); 230 ListIterator i = listIterator(index); 231 Object old = i.next(); 232 i.set(o); 233 return old; 234 } 235 } 236 | Popular Tags |