Class CursorableLinkedList
- java.lang.Object
-
- org.apache.commons.collections.CursorableLinkedList
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable,java.util.Collection,java.util.List
public class CursorableLinkedList extends java.lang.Object implements java.util.List, java.io.SerializableDeprecated.Use new version in list subpackage, which has been rewritten and now returns the cursor from the listIterator method. Will be removed in v4.0A doubly-linked list implementation of theListinterface, supporting aListIteratorthat allows concurrent modifications to the underlying list.Implements all of the optional
Listoperations, the stack/queue/dequeue operations available inLinkedListand supports aListIteratorthat allows concurrent modifications to the underlying list (seecursor()).Note that this implementation is not synchronized.
- Since:
- Commons Collections 1.0
- See Also:
LinkedList, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classCursorableLinkedList.CursorDeprecated.
-
Constructor Summary
Constructors Constructor Description CursorableLinkedList()Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(int index, java.lang.Object element)Deprecated.Inserts the specified element at the specified position in this list.booleanadd(java.lang.Object o)Deprecated.Appends the specified element to the end of this list.booleanaddAll(int index, java.util.Collection c)Deprecated.Inserts all of the elements in the specified collection into this list at the specified position.booleanaddAll(java.util.Collection c)Deprecated.Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specifiedCollection'sIterator.booleanaddFirst(java.lang.Object o)Deprecated.Inserts the specified element at the beginning of this list.booleanaddLast(java.lang.Object o)Deprecated.Inserts the specified element at the end of this list.voidclear()Deprecated.Removes all of the elements from this list.booleancontains(java.lang.Object o)Deprecated.Returns true if this list contains the specified element.booleancontainsAll(java.util.Collection c)Deprecated.Returns true if this list contains all of the elements of the specified collection.CursorableLinkedList.Cursorcursor()Deprecated.Returns aListIteratorfor iterating through the elements of this list.CursorableLinkedList.Cursorcursor(int i)Deprecated.Returns aListIteratorfor iterating through the elements of this list, initialized such thatListIterator.next()will return the element at the specified index (if any) andListIterator.previous()will return the element immediately preceding it (if any).booleanequals(java.lang.Object o)Deprecated.Compares the specified object with this list for equality.java.lang.Objectget(int index)Deprecated.Returns the element at the specified position in this list.java.lang.ObjectgetFirst()Deprecated.Returns the element at the beginning of this list.java.lang.ObjectgetLast()Deprecated.Returns the element at the end of this list.inthashCode()Deprecated.Returns the hash code value for this list.intindexOf(java.lang.Object o)Deprecated.Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.booleanisEmpty()Deprecated.Returns true if this list contains no elements.java.util.Iteratoriterator()Deprecated.Returns a fail-fast iterator.intlastIndexOf(java.lang.Object o)Deprecated.Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.java.util.ListIteratorlistIterator()Deprecated.Returns a fail-fast ListIterator.java.util.ListIteratorlistIterator(int index)Deprecated.Returns a fail-fast ListIterator.java.lang.Objectremove(int index)Deprecated.Removes the element at the specified position in this list (optional operation).booleanremove(java.lang.Object o)Deprecated.Removes the first occurrence in this list of the specified element.booleanremoveAll(java.util.Collection c)Deprecated.Removes from this list all the elements that are contained in the specified collection.java.lang.ObjectremoveFirst()Deprecated.Removes the first element of this list, if any.java.lang.ObjectremoveLast()Deprecated.Removes the last element of this list, if any.booleanretainAll(java.util.Collection c)Deprecated.Retains only the elements in this list that are contained in the specified collection.java.lang.Objectset(int index, java.lang.Object element)Deprecated.Replaces the element at the specified position in this list with the specified element.intsize()Deprecated.Returns the number of elements in this list.java.util.ListsubList(int i, int j)Deprecated.Returns a fail-fast sublist.java.lang.Object[]toArray()Deprecated.Returns an array containing all of the elements in this list in proper sequence.java.lang.Object[]toArray(java.lang.Object[] a)Deprecated.Returns an array containing all of the elements in this list in proper sequence; the runtime type of the returned array is that of the specified array.java.lang.StringtoString()Deprecated.Returns aStringrepresentation of this list, suitable for debugging.
-
-
-
Method Detail
-
add
public boolean add(java.lang.Object o)
Deprecated.Appends the specified element to the end of this list.- Specified by:
addin interfacejava.util.Collection- Specified by:
addin interfacejava.util.List- Parameters:
o- element to be appended to this list.- Returns:
- true
-
add
public void add(int index, java.lang.Object element)Deprecated.Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).- Specified by:
addin interfacejava.util.List- Parameters:
index- index at which the specified element is to be inserted.element- element to be inserted.- Throws:
java.lang.ClassCastException- if the class of the specified element prevents it from being added to this list.java.lang.IllegalArgumentException- if some aspect of the specified element prevents it from being added to this list.java.lang.IndexOutOfBoundsException- if the index is out of range (index < 0 || index > size()).
-
addAll
public boolean addAll(java.util.Collection c)
Deprecated.Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specifiedCollection'sIterator. The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)- Specified by:
addAllin interfacejava.util.Collection- Specified by:
addAllin interfacejava.util.List- Parameters:
c- collection whose elements are to be added to this list.- Returns:
- true if this list changed as a result of the call.
- Throws:
java.lang.ClassCastException- if the class of an element in the specified collection prevents it from being added to this list.java.lang.IllegalArgumentException- if some aspect of an element in the specified collection prevents it from being added to this list.
-
addAll
public boolean addAll(int index, java.util.Collection c)Deprecated.Inserts all of the elements in the specified collection into this list at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they are returned by the specifiedCollection'sIterator. The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)- Specified by:
addAllin interfacejava.util.List- Parameters:
index- index at which to insert first element from the specified collection.c- elements to be inserted into this list.- Returns:
- true if this list changed as a result of the call.
- Throws:
java.lang.ClassCastException- if the class of one of elements of the specified collection prevents it from being added to this list.java.lang.IllegalArgumentException- if some aspect of one of elements of the specified collection prevents it from being added to this list.java.lang.IndexOutOfBoundsException- if the index is out of range (index < 0 || index > size()).
-
addFirst
public boolean addFirst(java.lang.Object o)
Deprecated.Inserts the specified element at the beginning of this list. (Equivalent toadd(0,o)).- Parameters:
o- element to be prepended to this list.- Returns:
- true
-
addLast
public boolean addLast(java.lang.Object o)
Deprecated.Inserts the specified element at the end of this list. (Equivalent toadd(java.lang.Object)).- Parameters:
o- element to be appended to this list.- Returns:
- true
-
clear
public void clear()
Deprecated.Removes all of the elements from this list. This list will be empty after this call returns (unless it throws an exception).- Specified by:
clearin interfacejava.util.Collection- Specified by:
clearin interfacejava.util.List
-
contains
public boolean contains(java.lang.Object o)
Deprecated.Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).- Specified by:
containsin interfacejava.util.Collection- Specified by:
containsin interfacejava.util.List- Parameters:
o- element whose presence in this list is to be tested.- Returns:
- true if this list contains the specified element.
-
containsAll
public boolean containsAll(java.util.Collection c)
Deprecated.Returns true if this list contains all of the elements of the specified collection.- Specified by:
containsAllin interfacejava.util.Collection- Specified by:
containsAllin interfacejava.util.List- Parameters:
c- collection to be checked for containment in this list.- Returns:
- true if this list contains all of the elements of the specified collection.
-
cursor
public CursorableLinkedList.Cursor cursor()
Deprecated.Returns aListIteratorfor iterating through the elements of this list. Unlikeiterator(), a cursor is not bothered by concurrent modifications to the underlying list.Specifically, when elements are added to the list before or after the cursor, the cursor simply picks them up automatically. When the "current" (i.e., last returned by
ListIterator.next()orListIterator.previous()) element of the list is removed, the cursor automatically adjusts to the change (invalidating the last returned value--i.e., it cannot be removed).Note that the returned
ListIteratordoes not support theListIterator.nextIndex()andListIterator.previousIndex()methods (they throwUnsupportedOperationExceptionwhen invoked.Historical Note: In previous versions of this class, the object returned from this method was required to be explicitly closed. This is no longer necessary.
- See Also:
cursor(int),listIterator(),CursorableLinkedList.Cursor
-
cursor
public CursorableLinkedList.Cursor cursor(int i)
Deprecated.Returns aListIteratorfor iterating through the elements of this list, initialized such thatListIterator.next()will return the element at the specified index (if any) andListIterator.previous()will return the element immediately preceding it (if any). Unlikeiterator(), a cursor is not bothered by concurrent modifications to the underlying list.- Throws:
java.lang.IndexOutOfBoundsException- if the index is out of range (index < 0 || index > size()).- See Also:
cursor(),listIterator(int),CursorableLinkedList.Cursor
-
equals
public boolean equals(java.lang.Object o)
Deprecated.Compares the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two lists are defined to be equal if they contain the same elements in the same order. This definition ensures that the equals method works properly across different implementations of the List interface.- Specified by:
equalsin interfacejava.util.Collection- Specified by:
equalsin interfacejava.util.List- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the object to be compared for equality with this list.- Returns:
- true if the specified object is equal to this list.
-
get
public java.lang.Object get(int index)
Deprecated.Returns the element at the specified position in this list.- Specified by:
getin interfacejava.util.List- Parameters:
index- index of element to return.- Returns:
- the element at the specified position in this list.
- Throws:
java.lang.IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size()).
-
getFirst
public java.lang.Object getFirst()
Deprecated.Returns the element at the beginning of this list.
-
getLast
public java.lang.Object getLast()
Deprecated.Returns the element at the end of this list.
-
hashCode
public int hashCode()
Deprecated.Returns the hash code value for this list. The hash code of a list is defined to be the result of the following calculation:hashCode = 1; Iterator i = list.iterator(); while (i.hasNext()) { Object obj = i.next(); hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode()); }This ensures that list1.equals(list2) implies that list1.hashCode()==list2.hashCode() for any two lists, list1 and list2, as required by the general contract of Object.hashCode.- Specified by:
hashCodein interfacejava.util.Collection- Specified by:
hashCodein interfacejava.util.List- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code value for this list.
- See Also:
Object.hashCode(),Object.equals(Object),equals(Object)
-
indexOf
public int indexOf(java.lang.Object o)
Deprecated.Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.- Specified by:
indexOfin interfacejava.util.List- Parameters:
o- element to search for.- Returns:
- the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.
-
isEmpty
public boolean isEmpty()
Deprecated.Returns true if this list contains no elements.- Specified by:
isEmptyin interfacejava.util.Collection- Specified by:
isEmptyin interfacejava.util.List- Returns:
- true if this list contains no elements.
-
iterator
public java.util.Iterator iterator()
Deprecated.Returns a fail-fast iterator.- Specified by:
iteratorin interfacejava.util.Collection- Specified by:
iteratorin interfacejava.lang.Iterable- Specified by:
iteratorin interfacejava.util.List- See Also:
List.iterator()
-
lastIndexOf
public int lastIndexOf(java.lang.Object o)
Deprecated.Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element. More formally, returns the highest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.- Specified by:
lastIndexOfin interfacejava.util.List- Parameters:
o- element to search for.- Returns:
- the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.
-
listIterator
public java.util.ListIterator listIterator()
Deprecated.Returns a fail-fast ListIterator.- Specified by:
listIteratorin interfacejava.util.List- See Also:
List.listIterator()
-
listIterator
public java.util.ListIterator listIterator(int index)
Deprecated.Returns a fail-fast ListIterator.- Specified by:
listIteratorin interfacejava.util.List- See Also:
List.listIterator(int)
-
remove
public boolean remove(java.lang.Object o)
Deprecated.Removes the first occurrence in this list of the specified element. If this list does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))) (if such an element exists).- Specified by:
removein interfacejava.util.Collection- Specified by:
removein interfacejava.util.List- Parameters:
o- element to be removed from this list, if present.- Returns:
- true if this list contained the specified element.
-
remove
public java.lang.Object remove(int index)
Deprecated.Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.- Specified by:
removein interfacejava.util.List- Parameters:
index- the index of the element to removed.- Returns:
- the element previously at the specified position.
- Throws:
java.lang.IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size()).
-
removeAll
public boolean removeAll(java.util.Collection c)
Deprecated.Removes from this list all the elements that are contained in the specified collection.- Specified by:
removeAllin interfacejava.util.Collection- Specified by:
removeAllin interfacejava.util.List- Parameters:
c- collection that defines which elements will be removed from this list.- Returns:
- true if this list changed as a result of the call.
-
removeFirst
public java.lang.Object removeFirst()
Deprecated.Removes the first element of this list, if any.
-
removeLast
public java.lang.Object removeLast()
Deprecated.Removes the last element of this list, if any.
-
retainAll
public boolean retainAll(java.util.Collection c)
Deprecated.Retains only the elements in this list that are contained in the specified collection. In other words, removes from this list all the elements that are not contained in the specified collection.- Specified by:
retainAllin interfacejava.util.Collection- Specified by:
retainAllin interfacejava.util.List- Parameters:
c- collection that defines which elements this set will retain.- Returns:
- true if this list changed as a result of the call.
-
set
public java.lang.Object set(int index, java.lang.Object element)Deprecated.Replaces the element at the specified position in this list with the specified element.- Specified by:
setin interfacejava.util.List- Parameters:
index- index of element to replace.element- element to be stored at the specified position.- Returns:
- the element previously at the specified position.
- Throws:
java.lang.ClassCastException- if the class of the specified element prevents it from being added to this list.java.lang.IllegalArgumentException- if some aspect of the specified element prevents it from being added to this list.java.lang.IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= size()).
-
size
public int size()
Deprecated.Returns the number of elements in this list.- Specified by:
sizein interfacejava.util.Collection- Specified by:
sizein interfacejava.util.List- Returns:
- the number of elements in this list.
-
toArray
public java.lang.Object[] toArray()
Deprecated.Returns an array containing all of the elements in this list in proper sequence. Obeys the general contract of theCollection.toArray()method.- Specified by:
toArrayin interfacejava.util.Collection- Specified by:
toArrayin interfacejava.util.List- Returns:
- an array containing all of the elements in this list in proper sequence.
-
toArray
public java.lang.Object[] toArray(java.lang.Object[] a)
Deprecated.Returns an array containing all of the elements in this list in proper sequence; the runtime type of the returned array is that of the specified array. Obeys the general contract of theCollection.toArray()method.- Specified by:
toArrayin interfacejava.util.Collection- Specified by:
toArrayin interfacejava.util.List- Parameters:
a- the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.- Returns:
- an array containing the elements of this list.
- Throws:
java.lang.ArrayStoreException- if the runtime type of the specified array is not a supertype of the runtime type of every element in this list.
-
toString
public java.lang.String toString()
Deprecated.Returns aStringrepresentation of this list, suitable for debugging.- Overrides:
toStringin classjava.lang.Object- Returns:
- a
Stringrepresentation of this list, suitable for debugging.
-
subList
public java.util.List subList(int i, int j)Deprecated.Returns a fail-fast sublist.- Specified by:
subListin interfacejava.util.List- See Also:
List.subList(int,int)
-
-