FileDocCategorySizeDatePackage
IndexList.javaAPI DocExample4290Fri Jan 30 19:26:06 GMT 2004com.darwinsys.util

IndexList

public class IndexList extends Object implements List

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.

Fields Summary
private int
hwm
high water mark
private Object[]
data
Implementation: data
public static final int
DEFAULT_START_SIZE
The initial size of an instance's internal store
Constructors Summary
public IndexList()


	  
		this(DEFAULT_START_SIZE);
	
public IndexList(int startSize)

		data = new Object[startSize];
		hwm = 0;
	
Methods Summary
public voidadd(int i, java.lang.Object o)
Unlike the general contract of List, this will replace, not insert before, the object at the given index.

		ensureCapacity(i);
		data[i] = o;
	
public booleanadd(java.lang.Object o)
Add the given object to the end of the list

		ensureCapacity(hwm);
		data[hwm++] = o;
		return true;
	
public booleanaddAll(java.util.Collection c)

		Iterator it = c.iterator();
		while (it.hasNext()) {
			add(it.next());
		}
		return true;
	
public booleanaddAll(int i, java.util.Collection c)

		throw new IllegalStateException(
			"addAll method not implemented in IndexList");
	
public voidclear()

		data = new Object[DEFAULT_START_SIZE];
		hwm = 0;
	
public booleancontains(java.lang.Object o)

		return indexOf(o) >= 0;
	
public booleancontainsAll(java.util.Collection c)

		Iterator it = c.iterator();
		while (it.hasNext()) {
			if (indexOf(it.next()) == -1) {
				return false;
			}
		}
		return true;
	
public voidensureCapacity(int i)

		if (i > data.length) {
			Object newData = new Object[i + 10];
			System.arraycopy(data, 0, newData, 0, hwm);
		}
	
public java.lang.Objectget(int i)

		return data[i];
	
public inthashCode()

		return data.hashCode();
	
public intindexOf(java.lang.Object o)
Find the location where this object is referenced, or null

		for (int i=0; i<hwm; i++) {
			if (o == data[i]) {
				return i;
			}
		}
		return -1;
	
public booleanisEmpty()

		return hwm > 0;
	
public java.util.Iteratoriterator()

		Object[] newData = new Object[hwm];
		System.arraycopy(data, 0, newData, 0, hwm);
		return new ArrayIterator(newData);
	
public intlastIndexOf(java.lang.Object o)

		for (int i=hwm-1; i>=0; i--) {
			if (o == data[i]) {
				return i;
			}
		}
		return -1;
	
public java.util.ListIteratorlistIterator()

		throw new IllegalStateException(
			"listIterator method not implemented in IndexList");
	
public java.util.ListIteratorlistIterator(int i)

		throw new IllegalStateException(
			"listIterator method not implemented in IndexList");
	
public booleanremove(java.lang.Object o)
remove() simply sets the given value to null.

		int i;
		if ((i = indexOf(o)) == -1)
			return false;
		remove(i);
		return true;
	
public java.lang.Objectremove(int i)
remove() simply sets the given value to null.

		Object old = data[i];
		data[i] = null;
		return old;
	
public booleanremoveAll(java.util.Collection c)
removeAll removes all the elements in a Collection from this List
NOT IMPLEMENTED.

		throw new IllegalStateException(
			"removeAll method not implemented in IndexList");
	
public booleanretainAll(java.util.Collection c)

		throw new IllegalStateException(
			"removeAll method not implemented in IndexList");
	
public java.lang.Objectset(int i, java.lang.Object o)

		ensureCapacity(i);
		Object old = data[i];
		data[i] = o;
		return old;
	
public intsize()

		return hwm;
	
public java.util.ListsubList(int from, int to)

		throw new IllegalStateException(
			"subList method not implemented in IndexList");
	
public java.lang.Object[]toArray()
Return the collection as an Array of Object

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

		if (newData.length != hwm) {
			throw new IllegalArgumentException("newData length != current");
		}
		System.arraycopy(data, 0, newData, 0, hwm);
		return newData;