Packagecom.yworks.yfiles.base
Classpublic class YList
InheritanceYList Inheritance YObject Inheritance Object
Implements Collection, List
Subclasses EdgeList, NodeList

An implementation of a doubly linked list that provides direct access to the cells that store the elements. The cells are represented by class com.yworks.yfiles.base.ListCell .

This class supports fast access and removal operations, specifically, it is possible to remove an element in constant time (i.e. O(1)) given a reference to its list cell.

Class YList supports iteration over the elements either by using the list cells directly (methods firstCell() / lastCell() together with succCell() / predCell(), respectively) or by means of a cursor ( cursor()).

Furthermore, YList offers its own sort2() 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 com.yworks.bridge.util.List interface but does not support the subList() method. The implementation of this method will throw an flash.errors.IllegalOperationError if invoked. The iterator() s returned by instances of this class are fail fast, however the cursor() implementation is not.

See also

com.yworks.yfiles.base.ListCell
firstCell()
lastCell()
succCell()
predCell()
cursor()
sort2()
com.yworks.bridge.util.List
subList()
flash.errors.IllegalOperationError
iterator()


Public Properties
 PropertyDefined By
  empty : Boolean
[read-only] Checks whether this list contains elements.
YList
  length : int
[read-only] Returns the number of elements in this list.
YList
Public Methods
 MethodDefined By
  
YList(init:Boolean = true)
Creates an empty doubly linked list.
YList
  
addAll(collection:Collection):Boolean
Appends all elements provided by the given collection to this list.
YList
  
addAllAt(index:int, c:Collection):Boolean
YList
  
Appends all elements provided by the given cursor to this list.
YList
  
addFirst(o:Object):ListCell
Inserts the given object at the head of this list.
YList
  
Adds a formerly removed ListCell object at the head of this list.
YList
  
addItem(o:Object):Boolean
Same as addLast().
YList
  
addItemAt(index:int, element:Object):void
YList
  
addLast(o:Object):ListCell
Inserts the given object at the tail of this list.
YList
  
Adds a formerly removed ListCell object at the tail of this list.
YList
  
clear():void
Removes all elements from this list.
YList
  
containsAll(collection:Collection):Boolean
Whether or not this list contains all the elements in the given collection.
YList
  
containsItem(o:Object):Boolean
Whether or not this list contains the given element.
YList
  
Returns a cursor for this list.
YList
  
Returns the cyclic predecessor cell of the given list cell.
YList
  
Returns the cyclic successor cell of the given list cell.
YList
  
elementAt(i:int):Object
Returns the i-th element of this list.
YList
  
equals(other:Object):Boolean
[override]
YList
  
findCell(o:Object):ListCell
Returns the com.yworks.yfiles.base.ListCell where object o is stored.
YList
  
first():Object
Returns the first element of this list.
YList
  
Returns the first cell of this list.
YList
  
getCell(index:int):ListCell
Gets the cell at the given index.
YList
  
getClass():Class
[override]
YList
  
getInfo(c:ListCell):Object
Returns the element stored in the given list cell.
YList
  
getItemAt(index:int):Object
YList
  
hashCode():int
[override]
YList
  
indexOf(obj:Object):int
Returns the zero-based index of the given element in this list.
YList
  
insertAfter(o:Object, refCell:ListCell):ListCell
Inserts the given object into this list with respect to a given reference list cell.
YList
  
insertBefore(o:Object, refCell:ListCell):ListCell
Inserts the given object into this list with respect to a given reference list cell.
YList
  
insertCellAfter(cellToInsert:ListCell, refCell:ListCell):void
Inserts a formerly removed ListCell object into this list with respect to a given reference list cell.
YList
  
insertCellBefore(cellToInsert:ListCell, refCell:ListCell):void
Inserts a formerly removed ListCell object into this list with respect to a given reference list cell.
YList
  
Returns an iterator for that list.
YList
  
last():Object
Returns the last element of this list.
YList
  
Returns the last cell of this list.
YList
  
lastIndexOf(o:Object):int
YList
  
YList
  
YList
  
[static] Creates an empty doubly linked list.
YList
  
