Back to index

plt-scheme  4.2.1
Public Member Functions | Protected Member Functions | Protected Attributes | Package Functions | Static Package Functions
java.util.AbstractSequentialList Class Reference

Abstract superclass to make it easier to implement the List interface when backed by a sequential-access store, such as a linked list. More...

Inheritance diagram for java.util.AbstractSequentialList:
Inheritance graph
[legend]
Collaboration diagram for java.util.AbstractSequentialList:
Collaboration graph
[legend]

List of all members.

Public Member Functions

abstract ListIterator listIterator (int index)
 Returns a ListIterator over the list, starting from position index.
void add (int index, Object o)
 Insert an element into the list at a given position (optional operation).
boolean addAll (int index, Collection c)
 Insert the contents of a collection into the list at a given position (optional operation).
Object get (int index)
 Get the element at a given index in this list.
Iterator iterator ()
 Obtain an Iterator over this list, whose sequence is the list order.
Object remove (int index)
 Remove the element at a given position in this list (optional operation).
Object set (int index, Object o)
 Replace an element of this list with another object (optional operation).
boolean contains (Object o)
 Test whether this collection contains a given object.
boolean containsAll (Collection c)
 Tests whether this collection contains all the elements in a given collection.
boolean isEmpty ()
 Test whether this collection is empty.
boolean remove (Object o)
 Remove a single instance of an object from this collection (optional operation).
boolean removeAll (Collection c)
 Remove from this collection all its elements that are contained in a given collection (optional operation).
boolean retainAll (Collection c)
 Remove from this collection all its elements that are not contained in a given collection (optional operation).
abstract int size ()
 Return the number of elements in this collection.
Object[] toArray ()
 Return an array containing the elements of this collection.
Object[] toArray (Object[] o)
 Copy the collection into a given array if it will fit, or into a dynamically created array of the same run-time type as the given array if not.
boolean add (Object o)
 Add an element to the end of the list (optional operation).
boolean addAll (Collection c)
 Add all the elements of a given collection to this collection (optional operation).
void clear ()
 Clear the list, such that a subsequent call to isEmpty() would return true (optional operation).
boolean equals (Object o)
 Test whether this list is equal to another object.
int hashCode ()
 Obtains a hash code for this list.
int indexOf (Object o)
 Obtain the first index at which a given object is to be found in this list.
int lastIndexOf (Object o)
 Obtain the last index at which a given object is to be found in this list.
ListIterator listIterator ()
 Obtain a ListIterator over this list, starting at the beginning.
ListIterator listIterator (final int index)
List subList (int fromIndex, int toIndex)
 Obtain a List view of a subsection of this list, from fromIndex (inclusive) to toIndex (exclusive).
String toString ()
 Creates a String representation of the Collection.

Protected Member Functions

 AbstractSequentialList ()
 The main constructor, for use by subclasses.
void removeRange (int fromIndex, int toIndex)
 Remove a subsection of the list.

Protected Attributes

int modCount
 A count of the number of structural modifications that have been made to the list (that is, insertions and removals).

Package Functions

boolean removeAllInternal (Collection c)
 Remove from this collection all its elements that are contained in a given collection (optional operation).
boolean retainAllInternal (Collection c)
 Remove from this collection all its elements that are not contained in a given collection (optional operation).

Static Package Functions

static final boolean equals (Object o1, Object o2)
 Compare two objects according to Collection semantics.
static final int hashCode (Object o)
 Hash an object according to Collection semantics.

Detailed Description

Abstract superclass to make it easier to implement the List interface when backed by a sequential-access store, such as a linked list.

For random access data, use AbstractList. This class implements the random access methods (get, set, add, and remove) atop the list iterator, opposite of AbstractList's approach of implementing the iterator atop random access.

To implement a list, you need an implementation for size() and listIterator. With just hasNext, next, hasPrevious, previous, nextIndex, and previousIndex, you have an unmodifiable list. For a modifiable one, add set, and for a variable-size list, add add and remove.

The programmer should provide a no-argument constructor, and one that accepts another Collection, as recommended by the Collection interface. Unfortunately, there is no way to enforce this in Java.

