|
Search this API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object y.base.YList
public class YList
An implementation of a doubly linked list that provides direct access to the
cells that store the elements.
The cells are represented by class ListCell
.
firstCell()
/lastCell()
together with
succCell(ListCell)
/predCell(ListCell)
, respectively) or by
means of a cursor (cursor()
).
Furthermore, this list offers its own sort()
method.
Note that this class also provides all relevant methods to use the list like
a stack data type.
This implementation permits null
as values.
It implements the List
interface but does not support the
subList(int, int)
method. The implementation of this method will throw an
UnsupportedOperationException
if invoked.
The iterator()
s returned by instances of this class are fail fast, however
the cursor()
implementation is not.
Nested Class Summary | |
---|---|
class |
YList.ListCursorImpl
Cursor implementation for class YList. |
Constructor Summary | |
---|---|
YList()
Creates an empty doubly linked list. |
|
YList(java.util.Collection c)
Creates a list that is initialized with the elements provided by the given Collection object. |
|
YList(java.util.Iterator it)
Creates a list that is initialized with the elements provided by the given Iterator object. |
|
YList(java.lang.Object[] a)
Creates a list that is initialized with the elements provided by the given array of objects. |
|
YList(YCursor c)
Creates a list that is initialized with the elements provided by the given YCursor object. |
|
YList(YCursor c,
DataProvider predicate)
Creates a list that is initialized with those elements from the given YCursor object for which the given data provider returns true upon
calling its getBool method. |
Method Summary | |
---|---|
void |
add(int index,
java.lang.Object element)
|
boolean |
add(java.lang.Object o)
Same as addLast(Object) . |
boolean |
addAll(java.util.Collection collection)
Appends all elements provided by the given collection to this list. |
boolean |
addAll(int index,
java.util.Collection c)
Adds all elements provided by the given collection to this list at the specified position. |
void |
addAll(YCursor c)
Appends all elements provided by the given cursor to this list. |
ListCell |
addFirst(java.lang.Object o)
Inserts the given object at the head of this list. |
void |
addFirstCell(ListCell cell)
Adds a formerly removed ListCell object at the head of this list. |
ListCell |
addLast(java.lang.Object o)
Inserts the given object at the tail of this list. |
void |
addLastCell(ListCell cell)
Adds a formerly removed ListCell object at the tail of this list. |
void |
clear()
Removes all elements from this list. |
boolean |
contains(java.lang.Object o)
Whether or not this list contains the given element. |
boolean |
containsAll(java.util.Collection collection)
Whether or not this list contains all the elements in the given collection. |
YCursor |
cursor()
Returns a cursor for this list. |
ListCell |
cyclicPred(ListCell c)
Returns the cyclic predecessor cell of the given list cell. |
ListCell |
cyclicSucc(ListCell c)
Returns the cyclic successor cell of the given list cell. |
java.lang.Object |
elementAt(int i)
Returns the i-th element of this list. |
boolean |
equals(java.lang.Object other)
|
ListCell |
findCell(java.lang.Object o)
Returns the ListCell where object o is stored. |
java.lang.Object |
first()
Returns the first element of this list. |
ListCell |
firstCell()
Returns the first cell of this list. |
java.lang.Object |
get(int index)
|
ListCell |
getCell(int index)
Gets the cell at the given index. |
java.lang.Object |
getInfo(ListCell c)
Returns the element stored in the given list cell. |
int |
hashCode()
|
int |
indexOf(java.lang.Object obj)
Returns the zero-based index of the given element in this list. |
ListCell |
insertAfter(java.lang.Object o,
ListCell refCell)
Inserts the given object into this list with respect to a given reference list cell. |
ListCell |
insertBefore(java.lang.Object o,
ListCell refCell)
Inserts the given object into this list with respect to a given reference list cell. |
void |
insertCellAfter(ListCell cellToInsert,
ListCell refCell)
Inserts a formerly removed ListCell object into this list with respect to a
given reference list cell. |
void |
insertCellBefore(ListCell cellToInsert,
ListCell refCell)
Inserts a formerly removed ListCell object into this list with respect to a
given reference list cell. |
boolean |
isEmpty()
Checks whether this list contains elements. |
java.util.Iterator |
iterator()
Returns an iterator for that list. |
java.lang.Object |
last()
Returns the last element of this list. |
ListCell |
lastCell()
Returns the last cell of this list. |
int |
lastIndexOf(java.lang.Object o)
|
java.util.ListIterator |
listIterator()
|
java.util.ListIterator |
listIterator(int index)
|
java.lang.Object |
peek()
Equivalent to first() . |
java.lang.Object |
pop()
Removes the first element from this list and returns it. |
java.lang.Object |
popLast()
Removes the last element from this list and returns it. |
ListCell |
predCell(ListCell c)
Returns the predecessor cell of the given list cell. |
ListCell |
push(java.lang.Object o)
Equivalent to addFirst(Object) . |
java.lang.Object |
remove(int index)
|
boolean |
remove(java.lang.Object o)
Removes the given object from this list. |
boolean |
removeAll(java.util.Collection collection)
Removes the given collection of objects from this list. |
java.lang.Object |
removeAt(YCursor c)
Removes the element pointed to by the given YCursor object. |
java.lang.Object |
removeCell(ListCell c)
Removes the given list cell, and hence the element stored in it, from this list. |
boolean |
retainAll(java.util.Collection collection)
Retains only those elements in this list which are contained in the given collection. |
void |
reverse()
Reverses the sequence of elements in this list. |
java.lang.Object |
set(int index,
java.lang.Object element)
|
void |
setInfo(ListCell c,
java.lang.Object value)
Updates the element stored in the given list cell with the given object. |
int |
size()
Returns the number of elements in this list. |
void |
sort()
Sorts the elements in this list into ascending order, according to their natural ordering. |
void |
sort(java.util.Comparator comp)
Sorts the elements in this list according to the given comparator. |
void |
splice(YList list)
Transfers the contents of the given list to the end of this list. |
java.util.List |
subList(int fromIndex,
int toIndex)
|
ListCell |
succCell(ListCell c)
Returns the successor cell of the given list cell. |
java.lang.Object[] |
toArray()
Returns an array representation of this list. |
java.lang.Object[] |
toArray(java.lang.Object[] a)
Returns an array containing all list elements in the correct order. |
java.lang.String |
toString()
Returns a string representation of this List. |
java.util.Vector |
toVector()
Returns a Vector representation of this list. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public YList()
public YList(java.util.Collection c)
public YList(java.util.Iterator it)
public YList(YCursor c)
public YList(YCursor c, DataProvider predicate)
true
upon
calling its getBool
method.
c
- A cursor providing objects that should be added to this list.predicate
- A data provider that acts as a inclusion predicate for each object accessible
by the given cursor.public YList(java.lang.Object[] a)
Method Detail |
---|
public ListCell addFirst(java.lang.Object o)
public ListCell addLast(java.lang.Object o)
public void addLastCell(ListCell cell)
ListCell
object at the tail of this list.
Attention: If the ListCell
object is still part of any list, then that
list will be corrupted afterwards.
cell
- A list cell which is not part of any list.public void addFirstCell(ListCell cell)
ListCell
object at the head of this list.
Attention: If the ListCell
object is still part of any list, then that
list will be corrupted afterwards.
cell
- A list cell which is not part of any list.public boolean add(java.lang.Object o)
addLast(Object)
.
add
in interface java.util.Collection
add
in interface java.util.List
true
public boolean addAll(java.util.Collection collection)
addAll
in interface java.util.Collection
addAll
in interface java.util.List
public void addAll(YCursor c)
aList.append(aList.cursor())
results
in an infinite recursion.
public ListCell insertBefore(java.lang.Object o, ListCell refCell)
refCell
.
If refCell == null
, the given object is appended to the list.
refCell
must be part of this list.o
- The object to be inserted.refCell
- The list cell used to reference the position.
o
.public void insertCellBefore(ListCell cellToInsert, ListCell refCell)
ListCell
object into this list with respect to a
given reference list cell.
The ListCell
object is inserted right before the reference list cell refCell
.
Attention: If the ListCell
object is still part of any list, then that
list will be corrupted afterwards.
refCell
must be part of this list.cellToInsert
- A list cell which is not part of any list.refCell
- The list cell used to reference the position.public void insertCellAfter(ListCell cellToInsert, ListCell refCell)
ListCell
object into this list with respect to a
given reference list cell.
The ListCell
object is inserted right after the reference list cell refCell
.
Attention: If the ListCell
object is still part of any list, then that
list will be corrupted afterwards.
refCell
must be part of this list.cellToInsert
- A list cell which is not part of any list.refCell
- The list cell used to reference the position.public ListCell insertAfter(java.lang.Object o, ListCell refCell)
refCell
.
If refCell == null
, the given object is inserted at the head of
the list.
refCell
must be part of this list.o
- The object to be inserted.refCell
- The list cell used to reference the position.
o
.public int size()
size
in interface java.util.Collection
size
in interface java.util.List
public boolean isEmpty()
isEmpty
in interface java.util.Collection
isEmpty
in interface java.util.List
public void clear()
clear
in interface java.util.Collection
clear
in interface java.util.List
public java.lang.Object first()
!isEmpty()
.public java.lang.Object pop()
public ListCell push(java.lang.Object o)
addFirst(Object)
.
public java.lang.Object peek()
first()
.
public java.lang.Object last()
!isEmpty()
.public java.lang.Object popLast()
public java.lang.Object elementAt(int i)
i
is a valid index, i.e., i >= 0 && i < size()
.public int indexOf(java.lang.Object obj)
indexOf
in interface java.util.List
public ListCell firstCell()
!isEmpty()
.public ListCell lastCell()
!isEmpty()
.public ListCell succCell(ListCell c)
public ListCell predCell(ListCell c)
public ListCell cyclicSucc(ListCell c)
public ListCell cyclicPred(ListCell c)
public java.lang.Object getInfo(ListCell c)
public void setInfo(ListCell c, java.lang.Object value)
public boolean remove(java.lang.Object o)
o
holds gets removed.
remove
in interface java.util.Collection
remove
in interface java.util.List
public boolean removeAll(java.util.Collection collection)
removeAll
in interface java.util.Collection
removeAll
in interface java.util.List
public boolean retainAll(java.util.Collection collection)
retainAll
in interface java.util.Collection
retainAll
in interface java.util.List
public java.lang.Object removeCell(ListCell c)
public java.lang.Object removeAt(YCursor c)
cursor()
method and the element pointed to by it is contained in this list.public YCursor cursor()
public java.util.Iterator iterator()
iterator
in interface java.lang.Iterable
iterator
in interface java.util.Collection
iterator
in interface java.util.List
public java.util.ListIterator listIterator()
listIterator
in interface java.util.List
public boolean contains(java.lang.Object o)
Object.equals(Object)
method.
contains
in interface java.util.Collection
contains
in interface java.util.List
public boolean containsAll(java.util.Collection collection)
Object.equals(Object)
method.
containsAll
in interface java.util.Collection
containsAll
in interface java.util.List
public ListCell findCell(java.lang.Object o)
ListCell
where object o
is stored.
This operation returns null
, if no such cell exists.
Equality of elements is defined by the Object.equals(Object)
method.
The first element in the list that matches that criteria is returned.
null
if no
such ListCell was foundpublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection
toArray
in interface java.util.List
public java.lang.Object[] toArray(java.lang.Object[] a)
null
.
This is useful in determining the length of the list only if the caller
knows that the list does not contain any null
elements.
toArray
in interface java.util.Collection
toArray
in interface java.util.List
a
- The array into which the elements of the list are to be stored, if it is big
enough.
Otherwise, a new array of the same runtime type is allocated for this purpose.
java.lang.ArrayStoreException
- if the runtime type of the specified array a
is not a supertype of the runtime type of every element in this list.public java.util.Vector toVector()
public void reverse()
public void sort(java.util.Comparator comp)
public void sort()
Comparable
interface.
Furthermore, all elements in this list must be mutually comparable (that is,
e1.compareTo(e2)
must not throw a ClassCastException for any elements
e1
and e2
in this list).
NOTE: The elements will be assigned to different list cells by this method.
public void splice(YList list)
public boolean addAll(int index, java.util.Collection c)
addAll
in interface java.util.List
index
- index at which the first element of the specified collection is placedc
- the collection that contains the elements to be added
true
if this list was changed, false
otherwise
java.lang.IndexOutOfBoundsException
- if the index is out of range, that is, negative or larger than the size of this listpublic final ListCell getCell(int index)
index
- the zero-based index of the cell in this list.
java.lang.IndexOutOfBoundsException
- if the index is negative or greater or equal than the size()
public int lastIndexOf(java.lang.Object o)
lastIndexOf
in interface java.util.List
public java.lang.Object set(int index, java.lang.Object element)
set
in interface java.util.List
public java.lang.Object remove(int index)
remove
in interface java.util.List
public java.util.ListIterator listIterator(int index)
listIterator
in interface java.util.List
public java.lang.Object get(int index)
get
in interface java.util.List
public void add(int index, java.lang.Object element)
add
in interface java.util.List
public java.util.List subList(int fromIndex, int toIndex)
subList
in interface java.util.List
public boolean equals(java.lang.Object other)
equals
in interface java.util.Collection
equals
in interface java.util.List
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface java.util.Collection
hashCode
in interface java.util.List
hashCode
in class java.lang.Object
|
© Copyright 2000-2022, yWorks GmbH. All rights reserved. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |