Packagevegas.models.maps
Classpublic class MapModel
InheritanceMapModel Inheritance ChangeModel Inheritance CoreModel Inheritance CoreEventDispatcher Inheritance Object
Implements Iterable

This model use an internal Map to register Entry objects with a specific key and this corresponding value.

View the examples



Public Properties
 PropertyDefined By
 Inheritedchannel : String
[read-only] Indicates the channel of this dispatcher if this instance is global.
CoreEventDispatcher
 Inheritedcurrent : *
Determinates the selected value in this model.
ChangeModel
 Inheritedid : *
Returns the id of this IModelObject.
CoreModel
 Inheritedsecurity : Boolean = true
This property defined if the setCurrentVO method can accept the same vo in argument as the current one.
ChangeModel
Protected Properties
 PropertyDefined By
  _map : Map
The internal map of this model.
MapModel
  _sAddType : String
The internal ModelObjectEvent type use in the addVO method.
MapModel
  _sRemoveType : String
The internal ModelObjectEvent type use in the removeVO method.
MapModel
  _sUpdateType : String
The internal ModelObjectEvent type when the update event type is use.
MapModel
Public Methods
 MethodDefined By
  
MapModel(global:Boolean = true, channel:String = null, factory:Map = null, id:* = null)
Creates a new MapModel instance.
MapModel
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0.0, useWeakReference:Boolean = false):void
Allows the registration of event listeners on the event target.
CoreEventDispatcher
  
clear():void
[override] Removes all value objects in the model.
MapModel
  
contains(value:*):Boolean
Returns true if the model contains the specified value.
MapModel
  
containsKey(key:*):Boolean
Returns true if the model contains the specified id key in argument.
MapModel
 Inherited
dispatchEvent(event:Event):Boolean
Dispatches an event into the event flow.
CoreEventDispatcher
  
get(key:*):*
Returns the value register in the model with the specified key.
MapModel
 Inherited
Returns the internal system.events.EventDispatcher reference.
CoreEventDispatcher
  
Returns the event name use in the addVO method.
MapModel
 Inherited
Returns the event name use in the setCurrentVO method before is changed.
ChangeModel
 Inherited
Returns the event name use in the setVO method.
ChangeModel
 Inherited
Returns the event name use in the clear method.
ChangeModel
  
Returns the event name use in the removeVO method.
MapModel
  
Returns the event name use in the updateVO method.
MapModel
  
Returns the internal map of this model.
MapModel
  
Returns the MapEntry representation of the key/value entry register in the model with the specified key.
MapModel
 Inherited
hasEventListener(type:String):Boolean
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
CoreEventDispatcher
  
[override] This method is invoked to initialize all event types of the model.
MapModel
  
Initialize the internal Map instance in the constructor of the class.
MapModel
  
isEmpty():Boolean
Returns true if the model is empty.
MapModel
 Inherited
isGlobal():Boolean
Indicates if the dispatcher use a global event flow.
CoreEventDispatcher
 Inherited
isLocked():Boolean
Returns true if the object is locked.
CoreEventDispatcher
  
Returns the iterator of this model.
MapModel
  
Returns the keys iterator of this model.
MapModel
 Inherited
lock():void
Locks the object.
CoreEventDispatcher
  
notifyAdd(entry:Entry):void
Notify a ModelObjectEvent when a ValueObject is inserted in the model.
MapModel
  
notifyBeforeChange(value:*):void
[override] Notify an event before the current value selected in the model is changed.
MapModel
  
notifyChange(value:*):void
[override] Notify an event when a value is selected and changed in the model.
MapModel
  
[override] Notify an event when the model is cleared.
MapModel
  
notifyRemove(entry:Entry):void
Notify an EntryEvent when an key/value entry is removed in the model.
MapModel
  
notifyUpdate(entry:Entry):void
Notify an EntryEvent when the model is updated.
MapModel
  
put(key:*, value:*):void
Inserts a value object in the model.
MapModel
 Inherited