Author:
Original author unknown
Bryce McKinlay
Eric Blake ebb9@.nosp@m.emai.nosp@m.l.byu.nosp@m..edu
See also:
Collection
List
AbstractList
AbstractCollection
ListIterator
LinkedList
Since:
1.2 updated to 1.4

Definition at line 74 of file AbstractSequentialList.java.


Constructor & Destructor Documentation

The main constructor, for use by subclasses.

Definition at line 79 of file AbstractSequentialList.java.

  {
  }

Member Function Documentation

void java.util.AbstractSequentialList.add ( int  index,
Object  o 
) [inline]

Insert an element into the list at a given position (optional operation).

This shifts all existing elements from that position to the end one index to the right. This version of add has no return, since it is assumed to always succeed if there is no exception. This iteration uses listIterator(index).add(o).

Parameters:
indexthe location to insert the item
othe object to insert
Exceptions:
UnsupportedOperationExceptionif this list does not support the add operation
IndexOutOfBoundsExceptionif index < 0 || index > size()
ClassCastExceptionif o cannot be added to this list due to its type
IllegalArgumentExceptionif o cannot be added to this list for some other reason

Reimplemented from java.util.AbstractList.

Definition at line 110 of file AbstractSequentialList.java.

  {
    listIterator(index).add(o);
  }

Here is the call graph for this function:

boolean java.util.AbstractList.add ( Object  o) [inline, inherited]

Add an element to the end of the list (optional operation).

If the list imposes restraints on what can be inserted, such as no null elements, this should be documented. This implementation calls add(size(), o);, and will fail if that version does.

Parameters:
othe object to add
Returns:
true, as defined by Collection for a modified list
Exceptions:
UnsupportedOperationExceptionif this list does not support the add operation
ClassCastExceptionif o cannot be added to this list due to its type
IllegalArgumentExceptionif o cannot be added to this list for some other reason
See also:
add(int, Object)

Reimplemented from java.util.AbstractCollection.

Definition at line 158 of file AbstractList.java.

  {
    add(size(), o);
    return true;
  }

Here is the call graph for this function:

Insert the contents of a collection into the list at a given position (optional operation).

Shift all elements at that position to the right by the number of elements inserted. This operation is undefined if this list is modified during the operation (for example, if you try to insert a list into itself).

This implementation grabs listIterator(index), then proceeds to use add for each element returned by c's iterator. Sun's online specs are wrong, claiming that this also calls next(): listIterator.add() correctly skips the added element.

Parameters:
indexthe location to insert the collection
cthe collection to insert
Returns:
true if the list was modified by this action, that is, if c is non-empty
Exceptions:
UnsupportedOperationExceptionif this list does not support the addAll operation
IndexOutOfBoundsExceptionif index < 0 || index > size()
ClassCastExceptionif some element of c cannot be added to this list due to its type
IllegalArgumentExceptionif some element of c cannot be added to this list for some other reason
NullPointerExceptionif the specified collection is null
See also:
add(int, Object)

Reimplemented from java.util.AbstractList.

Definition at line 142 of file AbstractSequentialList.java.

  {
    Iterator ci = c.iterator();
    int size = c.size();
    ListIterator i = listIterator(index);
    for (int pos = size; pos > 0; pos--)
      i.add(ci.next());
    return size > 0;
  }

Here is the call graph for this function:

boolean java.util.AbstractList.addAll ( Collection  c) [inline, inherited]

Add all the elements of a given collection to this collection (optional operation).

This implementation obtains an Iterator over the given collection and iterates over it, adding each element with the add(Object) method (thus this method will fail with an UnsupportedOperationException if the add method does). The behavior is unspecified if the specified collection is modified during the iteration, including the special case of trying addAll(this) on a non-empty collection.

Parameters:
cthe collection to add the elements of to this collection
Returns:
true if the add operation caused the Collection to change
Exceptions:
UnsupportedOperationExceptionif the add operation is not supported on this collection
NullPointerExceptionif this collection does not support null, or if the specified collection is null
ClassCastExceptionif an object in c is of the wrong type
IllegalArgumentExceptionif some aspect of an object in c prevents it from being added
See also:
add(Object)