newYList2(a:Vector.<Object>):YList
[static] Creates a list that is initialized with the elements provided by the given array of objects.
YList
  
[static] Creates a list that is initialized with the elements provided by the given Collection object.
YList
  
[static] Creates a list that is initialized with the elements provided by the given Iterator object.
YList
  
[static] Creates a list that is initialized with the elements provided by the given YCursor object.
YList
  
[static] 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 (com.yworks.yfiles.base.DataProvider.getBool()) method.
YList
  
peek():Object
Equivalent to first().
YList
  
pop():Object
Removes the first element from this list and returns it.
YList
  
popLast():Object
Removes the last element from this list and returns it.
YList
  
Returns the predecessor cell of the given list cell.
YList
  
push(o:Object):ListCell
Equivalent to addFirst().
YList
  
removeAll(collection:Collection):Boolean
Removes the given collection of objects from this list.
YList
  
removeAt(c:YCursor):Object
Removes the element pointed to by the given YCursor object.
YList
  
Removes the given list cell, and hence the element stored in it, from this list.
YList
  
removeItem(o:Object):Boolean
Removes the given object from this list.
YList
  
removeItemAt(index:int):Object
YList
  
retainAll(collection:Collection):Boolean
Retains only those elements in this list which are contained in the given collection.
YList
  
reverse():void
Reverses the sequence of elements in this list.
YList
  
setInfo(c:ListCell, value:Object):void
Updates the element stored in the given list cell with the given object.
YList
  
setItemAt(index:int, element:Object):Object
YList
  
sort(comp:Comparator):void
Sorts the elements in this list according to the given comparator.
YList
  
sort2():void
Sorts the elements in this list into ascending order, according to their natural ordering.
YList
  
splice(list:YList):void
Transfers the contents of the given list to the end of this list.
YList
  
subList(fromIndex:int, toIndex:int):List
YList
  
Returns the successor cell of the given list cell.
YList
  
toArray():Vector.<Object>
Returns an array representation of this list.
YList
  
toArray2(a:Vector.<Object>):Vector.<Object>
Returns an array containing all list elements in the correct order.
YList
  
toString():String
Returns a string representation of this List.
YList
Protected Methods
 MethodDefined By
  
initYList1():void
Initializes this object.
YList
  
initYList2(a:Vector.<Object>):void
Initializes this object.
YList
  
Initializes this object.
YList
  
Initializes this object.
YList
  
Initializes this object.
YList
  
initYList6(c:YCursor, predicate:DataProvider):void
Initializes this object.
YList
Property Detail
emptyproperty
empty:Boolean  [read-only]

Checks whether this list contains elements.


Implementation
    public function get empty():Boolean
lengthproperty 
length:int  [read-only]

Returns the number of elements in this list.


Implementation
    public function get length():int
Constructor Detail
YList()Constructor
public function YList(init:Boolean = true)

Creates an empty doubly linked list.

Parameters
init:Boolean (default = true) — An internally used switch to help handle proper instance initialization in inheritance chains where classes can have multiple constructor-like factory methods. This parameter can safely be ignored/omitted when calling the constructor.
Method Detail
addAll()method
public function addAll(collection:Collection):Boolean

Appends all elements provided by the given collection to this list.

Parameters

collection:Collection

Returns
Boolean — Whether there have been elements appended.
addAllAt()method 
public function addAllAt(index:int, c:Collection):Boolean

Parameters

index:int
 
c:Collection

Returns
Boolean
addAllFromCursor()method 
public function addAllFromCursor(c:YCursor):void

Appends all elements provided by the given cursor to this list. The cursor will be moved from its given position to the end.

Be aware that a statement like aList.append(aList.cursor()) results in an infinite recursion.

Parameters

c:YCursor

addFirst()method 
public function addFirst(o:Object):ListCell

Inserts the given object at the head of this list.

Parameters

o:Object

Returns
ListCell — The newly created ListCell object that stores the given object.
addFirstCell()method 
public function addFirstCell(cell:ListCell):void

Adds a formerly removed 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.

Parameters

cell:ListCell — A list cell which is not part of any list.