registerEventListener(type:String, listener:*, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Allows the registration of event listeners on the event target (Function or EventListener).
CoreEventDispatcher
  
remove(key:*):void
Removes the entry register in the model with the specified key.
MapModel
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
CoreEventDispatcher
 Inherited
run(... arguments):void
Run the first process with this model.
CoreModel
 Inherited
Sets the internal EventDispatcher reference.
CoreEventDispatcher
  
setEventTypeADD(type:String):void
Sets the event name use in the addVO method.
MapModel
 Inherited
setEventTypeBEFORE_CHANGE(type:String):void
Returns the event name use in the setCurrentVO method before is changed.
ChangeModel
 Inherited
setEventTypeCHANGE(type:String):void
Returns the event name use in the setVO method.
ChangeModel
 Inherited
setEventTypeCLEAR(type:String):void
Returns the event name use in the clear method.
ChangeModel
  
setEventTypeREMOVE(type:String):void
Sets the event name use in the removeVO method.
MapModel
  
setEventTypeUPDATE(type:String):void
Sets the event name use in the addVO method.
MapModel
 Inherited
setGlobal(flag:Boolean = false, channel:String = null):void
Sets if the instance use a global system.events.EventDispatcher to dispatch this events, if the flag value is false the instance use a local EventDispatcher.
CoreEventDispatcher
  
setMap(m:Map):void
Sets the internal map of this model.
MapModel
  
size():Number
Returns the number of ValueObject in this model.
MapModel
 Inherited
unlock():void
Unlocks the display.
CoreEventDispatcher
 Inherited
unregisterEventListener(type:String, listener:*, useCapture:Boolean = false):void
Removes a listener (Function or EventListener object) from the EventDispatcher object.
CoreEventDispatcher
  
update(key:*, value:*):void
Update a key/value entry in the model.
MapModel
 Inherited
willTrigger(type:String):Boolean
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
CoreEventDispatcher
Protected Methods
 MethodDefined By
 Inherited
Creates and returns the internal EventDispatcher reference (this method is invoked in the constructor).
CoreEventDispatcher
Property Detail
_mapproperty
protected var _map:Map

The internal map of this model.

_sAddTypeproperty 
protected var _sAddType:String

The internal ModelObjectEvent type use in the addVO method.

_sRemoveTypeproperty 
protected var _sRemoveType:String

The internal ModelObjectEvent type use in the removeVO method.

_sUpdateTypeproperty 
protected var _sUpdateType:String

The internal ModelObjectEvent type when the update event type is use.

Constructor Detail
MapModel()Constructor
public function MapModel(global:Boolean = true, channel:String = null, factory:Map = null, id:* = null)

Creates a new MapModel instance.

Parameters
global:Boolean (default = true) — the flag to use a global event flow or a local event flow (default true).
 
channel:String (default = null) — (optional) the name of the global event flow if the global argument is true.
 
factory:Map (default = null) — (optional) the Map factory reference used in the model to register all entries.
 
id:* (default = null) — the id of this model.
Method Detail
clear()method
override public function clear():void

Removes all value objects in the model.

contains()method 
public function contains(value:*):Boolean

Returns true if the model contains the specified value.

Parameters

value:*

Returns
Booleantrue if the model contains the specified value.
containsKey()method 
public function containsKey(key:*):Boolean

Returns true if the model contains the specified id key in argument.

Parameters

key:*

Returns
Booleantrue if the model contains the specified id key in argument
get()method 
public function get(key:*):*

Returns the value register in the model with the specified key.

Parameters

key:*

Returns
* — the value register in the model with the specified key.
getEventTypeADD()method 
public function getEventTypeADD():String

Returns the event name use in the addVO method.

Returns
String — the event name use in the addVO method.
getEventTypeREMOVE()method 
public function getEventTypeREMOVE():String

Returns the event name use in the removeVO method.

Returns
String — the event name use in the removeVO method.
getEventTypeUPDATE()method 
public function getEventTypeUPDATE():String

Returns the event name use in the updateVO method.

Returns
String — the event name use in the updateVO method.
getMap()method 
public function getMap():Map

Returns the internal map of this model.

Returns
Map — the internal map of this model.
getMapEntry()method 
public function getMapEntry(key:*):MapEntry

Returns the MapEntry representation of the key/value entry register in the model with the specified key.

Parameters

key:*

Returns
MapEntry — the MapEntry representation of the key/value entry register in the model with the specified key.
initEventType()method 
override public function initEventType():void

This method is invoked to initialize all event types of the model.

initializeMap()method 
public function initializeMap():Map

Initialize the internal Map instance in the constructor of the class. You can overrides this method if you want change the default HashMap use in this model.

Returns
Map
isEmpty()method 
public function isEmpty():Boolean

Returns true if the model is empty.

Returns
Booleantrue if the model is empty.
iterator()method 
public function iterator():Iterator

Returns the iterator of this model.

Returns
Iterator — the iterator of this model.
keyIterator()method 
public function keyIterator():Iterator

Returns the keys iterator of this model.

Returns
Iterator — the keys iterator of this model.
notifyAdd()method 
public function notifyAdd(entry:Entry):void

Notify a ModelObjectEvent when a ValueObject is inserted in the model.

Parameters

entry:Entry

notifyBeforeChange()method 
override public function notifyBeforeChange(value:*):void

Notify an event before the current value selected in the model is changed.

Parameters

value:*

notifyChange()method 
override public function notifyChange(value:*):void

Notify an event when a value is selected and changed in the model.

Parameters

value:*

notifyClear()method 
override public function notifyClear():void

Notify an event when the model is cleared.

notifyRemove()method 
public function notifyRemove(entry:Entry):void

Notify an EntryEvent when an key/value entry is removed in the model.

Parameters

entry:Entry

notifyUpdate()method 
public function notifyUpdate(entry:Entry):void

Notify an EntryEvent when the model is updated.

Parameters

entry:Entry

put()method 
public function put(key:*, value:*):void

Inserts a value object in the model.

Parameters

key:*
 
value:*


Throws
ArgumentError — if the argument of this method is 'null' or 'undefined'.
 
ArgumentError — if the key passed in argument is already register in the model.
remove()method 
public function remove(key:*):void

Removes the entry register in the model with the specified key.

Parameters

key:*

setEventTypeADD()method 
public function setEventTypeADD(type:String):void

Sets the event name use in the addVO method.

Parameters

type:String

setEventTypeREMOVE()method 
public function setEventTypeREMOVE(type:String):void

Sets the event name use in the removeVO method.

Parameters

type:String

setEventTypeUPDATE()method 
public function setEventTypeUPDATE(type:String):void

Sets the event name use in the addVO method.

Parameters

type:String

setMap()method 
public function setMap(m:Map):void

Sets the internal map of this model. By default the 'initializeMap' method is used if the passed-in argument is null.

Parameters

m:Map

size()method 
public function size():Number

Returns the number of ValueObject in this model.

Returns
Number — the number of ValueObject in this model.
update()method 
public function update(key:*, value:*):void

Update a key/value entry in the model.

Parameters

key:*
 
value:*


Throws
ArgumentError — if the key passed-in argument isn't register in the model.
Examples
Example
     
     package examples
     {
         import vegas.events.EntryEvent;
         import vegas.models.maps.MapModel;
         
         import system.data.Iterator;
         import system.data.maps.ArrayMap;
         
         import flash.display.Sprite;
         
         public class ExampleMapModel extends Sprite 
         {
             public function ExampleMapModel()
             {
                 var model:MapModel = new MapModel() ;
                 
                 model.setMap( new ArrayMap() ) ;
                 
                 model.addEventListener( EntryEvent.ADD           , debug ) ;
                 model.addEventListener( EntryEvent.BEFORE_CHANGE , debug ) ;
                 model.addEventListener( EntryEvent.CHANGE        , debug ) ;
                 model.addEventListener( EntryEvent.REMOVE        , debug ) ;
                 model.addEventListener( EntryEvent.UPDATE        , debug ) ;
                 
                 var count:uint = 4 ;
                 
                 for (var i:int ; i<count ; i++ ) 
                 {
                     model.put( "key" + i , "value" + i ) ;
                 }
                 
                 var it:Iterator = model.keyIterator() ;
                 
                 while( it.hasNext() )
                 {
                     model.current = it.next() ;
                 }
                 
                 trace( "- model current : " + model.current ) ;
                 
                 trace( "- model size : " + model.size() ) ;
                 
                 model.remove( "key2" ) ;
                 
                 trace( "- model size : " + model.size() ) ;
                 
                 model.update( "key3" , "content3" ) ;
             }
             
             public function debug( e:EntryEvent ):void
             {
                 trace( "# type:" + e.type + " entry:" + e.entry ) ;
             }
         }
     }