Reimplemented from java.util.AbstractCollection.

Reimplemented in java.util.SubList.

Definition at line 196 of file AbstractList.java.

{ return super.addAll(c); }
void java.util.AbstractList.clear ( ) [inline, inherited]

Clear the list, such that a subsequent call to isEmpty() would return true (optional operation).

This implementation calls removeRange(0, size()), so it will fail unless remove or removeRange is overridden.

Exceptions:
UnsupportedOperationExceptionif this list does not support the clear operation
See also:
remove(int)
removeRange(int, int)

Reimplemented from java.util.AbstractCollection.

Definition at line 209 of file AbstractList.java.

  {
    removeRange(0, size());
  }

Here is the call graph for this function:

boolean java.util.AbstractList.contains ( Object  o) [inline, inherited]

Test whether this collection contains a given object.

That is, if the collection has an element e such that (o == null ? e == null : o.equals(e)). This implementation obtains an iterator over the collection and iterates over it, testing each element for equality with the given object. If it is equal, true is returned. Otherwise false is returned when the end of the collection is reached.

Parameters:
othe object to remove from this collection
Returns:
true if this collection contains an object equal to o

Reimplemented from java.util.AbstractCollection.

Reimplemented in java.util.SubList.

Definition at line 90 of file AbstractList.java.

{ return super.contains(o); }

Tests whether this collection contains all the elements in a given collection.

This implementation iterates over the given collection, testing whether each element is contained in this collection. If any one is not, false is returned. Otherwise true is returned.

Parameters:
cthe collection to test against
Returns:
true if this collection contains all the elements in the given collection
Exceptions:
NullPointerExceptionif the given collection is null
See also:
contains(Object)

Reimplemented from java.util.AbstractCollection.

Reimplemented in java.util.SubList.

Definition at line 91 of file AbstractList.java.

{ return super.containsAll(c); }
boolean java.util.AbstractList.equals ( Object  o) [inline, inherited]

Test whether this list is equal to another object.

A List is defined to be equal to an object if and only if that object is also a List, and the two lists have the same sequence. Two lists l1 and l2 are equal if and only if l1.size() == l2.size(), and for every integer n between 0 and l1.size() - 1 inclusive, l1.get(n) == null ? l2.get(n) == null : l1.get(n).equals(l2.get(n)).

This implementation returns true if the object is this, or false if the object is not a List. Otherwise, it iterates over both lists (with iterator()), returning false if two elements compare false or one list is shorter, and true if the iteration completes successfully.

Parameters:
othe object to test for equality with this list
Returns:
true if o is equal to this list
See also:
Object::equals(Object)
hashCode()

Definition at line 233 of file AbstractList.java.

  {
    if (o == this)
      return true;
    if (! (o instanceof List))
      return false;
    int size = size();
    if (size != ((List) o).size())
      return false;

    Iterator itr1 = iterator();
    Iterator itr2 = ((List) o).iterator();

    while (--size >= 0)
      if (! AbstractCollection.equals(itr1.next(), itr2.next()))
        return false;
    return true;
  }

Here is the call graph for this function:

static final boolean java.util.AbstractCollection.equals ( Object  o1,
Object  o2 
) [inline, static, package, inherited]

Compare two objects according to Collection semantics.

Parameters:
o1the first object
o2the second object
Returns:
o1 == null ? o2 == null : o1.equals(o2)

Definition at line 446 of file AbstractCollection.java.

  {
    return o1 == null ? o2 == null : o1.equals(o2);
  }

Here is the caller graph for this function:

Object java.util.AbstractSequentialList.get ( int  index) [inline, virtual]

Get the element at a given index in this list.

This implementation returns listIterator(index).next().

Parameters:
indexthe index of the element to be returned
Returns:
the element at index index in this list
Exceptions:
IndexOutOfBoundsExceptionif index < 0 || index >= size()

Implements java.util.AbstractList.

Definition at line 160 of file AbstractSequentialList.java.

  {
    // This is a legal listIterator position, but an illegal get.
    if (index == size())
      throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
                                          + size());
    return listIterator(index).next();
  }