addItem()method 
public function addItem(o:Object):Boolean

Same as addLast().

Parameters

o:Object

Returns
Booleantrue

See also

addItemAt()method 
public function addItemAt(index:int, element:Object):void

Parameters

index:int
 
element:Object

addLast()method 
public function addLast(o:Object):ListCell

Inserts the given object at the tail of this list.

Parameters

o:Object

Returns
ListCell — The newly created ListCell object that stores the given object.
addLastCell()method 
public function addLastCell(cell:ListCell):void

Adds a formerly removed 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.

Parameters

cell:ListCell — A list cell which is not part of any list.

clear()method 
public function clear():void

Removes all elements from this list.

containsAll()method 
public function containsAll(collection:Collection):Boolean

Whether or not this list contains all the elements in the given collection. Equality of elements is defined by the com.yworks.bridge.util.FlexUtils.equals() method.

Parameters

collection:Collection

Returns
Boolean

See also

containsItem()method 
public function containsItem(o:Object):Boolean

Whether or not this list contains the given element. Equality of elements is defined by the com.yworks.bridge.util.FlexUtils.equals() method.

Parameters

o:Object

Returns
Boolean

See also

cursor()method 
public function cursor():YCursor

Returns a cursor for this list. All cursor operations are supported. This cursor implementation is not fail-fast and continues to work if this list is modified during the traversal as long as the current ListCell the cursor points at is this in this list or has been removed from this list but has not been added to another instance since then.

Returns
YCursor
cyclicPred()method 
public function cyclicPred(c:ListCell):ListCell

Returns the cyclic predecessor cell of the given list cell.

The last cell is returned as the cyclic predecessor of the first list cell.

Parameters

c:ListCell

Returns
ListCell
cyclicSucc()method 
public function cyclicSucc(c:ListCell):ListCell

Returns the cyclic successor cell of the given list cell.

The first cell is returned as the cyclic successor of the last list cell.

Parameters

c:ListCell

Returns
ListCell
elementAt()method 
public function elementAt(i:int):Object

Returns the i-th element of this list.

Precondition i is a valid index, i.e., i >= 0 && i < size().

Parameters

i:int

Returns
Object
equals()method 
override public function equals(other:Object):Boolean

Parameters

other:Object

Returns
Boolean
findCell()method 
public function findCell(o:Object):ListCell

Returns the com.yworks.yfiles.base.ListCell where object o is stored. This operation returns null, if no such cell exists. Equality of elements is defined by the com.yworks.bridge.util.FlexUtils.equals() method. The first element in the list that matches that criteria is returned.

Parameters

o:Object

Returns
ListCell — the ListCell that contains the element or null if no such ListCell was found

See also

first()method 
public function first():Object

Returns the first element of this list.

Precondition !isEmpty().

Returns
Object
firstCell()method 
public function firstCell():ListCell

Returns the first cell of this list.

Precondition !isEmpty().

Returns
ListCell
getCell()method 
public function getCell(index:int):ListCell

Gets the cell at the given index.

Parameters

index:int — the zero-based index of the cell in this list.

Returns
ListCell — The cell.

Throws
RangeError — if the index is negative or greater or equal than the length

See also

getClass()method 
override public function getClass():Class

Returns
Class
getInfo()method 
public function getInfo(c:ListCell):Object

Returns the element stored in the given list cell.

Parameters

c:ListCell

Returns
Object
getItemAt()method 
public function getItemAt(index:int):Object

Parameters

index:int

Returns
Object
hashCode()method 
override public function hashCode():int

Returns
int
indexOf()method 
public function indexOf(obj:Object):int

Returns the zero-based index of the given element in this list. If the given element is not in the list, -1 is returned.

Parameters

obj:Object

Returns
int
initYList1()method 
protected final function initYList1():void

Initializes this object. See the documentation of the corresponding factory method newYList1() for details.

See also

initYList2()method 
protected final function initYList2(a:Vector.<Object>):void

Initializes this object. See the documentation of the corresponding factory method newYList2() for details.

Parameters

a:Vector.<Object>

See also

initYList3()method 
protected final function initYList3(c:Collection):void

