com.darwinsys.util
Class IndexList<T>

java.lang.Object
  extended by com.darwinsys.util.IndexList<T>
All Implemented Interfaces:
java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>

public class IndexList<T>
extends java.lang.Object
implements java.util.List<T>

A general-purpose List, in which objects keep their identity (index), that is, insert() operations do not renumber remaining objects. Hence, more like a real array than an ArrayList is(!).

Not necessarily for production use; written as an example of implementing the List interface.


Field Summary
static int DEFAULT_START_SIZE
          The initial size of an instance's internal store
 
Constructor Summary
IndexList()
           
IndexList(int startSize)
           
 
Method Summary
 void add(int i, T o)
          Unlike the general contract of List, this will replace, not insert before, the object at the given index.
 boolean add(T o)
          Add the given object to the end of the list
 boolean addAll(java.util.Collection c)
           
 boolean addAll(int i, java.util.Collection c)
           
 void clear()
           
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection c)
           
 void ensureCapacity(int i)
           
 T get(int i)
           
 int hashCode()
           
 int indexOf(java.lang.Object o)
          Find the location where this object is referenced, or null
 boolean isEmpty()
           
 java.util.Iterator<T> iterator()
           
 int lastIndexOf(java.lang.Object o)
           
 java.util.ListIterator<T> listIterator()
           
 java.util.ListIterator<T> listIterator(int i)
           
 T remove(int i)
          remove() simply sets the given value to null.
 boolean remove(java.lang.Object o)
          remove() simply sets the given value to null.
 boolean removeAll(java.util.Collection c)
          removeAll removes all the elements in a Collection from this List
NOT IMPLEMENTED.
 boolean retainAll(java.util.Collection c)
           
 T set(int i, T o)
           
 int size()
           
 java.util.List<T> subList(int from, int to)
           
 java.lang.Object[] toArray()
          Return the collection as an Array of Object
 java.lang.Object[] toArray(java.lang.Object[] newData)
          Return the collection as an Array of newData's type
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.List
equals
 

Field Detail

DEFAULT_START_SIZE

public static final int DEFAULT_START_SIZE
The initial size of an instance's internal store

See Also:
Constant Field Values
Constructor Detail

IndexList

public IndexList()

IndexList

public IndexList(int startSize)
Method Detail

ensureCapacity

public void ensureCapacity(int i)

size

public int size()
Specified by:
size in interface java.util.Collection<T>
Specified by:
size in interface java.util.List<T>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection<T>
Specified by:
isEmpty in interface java.util.List<T>

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection<T>
Specified by:
contains in interface java.util.List<T>

add

public boolean add(T o)
Add the given object to the end of the list

Specified by:
add in interface java.util.Collection<T>
Specified by:
add in interface java.util.List<T>

remove

public boolean remove(java.lang.Object o)
remove() simply sets the given value to null.

Specified by:
remove in interface java.util.Collection<T>
Specified by:
remove in interface java.util.List<T>

remove

public T remove(int i)
remove() simply sets the given value to null.

Specified by:
remove in interface java.util.List<T>

removeAll

public boolean removeAll(java.util.Collection c)
removeAll removes all the elements in a Collection from this List
NOT IMPLEMENTED.

Specified by:
removeAll in interface java.util.Collection<T>
Specified by:
removeAll in interface java.util.List<T>

iterator

public java.util.Iterator<T> iterator()
Specified by:
iterator in interface java.lang.Iterable<T>
Specified by:
iterator in interface java.util.Collection<T>
Specified by:
iterator in interface java.util.List<T>

toArray

public java.lang.Object[] toArray()
Return the collection as an Array of Object

Specified by:
toArray in interface java.util.Collection<T>
Specified by:
toArray in interface java.util.List<T>

toArray

public java.lang.Object[] toArray(java.lang.Object[] newData)
Return the collection as an Array of newData's type

Specified by:
toArray in interface java.util.Collection<T>
Specified by:
toArray in interface java.util.List<T>

containsAll

public boolean containsAll(java.util.Collection c)
Specified by:
containsAll in interface java.util.Collection<T>
Specified by:
containsAll in interface java.util.List<T>

addAll

public boolean addAll(java.util.Collection c)
Specified by:
addAll in interface java.util.Collection<T>
Specified by:
addAll in interface java.util.List<T>

addAll

public boolean addAll(int i,
                      java.util.Collection c)
Specified by:
addAll in interface java.util.List<T>

retainAll

public boolean retainAll(java.util.Collection c)
Specified by:
retainAll in interface java.util.Collection<T>
Specified by:
retainAll in interface java.util.List<T>

clear

public void clear()
Specified by:
clear in interface java.util.Collection<T>
Specified by:
clear in interface java.util.List<T>

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Collection<T>
Specified by:
hashCode in interface java.util.List<T>
Overrides:
hashCode in class java.lang.Object

get

public T get(int i)
Specified by:
get in interface java.util.List<T>

set

public T set(int i,
             T o)
Specified by:
set in interface java.util.List<T>

add

public void add(int i,
                T o)
Unlike the general contract of List, this will replace, not insert before, the object at the given index.

Specified by:
add in interface java.util.List<T>

indexOf

public int indexOf(java.lang.Object o)
Find the location where this object is referenced, or null

Specified by:
indexOf in interface java.util.List<T>

lastIndexOf

public int lastIndexOf(java.lang.Object o)
Specified by:
lastIndexOf in interface java.util.List<T>

listIterator

public java.util.ListIterator<T> listIterator()
Specified by:
listIterator in interface java.util.List<T>

listIterator

public java.util.ListIterator<T> listIterator(int i)
Specified by:
listIterator in interface java.util.List<T>

subList

public java.util.List<T> subList(int from,
                                 int to)
Specified by:
subList in interface java.util.List<T>


Copyright © 1996-2004 Ian F. Darwin. See license.html for usage license.