Here is the call graph for this function:

int java.util.AbstractList.hashCode ( ) [inline, inherited]

Obtains a hash code for this list.

In order to obey the general contract of the hashCode method of class Object, this value is calculated as follows:

hashCode = 1;
Iterator i = list.iterator();
while (i.hasNext())
{
  Object obj = i.next();
  hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
}

This ensures that the general contract of Object.hashCode() is adhered to.

Returns:
the hash code of this list
See also:
Object::hashCode()
equals(Object)

Definition at line 272 of file AbstractList.java.

  {
    int hashCode = 1;
    Iterator itr = iterator();
    int pos = size();
    while (--pos >= 0)
      hashCode = 31 * hashCode + AbstractCollection.hashCode(itr.next());
    return hashCode;
  }

Here is the call graph for this function:

static final int java.util.AbstractCollection.hashCode ( Object  o) [inline, static, package, inherited]

Hash an object according to Collection semantics.

Parameters:
othe object to hash
Returns:
o1 == null ? 0 : o1.hashCode()

Definition at line 459 of file AbstractCollection.java.

  {
    return o == null ? 0 : o.hashCode();
  }

Here is the caller graph for this function:

int java.util.AbstractList.indexOf ( Object  o) [inline, inherited]

Obtain the first index at which a given object is to be found in this list.

This implementation follows a listIterator() until a match is found, or returns -1 if the list end is reached.

Parameters:
othe object to search for
Returns:
the least integer n such that o == null ? get(n) == null : o.equals(get(n)), or -1 if there is no such index

Implements java.util.List.

Definition at line 291 of file AbstractList.java.

  {
    ListIterator itr = listIterator();
    int size = size();
    for (int pos = 0; pos < size; pos++)
      if (AbstractCollection.equals(o, itr.next()))
        return pos;
    return -1;
  }

Here is the call graph for this function:

boolean java.util.AbstractList.isEmpty ( ) [inline, inherited]

Test whether this collection is empty.

This implementation returns size() == 0.

Returns:
true if this collection is empty.
See also:
size()

Reimplemented from java.util.AbstractCollection.

Reimplemented in java.util.SubList.

Definition at line 92 of file AbstractList.java.

{ return super.isEmpty(); }

Obtain an Iterator over this list, whose sequence is the list order.

This implementation returns listIterator().

Returns:
an Iterator over the elements of this list, in order

Reimplemented from java.util.AbstractList.

Definition at line 175 of file AbstractSequentialList.java.

  {
    return (Iterator) ((Object) listIterator());
  }

Here is the call graph for this function:

int java.util.AbstractList.lastIndexOf ( Object  o) [inline, inherited]

Obtain the last index at which a given object is to be found in this list.

This implementation grabs listIterator(size()), then searches backwards for a match or returns -1.

Returns:
the greatest integer n such that o == null ? get(n) == null : o.equals(get(n)), or -1 if there is no such index

Implements java.util.List.

Definition at line 370 of file AbstractList.java.

  {
    int pos = size();
    ListIterator itr = listIterator(pos);
    while (--pos >= 0)
      if (AbstractCollection.equals(o, itr.previous()))
        return pos;
    return -1;
  }

Here is the call graph for this function:

Returns a ListIterator over the list, starting from position index.

Subclasses must provide an implementation of this method.

Parameters:
indexthe starting position of the list
Returns:
the list iterator
Exceptions:
IndexOutOfBoundsExceptionif index < 0 || index > size()

Implements java.util.List.

Obtain a ListIterator over this list, starting at the beginning.

This implementation returns listIterator(0).

Returns:
a ListIterator over the elements of this list, in order, starting at the beginning

Implements java.util.List.

Definition at line 387 of file AbstractList.java.

  {
    return listIterator(0);
  }

Here is the caller graph for this function:

ListIterator java.util.AbstractList.listIterator ( final int  index) [inline, inherited]

Reimplemented in java.util.SubList.

Definition at line 501 of file AbstractList.java.

  {
    if (index < 0 || index > size())
      throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
                                          + size());

    return new lIListIterator(index);
  }

Here is the call graph for this function:

boolean java.util.AbstractList.remove ( Object  o) [inline, inherited]

Remove a single instance of an object from this collection (optional operation).

That is, remove one element e such that (o == null ? e == null : o.equals(e)), if such an element exists. This implementation obtains an iterator over the collection and iterates over it, testing each element for equality with the given object. If it is equal, it is removed by the iterator's remove method (thus this method will fail with an UnsupportedOperationException if the Iterator's remove method does). After the first element has been removed, true is returned; if the end of the collection is reached, false is returned.

Parameters:
othe object to remove from this collection
Returns:
true if the remove operation caused the Collection to change, or equivalently if the collection did contain o.
Exceptions:
UnsupportedOperationExceptionif this collection's Iterator does not support the remove method
See also:
Iterator::remove()

Reimplemented from java.util.AbstractCollection.

Reimplemented in java.util.SubList.

Definition at line 93 of file AbstractList.java.

{ return super.remove(o); }

Here is the caller graph for this function:

Object java.util.AbstractSequentialList.remove ( int  index) [inline]

Remove the element at a given position in this list (optional operation).

Shifts all remaining elements to the left to fill the gap. This implementation uses listIterator(index) and ListIterator.remove().

Parameters:
indexthe position within the list of the object to remove
Returns:
the object that was removed
Exceptions:
UnsupportedOperationExceptionif this list does not support the remove operation
IndexOutOfBoundsExceptionif index < 0 || index >= size()

Reimplemented from java.util.AbstractList.

Definition at line 191 of file AbstractSequentialList.java.

  {
    // This is a legal listIterator position, but an illegal remove.
    if (index == size())
      throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
                                          + size());
    ListIterator i = listIterator(index);
    Object removed = i.next();
    i.remove();
    return removed;
  }

Here is the call graph for this function:

Remove from this collection all its elements that are contained in a given collection (optional operation).

This implementation iterates over this collection, and for each element tests if it is contained in the given collection. If so, it is removed by the Iterator's remove method (thus this method will fail with an UnsupportedOperationException if the Iterator's remove method does).

Parameters:
cthe collection to remove the elements of
Returns:
true if the remove operation caused the Collection to change
Exceptions:
UnsupportedOperationExceptionif this collection's Iterator does not support the remove method
See also:
Iterator::remove()

Reimplemented from java.util.AbstractCollection.

Reimplemented in java.util.SubList.

Definition at line 94 of file AbstractList.java.

{ return super.removeAll(c); }

Remove from this collection all its elements that are contained in a given collection (optional operation).

This implementation iterates over this collection, and for each element tests if it is contained in the given collection. If so, it is removed by the Iterator's remove method (thus this method will fail with an UnsupportedOperationException if the Iterator's remove method does). This method is necessary for ArrayList, which cannot publicly override removeAll but can optimize this call.

Parameters:
cthe collection to remove the elements of
Returns:
true if the remove operation caused the Collection to change
Exceptions:
UnsupportedOperationExceptionif this collection's Iterator does not support the remove method
See also:
Iterator::remove()

