E
- The type stored in the collection.@CodeReview(reviewer="Kevin R. Dixon", date="2008-02-08", changesNeeded=false, comments={"I\'m impressed: iteration (foreach) works on this class. I was ready to flunk this code review, but my unit test passes.","Looks fine."}) public class RangeExcludedArrayList<E> extends java.util.AbstractList<E> implements java.util.RandomAccess, MultiCollection<E>
RangeExcludedArrayList
class implements a light-weight list on
top of an ArrayList
where a certain range of values is excluded from
the list. In some ways, this class is a mirror of the subList method that
exists on the ArrayList
class, which is that it gives a list that
contains everything, except what is in the sub-list. The implementation
creates a read-only collection that remains O(1) for random access.
Note: One difference from the subList method is that the both indices given
to this list are inclusive, because it makes more sense when excluding a
range.Constructor and Description |
---|
RangeExcludedArrayList(java.util.ArrayList<E> list,
int fromIndex,
int toIndex)
Creates a new instance of RangeExcludedArrayList.
|
Modifier and Type | Method and Description |
---|---|
E |
get(int index) |
int |
getSubCollectionsCount()
Gets the number of sub-collections in the multi-collection.
|
int |
size() |
java.util.List<? extends java.util.Collection<E>> |
subCollections()
Returns the sub-collections of the multi-collection.
|
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
public RangeExcludedArrayList(java.util.ArrayList<E> list, int fromIndex, int toIndex)
list
- The list to apply the range exclusion to.fromIndex
- The lower index to exclude (inclusive).toIndex
- The upper index to exclude (inclusive).public E get(int index)
public int size()
public java.util.List<? extends java.util.Collection<E>> subCollections()
MultiCollection
subCollections
in interface MultiCollection<E>
public int getSubCollectionsCount()
MultiCollection
getSubCollectionsCount
in interface MultiCollection<E>