Initializes this object. See the documentation of the corresponding factory method newYList3() for details.

Parameters

c:Collection

See also

initYList4()method 
protected final function initYList4(it:Iterator):void

Initializes this object. See the documentation of the corresponding factory method newYList4() for details.

Parameters

it:Iterator

See also

initYList5()method 
protected final function initYList5(c:YCursor):void

Initializes this object. See the documentation of the corresponding factory method newYList5() for details.

Parameters

c:YCursor

See also

initYList6()method 
protected final function initYList6(c:YCursor, predicate:DataProvider):void

Initializes this object. See the documentation of the corresponding factory method newYList6() for details.

Parameters

c:YCursor
 
predicate:DataProvider

See also

insertAfter()method 
public function insertAfter(o:Object, refCell:ListCell):ListCell

Inserts the given object into this list with respect to a given reference list cell. The (newly created) list cell that stores the object is inserted right after the reference list cell refCell.

If refCell == null, the given object is inserted at the head of the list.

Precondition refCell must be part of this list.

Parameters

o:Object — The object to be inserted.
 
refCell:ListCell — The list cell used to reference the position.

Returns
ListCell — The newly created ListCell object that stores object o.
insertBefore()method 
public function insertBefore(o:Object, refCell:ListCell):ListCell

Inserts the given object into this list with respect to a given reference list cell. The (newly created) list cell that stores the object is inserted right before the reference list cell refCell.

If refCell == null, the given object is appended to the list.

Precondition refCell must be part of this list.

Parameters

o:Object — The object to be inserted.
 
refCell:ListCell — The list cell used to reference the position.

Returns
ListCell — The newly created ListCell object that stores object o.
insertCellAfter()method 
public function insertCellAfter(cellToInsert:ListCell, refCell:ListCell):void

Inserts a formerly removed 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.

Precondition refCell must be part of this list.

Parameters

cellToInsert:ListCell — A list cell which is not part of any list.
 
refCell:ListCell — The list cell used to reference the position.

insertCellBefore()method 
public function insertCellBefore(cellToInsert:ListCell, refCell:ListCell):void

Inserts a formerly removed 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.

Precondition refCell must be part of this list.

Parameters

cellToInsert:ListCell — A list cell which is not part of any list.
 
refCell:ListCell — The list cell used to reference the position.

iterator()method 
public function iterator():Iterator

Returns an iterator for that list. The remove operation is supported on the iterator. This iterator instance is fail-fast.

Returns
Iterator
last()method 
public function last():Object

Returns the last element of this list.

Precondition !isEmpty().

Returns
Object
lastCell()method 
public function lastCell():ListCell

Returns the last cell of this list.

Precondition !isEmpty().

Returns
ListCell
lastIndexOf()method 
public function lastIndexOf(o:Object):int

Parameters

o:Object

Returns
int
listIterator()method 
public function listIterator():ListIterator

Returns
ListIterator
listIterator2()method 
public function listIterator2(index:int):ListIterator

Parameters

index:int

Returns
ListIterator
newYList1()method 
public static function newYList1():YList

Creates an empty doubly linked list.

Returns
YList
newYList2()method 
public static function newYList2(a:Vector.<Object>):YList

Creates a list that is initialized with the elements provided by the given array of objects.

Parameters

a:Vector.<Object>

Returns
YList
newYList3()method 
public static function newYList3(c:Collection):YList

Creates a list that is initialized with the elements provided by the given Collection object.

Parameters

c:Collection

Returns
YList
newYList4()method 
public static function newYList4(it:Iterator):YList

Creates a list that is initialized with the elements provided by the given Iterator object.

Parameters

it:Iterator

Returns
YList
newYList5()method 
public static function newYList5(c:YCursor):YList

Creates a list that is initialized with the elements provided by the given YCursor object.

Parameters

c:YCursor

Returns
YList
newYList6()method 
public static function newYList6(c:YCursor, predicate:DataProvider):YList

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 (com.yworks.yfiles.base.DataProvider.getBool()) method.

Parameters

c:YCursor — A cursor providing objects that should be added to this list.
 