Definition at line 293 of file AbstractCollection.java.

  {
    Iterator itr = iterator();
    boolean modified = false;
    int pos = size();
    while (--pos >= 0)
      if (c.contains(itr.next()))
        {
          itr.remove();
          modified = true;
        }
    return modified;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void java.util.AbstractList.removeRange ( int  fromIndex,
int  toIndex 
) [inline, protected, inherited]

Remove a subsection of the list.

This is called by the clear and removeRange methods of the class which implements subList, which are difficult for subclasses to override directly. Therefore, this method should be overridden instead by the more efficient implementation, if one exists. Overriding this can reduce quadratic efforts to constant time in some cases!

This implementation first checks for illegal or out of range arguments. It then obtains a ListIterator over the list using listIterator(fromIndex). It then calls next() and remove() on this iterator repeatedly, toIndex - fromIndex times.

Parameters:
fromIndexthe index, inclusive, to remove from.
toIndexthe index, exclusive, to remove to.

Reimplemented in java.util.SubList.

Definition at line 546 of file AbstractList.java.

  {
    ListIterator itr = listIterator(fromIndex);
    for (int index = fromIndex; index < toIndex; index++)
      {
        itr.next();
        itr.remove();
      }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Remove from this collection all its elements that are not contained in a given collection (optional operation).

This implementation iterates over this collection, and for each element tests if it is contained in the given collection. If not, it is removed by the Iterator's remove method (thus this method will fail with an UnsupportedOperationException if the Iterator's remove method does).

Parameters:
cthe collection to retain the elements of
Returns:
true if the remove operation caused the Collection to change
Exceptions:
UnsupportedOperationExceptionif this collection's Iterator does not support the remove method
See also:
Iterator::remove()

Reimplemented from java.util.AbstractCollection.

Reimplemented in java.util.SubList.

Definition at line 95 of file AbstractList.java.

{ return super.retainAll(c); }

Remove from this collection all its elements that are not contained in a given collection (optional operation).

This implementation iterates over this collection, and for each element tests if it is contained in the given collection. If not, it is removed by the Iterator's remove method (thus this method will fail with an UnsupportedOperationException if the Iterator's remove method does). This method is necessary for ArrayList, which cannot publicly override retainAll but can optimize this call.

Parameters:
cthe collection to retain the elements of
Returns:
true if the remove operation caused the Collection to change
Exceptions:
UnsupportedOperationExceptionif this collection's Iterator does not support the remove method
See also:
Iterator::remove()

