Packageas3.collections.fx
Classpublic class SortedSetFx
InheritanceSortedSetFx Inheritance Treap
ImplementsISortedSetFx

Event dispatching SortedSet.

Dispatchs events after all changes to the set.

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 iterator returning either the affected item (add) 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.ISortedSetFx;
    import as3.collections.fx.SortedSetFx;
    import as3.collections.fx.events.FxEvents;
    import as3.collections.fx.events.SetEvent;
    import as3.collections.iterators.IIterator;
    import as3.collections.utils.NumericComparator;
   
    import flash.display.Sprite;
   
    public class SortedSetFxExample extends Sprite {
     
     public var theSet : ISortedSetFx;
     
     public function SortedSetFxExample() {
      
      theSet = new SortedSetFx(new NumericComparator());
      theSet.addEventListener(FxEvents.COLLECTION_CHANGED, collectionChanged);
      
      // add - [1,2,3,4]
      theSet.addItem(4);
      theSet.addItem(1);
      theSet.addItem(3); 
      theSet.addItem(2);
      
      // remove - [1]
      theSet.removeItem(2);
      theSet.removeFirstItem();
      theSet.removeLastItem();
   
      // empty theSet - []
      theSet.clear();
   
     }
     
     private function collectionChanged(event : SetEvent) : void {
      var item : = event.item;
      var iterator : IIterator = event.getIterator();
      
      switch (event.kind) {
       case FxEvents.ITEM_ADDED:
        trace ("Added item: " + item);
        trace ("Added after: " + iterator.getCurrent());
        iterator.getNext(); // returns added item
        trace ("Added before: " + iterator.getNext());
        break;
       case FxEvents.ITEM_REMOVED:
        trace ("Removed " + item);
        trace ("Removed after: " + iterator.getCurrent());
        trace ("Removed before: " + iterator.getNext());
        break;
       case FxEvents.ITEM_REPLACED:
        trace ("Replaced item: " + item);
        trace ("Replaced after: " + iterator.getCurrent());
        iterator.getNext(); // returns replaced item
        trace ("Replaced before: " + iterator.getNext());
        break;
       case FxEvents.COLLECTION_EMPTIED:
        trace ("Collection emptied");
        break;
      }
      
      trace ("----------------------");
      trace ("[" + theSet.toArray() + "]\n");
     }
    }
   }
   
   // Added item: 4
   // Added after: undefined
   // Added before: undefined
   // ----------------------
   // [4]
   
   // Added item: 1
   // Added after: undefined
   // Added before: 4
   // ----------------------
   // [1,4]
   
   // Added item: 3
   // Added after: 1
   // Added before: 4
   // ----------------------
   // [1,3,4]
   
   // Added item: 2
   // Added after: 1
   // Added before: 3
   // ----------------------
   // [1,2,3,4]
   
   // Removed 2
   // Removed after: 1
   // Removed before: 3
   // ----------------------
   // [1,3,4]
   
   // Removed 1
   // Removed after: undefined
   // Removed before: 3
   // ----------------------
   // [3,4]
   
   // Removed 4
   // Removed after: 3
   // Removed before: undefined
   // ----------------------
   // [3]
   
   // Collection emptied
   // ----------------------
   // []
   



Public Properties
 PropertyDefined by
  array : Array
[read-only]
SortedSetFx
 InheritednumItems : uint
Returns the size of the collection.
Treap
Protected Properties
 PropertyDefined by
 Inherited_comparator : IComparator
The sort criterion.
Treap
 Inherited_numItems : uint = 0
The size of the tree.
Treap
 Inherited_root : TreapNode
The root node.
Treap
Public Methods
 MethodDefined by
  
Creates a new SortedSetFx.
SortedSetFx
  
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
SortedSetFx
 Inherited
addItem(item:*):Boolean
Adds an item to the tree.
Treap
  
clear():void
Removes all items from the collection.
SortedSetFx
  
dispatchEvent(event:Event):Boolean
SortedSetFx
 Inherited
getEqualItem(item:*):*
Returns the item, that is equal to the given item against the sort criterion.
Treap
 Inherited
Returns the lowest item of the sorted set.
Treap
 Inherited
getIterator(cursor:uint = 0):IIterator
Returns an iterator over the tree.
Treap
 Inherited
Returns the greatest item of the sorted set.
Treap
 Inherited
hasEqualItem(item:*):Boolean
Returns true, if the set contains at least one item that is equal to the given item against the sort criterion.
Treap
  
hasEventListener(type:String):Boolean
SortedSetFx
 Inherited
hasItem(item:*):Boolean
Tests, if an item is contained by the set.
Treap
  
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
SortedSetFx
 Inherited
Removes the lowest item of the sorted set.
Treap
 Inherited
removeItem(item:*):Boolean
Removes an item from the set.
Treap
 Inherited
Removes the greatest item of the sorted set.
Treap
 Inherited
toArray():Array
Returns an array of all items in the order of the particular collection.
Treap
  
toString():String
Info
SortedSetFx
  
willTrigger(type:String):Boolean
SortedSetFx
Protected Methods
 MethodDefined by
 Inherited
addItemToTree(item:*):Boolean
Adds an item to the tree.
Treap
  
nodeAdded(node:TreapNode):void
Template method to notify subclasses after a new node has been added.
SortedSetFx
  
nodeRemoved():void
Commits the removal of the node, announced in willRemoveNode()
SortedSetFx
 Inherited
Removes a node from the tree.
Treap
 Inherited
rotate(parent:TreapNode, child:TreapNode):void
Rotates a parent with its child node.
Treap
  
Template method to notify subclasses when a node is about to be removed.
SortedSetFx
Events
 EventSummaryDefined by
   Event type for all collection events.SortedSetFx
Property detail
arrayproperty
array:Array  [read-only]

This property can be used as the source for data binding.

Implementation
    public function get array():Array
Constructor detail
SortedSetFx()constructor
public function SortedSetFx(comparator:IComparator)

Creates a new SortedSetFx.

Parameters
comparator:IComparator — The sort criterion.
Method detail
addEventListener()method
public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void

Parameters
type:String
 
listener:Function
 
useCapture:Boolean (default = false)
 
priority:int (default = 0)
 
useWeakReference:Boolean (default = false)
clear()method 
public override function clear():void

Removes all items from the collection.

dispatchEvent()method 
public function dispatchEvent(event:Event):Boolean

Parameters
event:Event

Returns
Boolean
hasEventListener()method 
public function hasEventListener(type:String):Boolean

Parameters
type:String

Returns
Boolean
nodeAdded()method 
protected override function nodeAdded(node:TreapNode):void

Template method to notify subclasses after a new node has been added.

Parameters
node:TreapNode — The last added node.
nodeRemoved()method 
protected override function nodeRemoved():void

Commits the removal of the node, announced in willRemoveNode()

removeEventListener()method 
public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void

Parameters
type:String
 
listener:Function
 
useCapture:Boolean (default = false)
toString()method 
public override function toString():String

Info

Returns
String
willRemoveNode()method 
protected override function willRemoveNode(node:TreapNode):void

Template 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.

Parameters
node:TreapNode — The node that will be removed soon.
willTrigger()method 
public function willTrigger(type:String):Boolean

Parameters
type:String

Returns
Boolean
Event detail
collectionChangedevent 
Event object type: as3.collections.fx.events.SetEvent
SetEvent.type property = 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:

PropertyValue
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.
keyThe key of the affected item.
Only set for map events.
Not set for DATA_SOURCE_REPLACED and COLLECTION_EMPTIED.