| Package | as3.collections.fx |
| Class | public class SortedMapFx |
| Inheritance | SortedMapFx SortedMap |
| Implements | ISortedMapFx |
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().
Note, since replacing might move an item within the collections, two events will be dispatched. First for the removal of the old value and then for the add of the new value.
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.ISortedMapFx;
import as3.collections.fx.SortedMapFx;
import as3.collections.fx.events.FxEvents;
import as3.collections.fx.events.MapEvent;
import as3.collections.iterators.IMapIterator;
import as3.collections.utils.NumericComparator;
import flash.display.Sprite;
public class SortedMapFxExample extends Sprite {
public var map : ISortedMapFx;
public function SortedMapFxExample() {
map = new SortedMapFx(new NumericComparator());
map.addEventListener(FxEvents.COLLECTION_CHANGED, collectionChanged);
// add - [1,2,3,4]
map.addItem("2", 2);
map.addItem("4", 4);
map.addItem("1", 1);
map.addItem("3", 3);
// replace - [1,2,3,44]
map.replaceItem("4", 44);
map.replaceItem("2", 2); // no event since 2 == 2
// remove - [1,44]
map.removeKey("2");
map.removeKey("3");
// 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: 2 key 2
// Added after: undefined key undefined
// Added before: undefined key undefined
// ----------------------
// [2]
// Added item: 4 key 4
// Added after: 2 key 2
// Added before: undefined key undefined
// ----------------------
// [2,4]
// Added item: 1 key 1
// Added after: undefined key undefined
// Added before: 2 key 2
// ----------------------
// [1,2,4]
// Added item: 3 key 3
// Added after: 2 key 2
// Added before: 4 key 4
// ----------------------
// [1,2,3,4]
// Removed 4 key 4
// Removed after: 3 key 3
// Removed before: undefined key undefined
// ----------------------
// [1,2,3]
// Added item: 44 key 4
// Added after: 3 key 3
// Added before: undefined key undefined
// ----------------------
// [1,2,3,44]
// Removed 2 key 2
// Removed after: 1 key 1
// Removed before: 3 key 3
// ----------------------
// [1,3,44]
// Removed 3 key 3
// Removed after: 1 key 1
// Removed before: 44 key 4
// ----------------------
// [1,44]
// Collection emptied
// ----------------------
// []
| Property | Defined by | ||
|---|---|---|---|
| array : Array [read-only]
| SortedMapFx | ||
![]() | numItems : uint
Returns the size of the collection.
| SortedMap | |
| Method | Defined by | ||
|---|---|---|---|
|
SortedMapFx(comparator:IComparator)
Creates a new SortedMapFx.
| SortedMapFx | ||
|
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
| SortedMapFx | ||
![]() |
addItem(key:*, item:*):Boolean
Adds a new item to the map.
| SortedMap | |
|
clear():void
Removes all items from the collection.
| SortedMapFx | ||
|
dispatchEvent(event:Event):Boolean
| SortedMapFx | ||
![]() |
getEqualItemKey(item:*):*
Returns the key of the item, that is equal to the given item against the sort criterion.
| SortedMap | |
![]() |
getFirstItem():*
Returns the lowest item of the sorted map.
| SortedMap | |
![]() |
getItem(key:*):*
Returns the item associated with the given key.
| SortedMap | |
![]() |
getIterator(cursor:uint = 0):IIterator
Returns an iterator over the map items starting at the specified position.
| SortedMap | |
![]() |
getKeyIterator(cursor:uint = 0):IIterator
Returns an iterator over the map keys starting at the specified position.
| SortedMap | |
![]() |
getLastItem():*
Returns the greatest item of the sorted map.
| SortedMap | |
![]() |
getMapIterator(cursor:uint = 0):IMapIterator
Returns a map iterator, which provides additionally access to the key of
the last returned item.
| SortedMap | |
![]() |
hasEqualItem(item:*):Boolean
Returns true, if the map contains at least one item that is equal
to the given item against the sort criterion.
| SortedMap | |
|
hasEventListener(type:String):Boolean
| SortedMapFx | ||
![]() |
hasKey(key:*):Boolean
Tests, if the map contains an item for the given key.
| SortedMap | |
![]() |
keysToArray():Array
Returns an array of all keys.
| SortedMap | |
|
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
| SortedMapFx | ||
![]() |
removeFirstItem():*
Removes the lowest item of the sorted map.
| SortedMap | |
![]() |
removeKey(key:*):*
Removes the key and the item associated with that key.
| SortedMap | |
![]() |
removeLastItem():*
Removes the greatest item of the sorted map.
| SortedMap | |
![]() |
replaceItem(key:*, item:*):Boolean
Replaces the item associated with the given key.
| SortedMap | |
![]() |
toArray():Array
Returns an array of all items in the order of the particular collection.
| SortedMap | |
|
toString():String
Info
| SortedMapFx | ||
|
willTrigger(type:String):Boolean
| SortedMapFx | ||
| Method | Defined by | ||
|---|---|---|---|
|
Template method to notify subclasses after a new node has been added.
| SortedMapFx | ||
|
nodeRemoved():void
Commits the removal of the node, announced in willRemoveNode()
| SortedMapFx | ||
![]() |
updateItem(key:*, item:*):Boolean
Replaces the item associated with the given key.
| SortedMap | |
|
willRemoveNode(node:MapEntry):void
Template method to notify subclasses when a node is about to be removed.
| SortedMapFx | ||
| Event | Summary | Defined by | ||
|---|---|---|---|---|
| Event type for all collection events. | SortedMapFx | |||
| array | property |
array:Array [read-only]
This property can be used as the source for data binding.
Implementation public function get array():Array
| SortedMapFx | () | constructor |
public function SortedMapFx(comparator:IComparator)Creates a new SortedMapFx.
Parameterscomparator:IComparator — The sort criterion.
|
| 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():voidRemoves all items from the collection.
| 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:MapEntry):voidTemplate method to notify subclasses after a new node has been added.
Parametersnode:MapEntry — The last added node.
|
| nodeRemoved | () | method |
protected override function nodeRemoved():voidCommits the removal of the node, announced in willRemoveNode()
| 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:MapEntry):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:MapEntry — 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. |