| Package | as3.collections.fx |
| Class | public class LinkedMapFx |
| Inheritance | LinkedMapFx LinkedMap AbstractLinkedList |
| Implements | ILinkedMapFx |
Dispatchs events after all changes to the map.
The dispatched event is of type FxEvents.COLLECTION_CHANGED and can be distinguished by its event.kind property.
All events of kind ITEM_xxx contain a reference to the affected item as well as an IMapIterator returning either the affected item (add, replace) or its successor (remove) with the first call to getNext().
The iterator returned by the particular collection event does not recognize, whether the collection has been changed during an event dispatcher sequence and may become invalid. So do not change the collection in event handlers and their scope.
Usage example
package fx.basicusage {
import as3.collections.fx.ILinkedMapFx;
import as3.collections.fx.LinkedMapFx;
import as3.collections.fx.events.FxEvents;
import as3.collections.fx.events.MapEvent;
import as3.collections.iterators.IMapIterator;
import flash.display.Sprite;
public class LinkedMapFxExample extends Sprite {
public var map : ILinkedMapFx;
public function LinkedMapFxExample() {
map = new LinkedMapFx();
map.addEventListener(FxEvents.COLLECTION_CHANGED, collectionChanged);
// add - [3,1,2,4]
map.addItem("1", 1);
map.addItem("2", 2);
map.addItemAtEnd("4", 4);
map.addItemAtStart("3", 3);
// replace - [3,1,2,44]
map.replaceItem("4", 44);
map.replaceItem("2", 2); // no event since 2 == 2
// remove - [1]
map.removeKey("2");
map.removeFirstItem();
map.removeLastItem();
// empty map - []
map.clear();
}
private function collectionChanged(event : MapEvent) : void {
var key : = event.key;
var item : = event.item;
var iterator : IMapIterator = event.getIterator();
switch (event.kind) {
case FxEvents.ITEM_ADDED:
trace ("Added item: " + item + " key " + key);
trace ("Added after: " + iterator.getCurrent() + " key " + iterator.getKey());
iterator.getNext(); // returns added item
trace ("Added before: " + iterator.getNext() + " key " + iterator.getKey());
break;
case FxEvents.ITEM_REMOVED:
trace ("Removed " + item + " key " + key);
trace ("Removed after: " + iterator.getCurrent() + " key " + iterator.getKey());
trace ("Removed before: " + iterator.getNext() + " key " + iterator.getKey());
break;
case FxEvents.ITEM_REPLACED:
trace ("Replaced item: " + item + " key " + key);
trace ("Replaced after: " + iterator.getCurrent() + " key " + iterator.getKey());
iterator.getNext(); // returns replaced item
trace ("Replaced before: " + iterator.getNext() + " key " + iterator.getKey());
break;
case FxEvents.COLLECTION_EMPTIED:
trace ("Collection emptied");
break;
}
trace ("----------------------");
trace ("[" + map.toArray() + "]\n");
}
}
}
// Added item: 1 key 1
// Added after: undefined key undefined
// Added before: undefined key undefined
// ----------------------
// [1]
// Added item: 2 key 2
// Added after: 1 key 1
// Added before: undefined key undefined
// ----------------------
// [1,2]
// Added item: 4 key 4
// Added after: 2 key 2
// Added before: undefined key undefined
// ----------------------
// [1,2,4]
// Added item: 3 key 3
// Added after: undefined key undefined
// Added before: 1 key 1
// ----------------------
// [3,1,2,4]
// Replaced item: 44 key 4
// Replaced after: 2 key 2
// Replaced before: undefined key undefined
// ----------------------
// [3,1,2,44]
// Removed 2 key 2
// Removed after: 1 key 1
// Removed before: 44 key 4
// ----------------------
// [3,1,44]
// Removed 3 key 3
// Removed after: undefined key undefined
// Removed before: 1 key 1
// ----------------------
// [1,44]
// Removed 44 key 4
// Removed after: 1 key 1
// Removed before: undefined key undefined
// ----------------------
// [1]
// Collection emptied
// ----------------------
// []
| Property | Defined by | ||
|---|---|---|---|
| array : Array [read-only]
| LinkedMapFx | ||
![]() | numItems : uint
Returns the size of the linked list.
| AbstractLinkedList | |
| Method | Defined by | ||
|---|---|---|---|
|
Creates a new LinkedMapFx.
| LinkedMapFx | ||
|
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
| LinkedMapFx | ||
![]() |
addItem(key:*, item:*):Boolean
Adds a new item to the map.
| LinkedMap | |
![]() |
addItemAtEnd(key:*, item:*):Boolean
Adds an item at the end of the linked map.
| LinkedMap | |
![]() |
addItemAtStart(key:*, item:*):Boolean
Adds an item in front of the linked map.
| LinkedMap | |
|
clear():void
Clears the list by removing the references to the first
and last item.
| LinkedMapFx | ||
|
dispatchEvent(event:Event):Boolean
| LinkedMapFx | ||
![]() |
getFirstItem():*
Returns the first item of the linked list.
| AbstractLinkedList | |
![]() |
getItem(key:*):*
Returns the item associated with the given key.
| LinkedMap | |
![]() |
getIterator(cursor:uint = 0):IIterator
Returns an iterator starting at the specified position.
| LinkedMap | |
![]() |
getKeyIterator(cursor:uint = 0):IIterator
Returns an iterator over the map keys starting at the specified position.
| LinkedMap | |
![]() |
getLastItem():*
Returns the last item of the linked list.
| AbstractLinkedList | |
![]() |
getMapIterator(cursor:uint = 0):IMapIterator
Returns a map iterator, which provides additionally access to the key of
the last returned item.
| LinkedMap | |
![]() |
getPointer(key:*):IMapPointer
Returns a map pointer for the linked map.
| LinkedMap | |
|
hasEventListener(type:String):Boolean
| LinkedMapFx | ||
![]() |
hasKey(key:*):Boolean
Tests, if the map contains an item for the given key.
| LinkedMap | |
![]() |
keysToArray():Array
Returns an array of all keys.
| LinkedMap | |
|
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
| LinkedMapFx | ||
![]() |
removeFirstItem():*
Removes the first item of the linked map.
| LinkedMap | |
![]() |
removeKey(key:*):*
Removes the key and the item associated with that key.
| LinkedMap | |
![]() |
removeLastItem():*
Removes the last item of the linked map.
| LinkedMap | |
![]() |
replaceItem(key:*, item:*):Boolean
Replaces the item associated with the given key.
| LinkedMap | |
![]() |
reverse():void
Reverses the linked list order.
| AbstractLinkedList | |
![]() |
sort(comparator:IComparator):void
Sorts the linked list by a given criterion.
| AbstractLinkedList | |
![]() |
toArray():Array
Returns an array of all items in the present order.
| AbstractLinkedList | |
|
toString():String
Info
| LinkedMapFx | ||
|
willTrigger(type:String):Boolean
| LinkedMapFx | ||
| Method | Defined by | ||
|---|---|---|---|
![]() |
addFirstNode(node:LinkedNode):void
Adds the first node to an empty list.
| AbstractLinkedList | |
![]() |
Inserts a new node after an existing one.
| AbstractLinkedList | |
![]() |
addNodeAtEnd(node:LinkedNode):void
Inserts a new node at the end of the sequence.
| AbstractLinkedList | |
![]() |
addNodeAtStart(node:LinkedNode):void
Inserts a new node at the start of the sequence.
| AbstractLinkedList | |
![]() |
Inserts a new node before an existing one.
| AbstractLinkedList | |
![]() |
deregisterNode(node:LinkedNode):void
Deregisters a node from the internal map.
| LinkedMap | |
![]() |
getNodeAt(index:uint):LinkedNode
Returns the node at a specific position.
| AbstractLinkedList | |
![]() |
insertionSort(comparator:IComparator):void
Insertion sort algorithm.
| AbstractLinkedList | |
![]() |
mergeSort(comparator:IComparator):void
Merge sort algorithm.
| AbstractLinkedList | |
|
nodeAdded(node:LinkedNode):void
Template method to notify subclasses after a new node has been added.
| LinkedMapFx | ||
|
nodeRemoved():void
Commits the removal of the node, announced in willRemoveNode()
| LinkedMapFx | ||
|
nodeReplaced(node:LinkedNode):void
Template method to notify subclasses after a node has been replaced.
| LinkedMapFx | ||
![]() |
registerNode(node:LinkedNode):void
Registers a node in the internal map.
| LinkedMap | |
![]() |
unlinkFirstNode():void
Unlinks the first node of the sequence.
| AbstractLinkedList | |
![]() |
unlinkLastNode():void
Unlinks the last node of the sequence.
| AbstractLinkedList | |
![]() |
unlinkNode(node:LinkedNode):void
Unlinks a node and connects predecessor with successor.
| AbstractLinkedList | |
|
willRemoveNode(node:LinkedNode):void
Template method to notify subclasses when a node is about to be removed.
| LinkedMapFx | ||
| Event | Summary | Defined by | ||
|---|---|---|---|---|
| Event type for all collection events. | LinkedMapFx | |||
| array | property |
array:Array [read-only]
This property can be used as the source for data binding.
Implementation public function get array():Array
| LinkedMapFx | () | constructor |
public function LinkedMapFx()Creates a new LinkedMapFx.
| addEventListener | () | method |
public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):voidParameters
type:String |
|
listener:Function |
|
useCapture:Boolean (default = false) |
|
priority:int (default = 0) |
|
useWeakReference:Boolean (default = false) |
| clear | () | method |
public override function clear():voidClears the list by removing the references to the first and last item. Cleans also the pointer reference.
May be extended in sub classes.
| dispatchEvent | () | method |
public function dispatchEvent(event:Event):BooleanParameters
event:Event |
Boolean |
| hasEventListener | () | method |
public function hasEventListener(type:String):BooleanParameters
type:String |
Boolean |
| nodeAdded | () | method |
protected override function nodeAdded(node:LinkedNode):voidTemplate method to notify subclasses after a new node has been added.
Parametersnode:LinkedNode — The last added node.
|
| nodeRemoved | () | method |
protected override function nodeRemoved():voidCommits the removal of the node, announced in willRemoveNode()
| nodeReplaced | () | method |
protected override function nodeReplaced(node:LinkedNode):voidTemplate method to notify subclasses after a node has been replaced.
Parametersnode:LinkedNode — The replaced node.
|
| removeEventListener | () | method |
public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):voidParameters
type:String |
|
listener:Function |
|
useCapture:Boolean (default = false) |
| toString | () | method |
public override function toString():StringInfo
ReturnsString |
| willRemoveNode | () | method |
protected override function willRemoveNode(node:LinkedNode):voidTemplate method to notify subclasses when a node is about to be removed.
We need this node to create a reference to its predecessor. After the node has been removed, this reference would be null. The subclass is in charge to cache the node's predecessor till the node is finally removed.
Parametersnode:LinkedNode — The node that will be removed soon.
|
| willTrigger | () | method |
public function willTrigger(type:String):BooleanParameters
type:String |
Boolean |
| collectionChanged | event |
as3.collections.fx.events.MapEvent
as3.collections.fx.events.FxEvents.COLLECTION_CHANGED
Event type for all collection events.
A collection event always is of the type COLLECTION_CHANGED. The specific change to the collection can be distinguished by examine the event's kind property. The kind of an event can be one of the following:
| Property | Value |
|---|---|
| kind | The kind of change to the collection. |
| item | The affected item. Not set for DATA_SOURCE_REPLACED and COLLECTION_EMPTIED. |
| getIterator | Returns an iterator pointing to the affected item (add, replace) or to its
successor (remove). Not set for DATA_SOURCE_REPLACED and COLLECTION_EMPTIED. |
| key | The key of the affected item. Only set for map events. Not set for DATA_SOURCE_REPLACED and COLLECTION_EMPTIED. |