package li.earth.urchin.twic.collections; import java.util.Collection; import java.util.List; import java.util.ListIterator; import java.util.AbstractList; public class GeneralBigSubList extends AbstractBigList { private final BigList list; private final long base; private long size; public GeneralBigSubList(BigList list, long fromIndex, long toIndex) { if (fromIndex < 0L) throw new IndexOutOfBoundsException("illegal fromIndex value: " + fromIndex); if ((toIndex > list.bigSize()) || (fromIndex > toIndex)) throw new IndexOutOfBoundsException("illegal toIndex value: " + toIndex); this.list = list; base = fromIndex; size = toIndex - fromIndex; } public long bigSize() { return size; } public E get(long index) { boundsCheck(index, false); return list.get(index + base); } public E set(long index, E obj) { boundsCheck(index, false); return list.set((index + base), obj); } public void add(long index, E obj) { boundsCheck(index, true); list.set((index + base), obj); ++size; } public E remove(long index) { boundsCheck(index, false); E obj = list.remove((index + base)); --size; return obj; } private void boundsCheck(long index, boolean halfOpen) { if ((index < 0L) || (halfOpen ? (index > size) : (index >= size))) throw new IndexOutOfBoundsException(Long.toString(index)); } }