Definition at line 342 of file AbstractCollection.java.

  {
    Iterator itr = iterator();
    boolean modified = false;
    int pos = size();
    while (--pos >= 0)
      if (!c.contains(itr.next()))
        {
          itr.remove();
          modified = true;
        }
    return modified;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Object java.util.AbstractSequentialList.set ( int  index,
Object  o 
) [inline]

Replace an element of this list with another object (optional operation).

This implementation uses listIterator(index) and ListIterator.set(o).

Parameters:
indexthe position within this list of the element to be replaced
othe object to replace it with
Returns:
the object that was replaced
Exceptions:
UnsupportedOperationExceptionif this list does not support the set operation
IndexOutOfBoundsExceptionif index < 0 || index >= size()
ClassCastExceptionif o cannot be added to this list due to its type
IllegalArgumentExceptionif o cannot be added to this list for some other reason

Reimplemented from java.util.AbstractList.

Definition at line 218 of file AbstractSequentialList.java.

  {
    // This is a legal listIterator position, but an illegal set.
    if (index == size())
      throw new IndexOutOfBoundsException("Index: " + index + ", Size:"
                                          + size());
    ListIterator i = listIterator(index);
    Object old = i.next();
    i.set(o);
    return old;
  }

Here is the call graph for this function:

abstract int java.util.AbstractList.size ( ) [pure virtual, inherited]

Return the number of elements in this collection.

If there are more than Integer.MAX_VALUE elements, return Integer.MAX_VALUE.

Returns:
the size

Implements java.util.AbstractCollection.

Implemented in java.util.SubList.

Here is the caller graph for this function:

List java.util.AbstractList.subList ( int  fromIndex,
int  toIndex 
) [inline, inherited]

Obtain a List view of a subsection of this list, from fromIndex (inclusive) to toIndex (exclusive).

If the two indices are equal, the sublist is empty. The returned list should be modifiable if and only if this list is modifiable. Changes to the returned list should be reflected in this list. If this list is structurally modified in any way other than through the returned list, the result of any subsequent operations on the returned list is undefined.

This implementation returns a subclass of AbstractList. It stores, in private fields, the offset and size of the sublist, and the expected modCount of the backing list. If the backing list implements RandomAccess, the sublist will also.

The subclass's set(int, Object), get(int), add(int, Object), remove(int), addAll(int, Collection) and removeRange(int, int) methods all delegate to the corresponding methods on the backing abstract list, after bounds-checking the index and adjusting for the offset. The addAll(Collection c) method merely returns addAll(size, c). The listIterator(int) method returns a "wrapper object" over a list iterator on the backing list, which is created with the corresponding method on the backing list. The iterator() method merely returns listIterator(), and the size() method merely returns the subclass's size field.

All methods first check to see if the actual modCount of the backing list is equal to its expected value, and throw a ConcurrentModificationException if it is not.

Parameters:
fromIndexthe index that the returned list should start from (inclusive)
toIndexthe index that the returned list should go to (exclusive)
Returns:
a List backed by a subsection of this list
Exceptions:
IndexOutOfBoundsExceptionif fromIndex < 0 || toIndex > size()
IllegalArgumentExceptionif fromIndex > toIndex
See also:
ConcurrentModificationException
RandomAccess

Implements java.util.List.

Definition at line 620 of file AbstractList.java.

  {
    // This follows the specification of AbstractList, but is inconsistent
    // with the one in List. Don't you love Sun's inconsistencies?
    if (fromIndex > toIndex)
      throw new IllegalArgumentException(fromIndex + " > " + toIndex);
    if (fromIndex < 0 || toIndex > size())
      throw new IndexOutOfBoundsException();

    if (((Object) this) instanceof RandomAccess)
      return new RandomAccessSubList(this, fromIndex, toIndex);
    return new SubList(this, fromIndex, toIndex);
  }

Here is the call graph for this function:

Object [] java.util.AbstractList.toArray ( ) [inline, inherited]

Return an array containing the elements of this collection.

This implementation creates an Object array of size size() and then iterates over the collection, setting each element of the array from the value returned by the iterator. The returned array is safe, and is not backed by the collection.

Returns:
an array containing the elements of this collection

Reimplemented from java.util.AbstractCollection.

Reimplemented in java.util.SubList.

Definition at line 97 of file AbstractList.java.

{ return super.toArray(); }
Object [] java.util.AbstractList.toArray ( Object[]  a) [inline, inherited]

Copy the collection into a given array if it will fit, or into a dynamically created array of the same run-time type as the given array if not.

If there is space remaining in the array, the first element after the end of the collection is set to null (this is only useful if the collection is known to contain no null elements, however). This implementation first tests whether the given array is large enough to hold all the elements of the collection. If not, the reflection API is used to allocate a new array of the same run-time type. Next an iterator is obtained over the collection and the elements are placed in the array as they are returned by the iterator. Finally the first spare element, if any, of the array is set to null, and the created array is returned. The returned array is safe; it is not backed by the collection. Note that null may not mark the last element, if the collection allows null elements.

Parameters:
athe array to copy into, or of the correct run-time type
Returns:
the array that was produced
Exceptions:
NullPointerExceptionif the given array is null
ArrayStoreExceptionif the type of the array precludes holding one of the elements of the Collection

Reimplemented from java.util.AbstractCollection.

Reimplemented in java.util.SubList.

Definition at line 98 of file AbstractList.java.

{ return super.toArray(o); }
String java.util.AbstractCollection.toString ( ) [inline, inherited]

Creates a String representation of the Collection.

The string returned is of the form "[a, b, ...]" where a and b etc are the results of calling toString on the elements of the collection. This implementation obtains an Iterator over the Collection and adds each element to a StringBuffer as it is returned by the iterator.

Returns:
a String representation of the Collection

Definition at line 423 of file AbstractCollection.java.

  { return super.toString();
    //Iterator itr = iterator();
    //StringBuffer r = new StringBuffer("[");
    //for (int pos = size(); pos > 0; pos--)
    //  {
    //    r.append(itr.next());
    //    if (pos > 1)
    //      r.append(", ");
    //  }
    //r.append("]");
    //return r.toString();
  }

Member Data Documentation

int java.util.AbstractList.modCount [protected, inherited]

A count of the number of structural modifications that have been made to the list (that is, insertions and removals).

Structural modifications are ones which change the list size or affect how iterations would behave. This field is available for use by Iterator and ListIterator, in order to throw a ConcurrentModificationException in response to the next operation on the iterator. This fail-fast behavior saves the user from many subtle bugs otherwise possible from concurrent modification during iteration.

To make lists fail-fast, increment this field by just 1 in the add(int, Object) and remove(int) methods. Otherwise, this field may be ignored.

Definition at line 88 of file AbstractList.java.


The documentation for this class was generated from the following file: