Packagesystem.models.maps
Classpublic class MapModel
InheritanceMapModel Inheritance ChangeModel Inheritance KernelModel Inheritance Object
Implements Iterable
Subclasses OrderedMapModel

This model use an internal Map to register objects with a specific key.

Example :

                  
     package examples
     {
         import core.dump;
         
         import system.models.maps.MapModel;
         
         import flash.display.Sprite;
         
         public class MapModelExample extends Sprite
         {
             public function MapModelExample()
             {
                 model = new MapModel() ;
                 
                 trace( "# model primary key : " + model.primaryKey ) ;
                 
                 model.added.connect( added ) ;
                 model.beforeChanged.connect( beforeChanged ) ;
                 model.changed.connect( changed ) ;
                 model.cleared.connect( cleared ) ;
                 model.removed.connect( removed ) ;
                 model.updated.connect( updated ) ;
                 
                 model.add( o1 ) ;
                 model.add( o2 ) ;
                 model.add( o3 ) ;
                 
                 trace( "#  model.get('key1') == o1 : " + ( model.get("key1") == o1 ) ) ;
                 trace( "#  model.get('key1') == o4 : " + ( model.get("key1") == o4 ) ) ;
                 
                 model.update( o4 ) ;
                 
                 model.current = o1 ;
                 model.current = o2 ;
                 
                 model.remove( o1 ) ;
                 
                 model.clear() ;
             }
             
             protected var model:MapModel ;
             
             protected var o1:Object = { id : "key1" } ;
             protected var o2:Object = { id : "key2" } ;
             protected var o3:Object = { id : "key3" } ;
             protected var o4:Object = { id : "key1" } ;
             
             protected function added( value:, model:MapModel ):void
             {
                 trace( model + " added : " + dump(value) ) ;
             }
             
             protected function beforeChanged( value:, model:MapModel ):void
             {
                 trace( model + " beforeChanged : " + dump(value) ) ;
             }
             
             protected function changed( value:, model:MapModel ):void
             {
                 trace( model + " changed : " + dump(value) ) ;
             }
             
             protected function cleared( model:MapModel ):void
             {
                 trace( model + " cleared" ) ;
             }
             
             protected function removed( value:, model:MapModel ):void
             {
                 trace( model + " removed : " + dump(value) ) ;
             }
             
             protected function updated( value:, model:MapModel ):void
             {
                 trace( model + " updated : " + dump(value) ) ;
                 trace( "#  model.get('key1') == o1 : " + ( model.get("key1") == o1 ) ) ;
                 trace( "#  model.get('key1') == o4 : " + ( model.get("key1") == o4 ) ) ;
             }
         }
     }
     
               



Public Properties
 PropertyDefined By
  added : Signaler
[read-only] Emits a message when an entry is added in the model.
MapModel
 InheritedbeforeChanged : Signaler
[read-only] Emits a message before the current object in the model is changed.
ChangeModel
 Inheritedchanged : Signaler
[read-only] Emits a message when the current object in the model is changed.
ChangeModel
 Inheritedcleared : Signaler
[read-only] Emits a message when the current object in the model is cleared.
ChangeModel
 Inheritedcurrent : *
Determinates the selected value in this model.
ChangeModel
  length : uint
[read-only] Indicates the number of entries in the model.
MapModel
  primaryKey : String
Indicates the name of the primary key used to map all objects in the model and identifies each record in the table.
MapModel
  removed : Signaler
[read-only] Emits a message when an entry is removed in the model.
MapModel
 Inheritedsecurity : Boolean = true
This property defined if the current property can accept the same object in argument as the current one.
ChangeModel
  updated : Signaler
[read-only] Emits a message when an entry is updated in the model.
MapModel
Public Methods
 MethodDefined By
  
MapModel(factory:Map = null, key:String = id)
Creates a new MapModel instance.
MapModel
  
add(entry:Object):void
Inserts an entry in the model, must be identifiable and contains an id property.
MapModel
  
clear():void
[override] Removes all value objects in the model.
MapModel
  
contains(entry:Object):Boolean
Returns true if the model contains the specified entry.
MapModel
  
containsByProperty(propName:String, value:*):Boolean
Returns true if the model contains the specified attribute value.
MapModel
  
containsKey(key:*):Boolean
Returns true if the model contains the specified id key in argument.
MapModel
  
get(key:*):Object
Returns the entry defined by the key passed-in argument.
MapModel
  
getByProperty(propName:String, value:*):Object
Returns an entry defines in the model with the specified member.
MapModel
  
Returns the internal map of this model.
MapModel
  
isEmpty():Boolean
Returns true if the model is empty.
MapModel
 Inherited
isLocked():Boolean
Returns true if the object is locked.
KernelModel
  
Returns the iterator of this model.
MapModel
  
Returns the keys iterator of this model.
MapModel
 Inherited
lock():void
Locks the object.
KernelModel
  
notifyAdd(entry:Object):void
Notify a signal when a new entry is inserted in the model.
MapModel
 Inherited
notifyBeforeChange(value:*):void
Notify a signal before the specified value is changed.
ChangeModel
 Inherited
notifyChange(value:*):void
Notify a signal when the model is changed.
ChangeModel
 Inherited
Notify a signal when the model is cleared.
ChangeModel
  
notifyRemove(entry:Object):void
Notify a signal when a new entry is removed in the model.
MapModel
  
notifyUpdate(entry:Object):void
Notify a signal when a new entry is updated in the model.
MapModel
  
remove(entry:Object):void
Removes an entry in the model.
MapModel
  
setMap(map:Map):void
Sets the internal map of this model (default use a new system.data.maps.HashMap instance).
MapModel
 Inherited
supports(value:*):Boolean
Returns true if the Validator object validate the value.
KernelModel
 Inherited
unlock():void
Unlocks the display.
KernelModel
  
update(entry:Object):void
Update a value object in the model.
MapModel
 Inherited
validate(value:*):void
Evaluates the specified value and throw a TypeError object if the value is not valid.
KernelModel
Public Constants
 ConstantDefined By
  DEFAULT_PRIMARY_KEY : String = id
[static] Indicates the default primary key value ("id").
MapModel
Property Detail
addedproperty
added:Signaler  [read-only]

Emits a message when an entry is added in the model.


Implementation
    public function get added():Signaler
lengthproperty 
length:uint  [read-only]

Indicates the number of entries in the model.


Implementation
    public function get length():uint
primaryKeyproperty 
primaryKey:String

Indicates the name of the primary key used to map all objects in the model and identifies each record in the table. By default the model use the "id" primary key in the objects.

Note: If you use this property and if the model contains entries, all entries will be removing.


Implementation
    public function get primaryKey():String
    public function set primaryKey(value:String):void

See also

DEFAULT_PRIMARY_KEY
removedproperty 
removed:Signaler  [read-only]

Emits a message when an entry is removed in the model.


Implementation
    public function get removed():Signaler
updatedproperty 
updated:Signaler  [read-only]

Emits a message when an entry is updated in the model.


Implementation
    public function get updated():Signaler
Constructor Detail
MapModel()Constructor
public function MapModel(factory:Map = null, key:String = id)

Creates a new MapModel instance.

Parameters
factory:Map (default = null) — (optional) the Map factory reference used in the model to register all entries.
 
key:String (default = id) — Indicates the name of the primary key used to map all objects in the model and identifies each record in the table (default "id").
Method Detail
add()method
public function add(entry:Object):void

Inserts an entry in the model, must be identifiable and contains an id property.

Parameters

entry:Object


Throws
ArgumentError — if the argument of this method is 'null' or 'undefined'.
 
ArgumentError — if the passed-in entry is already register in the model.
clear()method 
override public function clear():void

Removes all value objects in the model.

contains()method 
public function contains(entry:Object):Boolean

Returns true if the model contains the specified entry.

Parameters

entry:Object

Returns
Booleantrue if the model contains the specified entry.
containsByProperty()method 
public function containsByProperty(propName:String, value:*):Boolean

Returns true if the model contains the specified attribute value.

Parameters

propName:String
 
value:*

Returns
Booleantrue if the model contains the specified key in argument
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:*):Object

Returns the entry defined by the key passed-in argument.

Parameters

key:*

Returns
Object — the entry defined by the key passed-in argument.
getByProperty()method 
public function getByProperty(propName:String, value:*):Object

Returns an entry defines in the model with the specified member.

Parameters

propName:String
 
value:*

Returns
Object — an entry defines in the model with the specified member.
getMap()method 
public function getMap():Map

Returns the internal map of this model.

Returns
Map — the internal map of this model.
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:Object):void

Notify a signal when a new entry is inserted in the model.

Parameters

entry:Object

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

Notify a signal when a new entry is removed in the model.

Parameters

entry:Object

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

Notify a signal when a new entry is updated in the model.

Parameters

entry:Object

remove()method 
public function remove(entry:Object):void

Removes an entry in the model.

Parameters

entry:Object

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

Sets the internal map of this model (default use a new system.data.maps.HashMap instance).

Parameters

map:Map

update()method 
public function update(entry:Object):void

Update a value object in the model.

Parameters

entry:Object


Throws
ArgumentError — if the entry is not register in the model.
Constant Detail
DEFAULT_PRIMARY_KEYConstant
public static const DEFAULT_PRIMARY_KEY:String = id

Indicates the default primary key value ("id").