predicate:DataProvider — A data provider that acts as a inclusion predicate for each object accessible by the given cursor.

Returns
YList

See also

peek()method 
public function peek():Object

Equivalent to first().

Returns
Object

See also

pop()method 
public function pop():Object

Removes the first element from this list and returns it.

Returns
Object
popLast()method 
public function popLast():Object

Removes the last element from this list and returns it.

Returns
Object
predCell()method 
public function predCell(c:ListCell):ListCell

Returns the predecessor cell of the given list cell.

Parameters

c:ListCell

Returns
ListCell
push()method 
public function push(o:Object):ListCell

Equivalent to addFirst().

Parameters

o:Object

Returns
ListCell

See also

removeAll()method 
public function removeAll(collection:Collection):Boolean

Removes the given collection of objects from this list.

Parameters

collection:Collection

Returns
Boolean — Whether there have been elements removed.
removeAt()method 
public function removeAt(c:YCursor):Object

Removes the element pointed to by the given YCursor object.

Precondition The given cursor has been created by a call to this list's cursor() method and the element pointed to by it is contained in this list.

Parameters

c:YCursor

Returns
Object — The removed element.

See also

removeCell()method 
public function removeCell(c:ListCell):Object

Removes the given list cell, and hence the element stored in it, from this list.

Complexity O(1)

Precondition The given list cell is part of this list.

Parameters

c:ListCell

Returns
Object — The element that is stored in the removed cell.
removeItem()method 
public function removeItem(o:Object):Boolean

Removes the given object from this list. Only the first element for which equality to o holds gets removed.

Complexity O(size())

Parameters

o:Object

Returns
Boolean
removeItemAt()method 
public function removeItemAt(index:int):Object

Parameters

index:int

Returns
Object
retainAll()method 
public function retainAll(collection:Collection):Boolean

Retains only those elements in this list which are contained in the given collection.

Complexity This operation has running time O(max(m, n)), were m and n are the sizes of this list and the given collection, respectively.

Parameters

collection:Collection

Returns
Boolean — Whether there have been elements removed.
reverse()method 
public function reverse():void

Reverses the sequence of elements in this list.

setInfo()method 
public function setInfo(c:ListCell, value:Object):void

Updates the element stored in the given list cell with the given object.

Parameters

c:ListCell
 
value:Object

setItemAt()method 
public function setItemAt(index:int, element:Object):Object

Parameters

index:int
 
element:Object

Returns
Object
sort()method 
public function sort(comp:Comparator):void

Sorts the elements in this list according to the given comparator.

NOTE: The elements will be assigned to different list cells by this method.

Complexity O(size() * log(size()))

Parameters

comp:Comparator

sort2()method 
public function sort2():void

Sorts the elements in this list into ascending order, according to their natural ordering. All elements must implement the com.yworks.bridge.util.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.

Complexity O(size() * log(size()))

See also

splice()method 
public function splice(list:YList):void

Transfers the contents of the given list to the end of this list. The given list will be empty after this operation.

Note that this operation transfers the list cells of the given list to this list. No new list cells are created by this operation.

Complexity O(1)

Parameters

list:YList

subList()method 
public function subList(fromIndex:int, toIndex:int):List

Parameters

fromIndex:int
 
toIndex:int

Returns
List
succCell()method 
public function succCell(c:ListCell):ListCell

Returns the successor cell of the given list cell.

Parameters

c:ListCell

Returns
ListCell
toArray()method 
public function toArray():Vector.<Object>

Returns an array representation of this list.

Returns
Vector.<Object>
toArray2()method 
public function toArray2(a:Vector.<Object>):Vector.<Object>

Returns an array containing all list elements in the correct order. The runtime type of the returned array is that of the given array.

If the list does not fit in the specified array, a new array is allocated with the runtime type of the specified array and the size of this list.

If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to 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.

Parameters

a:Vector.<Object> — 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.

Returns
Vector.<Object> — An array containing the elements of the list.

Throws
Error — if the runtime type of the specified array a is not a supertype of the runtime type of every element in this list.
toString()method 
public function toString():String

Returns a string representation of this List.

Returns
String