gov.sandia.cognition.collection
Class RangeExcludedArrayList<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by gov.sandia.cognition.collection.RangeExcludedArrayList<E>
Type Parameters:
E - The type stored in the collection.
All Implemented Interfaces:
MultiCollection<E>, Iterable<E>, Collection<E>, List<E>, RandomAccess

@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 AbstractList<E>
implements RandomAccess, MultiCollection<E>

The 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.

Since:
2.0
Author:
Justin Basilico

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
RangeExcludedArrayList(ArrayList<E> list, int fromIndex, int toIndex)
          Creates a new instance of RangeExcludedArrayList.
 
Method Summary
 E get(int index)
           
 int getSubCollectionsCount()
          Gets the number of sub-collections in the multi-collection.
 int size()
           
 List<? extends Collection<E>> subCollections()
          Returns the sub-collections of the multi-collection.
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

RangeExcludedArrayList

public RangeExcludedArrayList(ArrayList<E> list,
                              int fromIndex,
                              int toIndex)
Creates a new instance of RangeExcludedArrayList.

Parameters:
list - The list to apply the range exclusion to.
fromIndex - The lower index to exclude (inclusive).
toIndex - The upper index to exclude (inclusive).
Method Detail

get

public E get(int index)
Specified by:
get in interface List<E>
Specified by:
get in class AbstractList<E>

size

public int size()
Specified by:
size in interface Collection<E>
Specified by:
size in interface List<E>
Specified by:
size in class AbstractCollection<E>

subCollections

public List<? extends Collection<E>> subCollections()
Description copied from interface: MultiCollection
Returns the sub-collections of the multi-collection.

Specified by:
subCollections in interface MultiCollection<E>
Returns:
The sub-collection of the multi-collection.

getSubCollectionsCount

public int getSubCollectionsCount()
Description copied from interface: MultiCollection
Gets the number of sub-collections in the multi-collection.

Specified by:
getSubCollectionsCount in interface MultiCollection<E>
Returns:
Number of sub-collections in the multi-collection.