Packagesystem.data.maps
Classpublic class MultiValueMap
InheritanceMultiValueMap Inheritance Object
Implements MultiMap
Subclasses MultiSetMap

A Map with multiple values to keys. It's the basic implementation of the MultiMap interface.

Example :

     import system.data.maps.MultiValueMap ;
     
     var map:MultiValueMap = new MultiValueMap() ;
     
     map.put("key1" , "value1") ;
     map.put("key1" , "value2") ;
     map.put("key2" , "value3") ;
     
     trace( map ) ;
     



Public Properties
 PropertyDefined By
  internalBuildClass : Class
Determinates the internal build class used in the createCollection() method to create a new collection to register all values with a new key.
MultiValueMap
Public Methods
 MethodDefined By
  
MultiValueMap(map:Map = null, factory:* = null)
Creates a new MultiValueMap instance.
MultiValueMap
  
clear():void
Removes all elements in this map.
MultiValueMap
  
clone():*
Returns a shallow copy of this object.
MultiValueMap
  
containsKey(key:*):Boolean
Checks whether the map contains the key specified.
MultiValueMap
  
containsValue(value:*):Boolean
Checks whether the map contains the value specified.
MultiValueMap
  
containsValueByKey(key:*, value:*):Boolean
Checks whether the map contains the value specified or at the specified key contains the value.
MultiValueMap
  
Creates a new instance of the map value Collection container.
MultiValueMap
  
get(key:*):*
Gets the collection mapped to the specified key.
MultiValueMap
  
Gets the collection mapped to the specified key.
MultiValueMap
  
getKeys():Array
Returns an Array containing the combination of all keys in the Map.
MultiValueMap
  
getValues():Array
Returns an Array containing the combination of values from all keys.
MultiValueMap
  
isEmpty():Boolean
Returns whether this object contains any mappings.
MultiValueMap
  
Returns the Iterator representation of the object.
MultiValueMap
  
Gets an Iterator for the collection mapped to the specified key.
MultiValueMap
  
Gets an iterator for the map to iterate keys.
MultiValueMap
  
put(key:*, value:*):*
Adds the value to the collection associated with the specified key.
MultiValueMap
  
putAll(map:Map):void
Override superclass to ensure that MultiMap instances are correctly handled.
MultiValueMap
  
putCollection(key:*, c:Collection):void
Adds a collection of values to the collection associated with the specified key.
MultiValueMap
  
remove(o:*):*
Removes a specific value from map with a specific key.
MultiValueMap
  
removeByKey(key:*, value:*):*
Removes a specific value from all the map.
MultiValueMap
  
size():uint
Returns the size of the collection mapped to the specified key.
MultiValueMap
  
toSource(indent:int = 0):String
Returns the source code string representation of the object.
MultiValueMap
  
toString():String
Returns the string representation of this instance.
MultiValueMap
  
totalSize():uint
Returns the total size of the map by counting all the values.
MultiValueMap
  
Returns the iterator representation of all Collections register in the MultiValueMap, all collections represents a key.
MultiValueMap
  
Returns a Collection of all values in the MultiValueMap.
MultiValueMap
  
Returns an Iterator representation of all values in the MultiValueMap.
MultiValueMap
Property Detail
internalBuildClassproperty
internalBuildClass:Class

Determinates the internal build class used in the createCollection() method to create a new collection to register all values with a new key. The class must implements the Collection interface and by default the ArrayCollection class is used.


Implementation
    public function get internalBuildClass():Class
    public function set internalBuildClass(value:Class):void
Constructor Detail
MultiValueMap()Constructor
public function MultiValueMap(map:Map = null, factory:* = null)

Creates a new MultiValueMap instance.

Example :

         import system.data.maps.MultiValueMap ;
         var map:MultiValueMap = new MultiValueMap() ;
         

Parameters
map:Map (default = null) — Optional Map reference to initialize and fill this MultiMap.
 
factory:* (default = null) — Optional Map reference to create the internal Map of the MultiValueMap
Method Detail
clear()method
public function clear():void

Removes all elements in this map.

Example :

         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.put( "key1" , "hello"   ) ;
         map.put( "key2" , "bonjour" ) ;
         
         map.clear() ;
         
         trace( map ) ; // {}
         

clone()method 
public function clone():*

Returns a shallow copy of this object.

Example :

         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.put("keyA" , "itemA_1" ) ;
         map.put("keyA" , "itemA_2" ) ;
         map.put("keyB" , "itemB_2" ) ;
         
         var clone:MultiValueMap = map.clone() ;
         trace( clone ) ;
         

Returns
* — a shallow copy of this object.
containsKey()method 
public function containsKey(key:*):Boolean

Checks whether the map contains the key specified.

Example :

         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.put( "key1" , "hello world" ) ;
         
         trace( map.containsKey( "key1" ) ) ; // true
         trace( map.containsKey( "key2" ) ) ; // false
         

Parameters

key:*

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

Checks whether the map contains the value specified.

Example :

         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.put( "key1" , "hello"   ) ;
         map.put( "key2" , "bonjour" ) ;
         
         trace( map.containsValue( "hello"       ) ) ; // true
         trace( map.containsValue( "bonjour"     ) ) ; // true
         trace( map.containsValue( "buenos dias" ) ) ; // false
         

Parameters

value:*

Returns
Booleantrue if the List contains the specified value.
containsValueByKey()method 
public function containsValueByKey(key:*, value:*):Boolean

Checks whether the map contains the value specified or at the specified key contains the value.

Example :

         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.put( "key1" , "hello"   ) ;
         map.put( "key2" , "bonjour" ) ;
         
         trace( map.containsValueByKey( "key1" , "hello"   ) ) ; // true
         trace( map.containsValueByKey( "key1" , "bonjour" ) ) ; // false
         
         trace( map.containsValueByKey( "key2" , "hello"       ) ) ; // false
         trace( map.containsValueByKey( "key2" , "bonjour"     ) ) ; // true
         

Parameters

key:*
 
value:*

Returns
Boolean
createCollection()method 
public function createCollection():Collection

Creates a new instance of the map value Collection container. This method can be overridden to use your own collection type.

Returns
Collection
get()method 
public function get(key:*):*

Gets the collection mapped to the specified key.

Example :

         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.put( "key1" , "hello"   ) ;
         map.put( "key2" , "bonjour" ) ;
         
         trace( map.get( "key1"  ) ) ; // {hello}
         trace( map.get( "key2"  ) ) ; // {bonjour}
         trace( map.get( "key3"  ) ) ; // undefined
         

Parameters

key:*

Returns
*
getCollection()method 
public function getCollection(key:*):Collection

Gets the collection mapped to the specified key.

This method is a convenience method to typecast the result of get(key).

Example :

         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.put( "key1" , "hello"   ) ;
         map.put( "key2" , "bonjour" ) ;
         
         trace( map.getCollection( "key1"  ) ) ; // {hello}
         trace( map.getCollection( "key2"  ) ) ; // {bonjour}
         trace( map.getCollection( "key3"  ) ) ; // null
         

Parameters

key:*

Returns
Collection
getKeys()method 
public function getKeys():Array

Returns an Array containing the combination of all keys in the Map.

Example :

         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.put( "key1" , "hello"   ) ;
         map.put( "key2" , "bonjour" ) ;
         
         trace( map.getKeys() ) ; // key1,key2
         

Returns
Array — An Array containing the combination of all keys in the Map.
getValues()method 
public function getValues():Array

Returns an Array containing the combination of values from all keys.

Example :

         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.put( "key1" , "A1"   ) ;
         map.put( "key2" , "B1" ) ;
         map.put( "key2" , "B2" ) ;
         map.put( "key3" , "C1" ) ;
         
         trace( map.getValues() ) ; // no order if the internal Map is a HashMap (default)
         

Returns
Array — An Array containing the combination of values from all keys.
isEmpty()method 
public function isEmpty():Boolean

Returns whether this object contains any mappings.

Example :

         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         trace( map.isEmpty() ) ;  // true
         
         map.put( "key" , "value"   ) ;
         
         trace( map.isEmpty() ) ; // false
         

Returns
Booleantrue if this MultiHashSet contains any mappings else false
iterator()method 
public function iterator():Iterator

Returns the Iterator representation of the object.

Returns
Iterator — the Iterator representation of the object.
iteratorByKey()method 
public function iteratorByKey(key:*):Iterator

Gets an Iterator for the collection mapped to the specified key.

Example :

         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.put("key1" , "value1") ;
         map.put("key1" , "value2") ;
         map.put("key2" , "value3") ;
         
         trace( map.iteratorByKey( "key1" ) ) ; // [object ArrayIterator]
         trace( map.iteratorByKey( "key3" ) ) ; // null
         

Parameters

key:*

Returns
Iterator — the iterator of the collection at the key, null if key not in map
keyIterator()method 
public function keyIterator():Iterator

Gets an iterator for the map to iterate keys.

Returns
Iterator
put()method 
public function put(key:*, value:*):*

Adds the value to the collection associated with the specified key.

Unlike a normal Map the previous value is not replaced. Instead the new value is added to the collection stored against the key.

Example :

         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.put("keyA" , "itemA_1" ) ;
         map.put("keyA" , "itemA_2" ) ;
         
         map.put("keyB" , "itemB_2" ) ;
         
         trace( map ) ; // {keyB:{itemB_2},keyA:{itemA_1,itemA_2}}
         

Parameters

key:* — the key to store against.
 
value:* — the value to add to the collection at the key.

Returns
* — the value added if the map changed and null if the map did not change.
putAll()method 
public function putAll(map:Map):void

Override superclass to ensure that MultiMap instances are correctly handled.

If you call this method with a normal map, each entry is added using put(key:value:. If you call this method with a multi map, each entry is added using putCollection( key: co:Collection ).

Example :

         import system.data.collections.ArrayCollection ;
         
         import system.data.maps.ArrayMap ;
         import system.data.maps.MultiValueMap ;
         
         var am1:ArrayMap = new ArrayMap( [ "key1" , "key2" ] , ["value1" , "value2" ] ) ;
         var am2:ArrayMap = new ArrayMap( [ "key1" ]          , [ new ArrayCollection( [ "value3" ] ) ] ) ;
         
         var mm:MultiValueMap = new MultiValueMap() ;
         
         mm.putAll( am1 ) ; // {key2:{value2},key1:{value1}}
         
         trace( mm ) ;
         
         mm.putAll( am2 ) ; // {key2:{value2},key1:{value1,value3}}
         
         trace( mm ) ;
         

Parameters

map:Map

putCollection()method 
public function putCollection(key:*, c:Collection):void

Adds a collection of values to the collection associated with the specified key.

Example :

         import system.data.collections.ArrayCollection ;
         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.putCollection( "key1" , new ArrayCollection(["value1", "value2"])) ;
         map.putCollection( "key1" , new ArrayCollection(["value3", "value4"])) ;
         map.putCollection( "key2" , new ArrayCollection(["value5"])) ;
         
         trace( map ) ; // {key2:{value5},key1:{value1,value2,value3,value4}}
         

Parameters

key:*
 
c:Collection

remove()method 
public function remove(o:*):*

Removes a specific value from map with a specific key.

Example :

         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.put("key1" , "value1") ;
         map.put("key1" , "value2") ;
         map.put("key2" , "value3") ;
         
         trace( map.remove("key1") ) ; // {value1,value2}
         

Parameters

o:* — the key to remove in the map.

Returns
*
removeByKey()method 
public function removeByKey(key:*, value:*):*

Removes a specific value from all the map.

Example :

         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.put("key1" , "value1") ;
         map.put("key1" , "value2") ;
         map.put("key2" , "value3") ;
         
         trace( map.removeByKey("key1" , "value1" ) ) ; // true
         trace( map.removeByKey("key1" , "value5" ) ) ; // false
         
         trace( map ) ; // {key2:{value3},key1:{value2}}
         

Parameters

key:* — the key to remove in the map
 
value:* — (optional) if this value is defined removes a specific value from map else removes all values associated with the specified key.

Returns
* — the removed value.
size()method 
public function size():uint

Returns the size of the collection mapped to the specified key.

Example :

         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         trace( map.size() ) ;  // 0
         
         map.put( "key1" , "value1" ) ;
         map.put( "key1" , "value2" ) ;
         map.put( "key2" , "value3" ) ;
         
         trace( map.size() ) ; // 2
         

Returns
uint — the size of the collection mapped to the specified key.
toSource()method 
public function toSource(indent:int = 0):String

Returns the source code string representation of the object.

Parameters

indent:int (default = 0)

Returns
String — the source code string representation of the object.
toString()method 
public function toString():String

Returns the string representation of this instance.

Returns
String — the string representation of this instance
totalSize()method 
public function totalSize():uint

Returns the total size of the map by counting all the values.

Example :

         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         trace( map.totalSize() ) ;  // 0
         
         map.put( "key1" , "value1" ) ;
         map.put( "key1" , "value2" ) ;
         map.put( "key2" , "value3" ) ;
         
         trace( map.totalSize() ) ; // 3
         

Returns
uint — the total size of the map by counting all the values.
valueIterator()method 
public function valueIterator():Iterator

Returns the iterator representation of all Collections register in the MultiValueMap, all collections represents a key.

Example :

         import system.data.Iterator ;
         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.put( "key1" , "A1"   ) ;
         map.put( "key2" , "B1" ) ;
         map.put( "key2" , "B2" ) ;
         map.put( "key3" , "C1" ) ;
         
         var it:Iterator = map.valueIterator() ;
         
         trace( it ) ;
         
         while( it.hasNext() )
         {
             trace( it.next() ) ;
         }
         

Returns
Iterator — the iterator representation of all Collections of values in the MultiValueMap.
values()method 
public function values():Collection

Returns a Collection of all values in the MultiValueMap.

Example :

         import system.data.Collection ;
         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.put( "key1" , "A1"   ) ;
         map.put( "key2" , "B1" ) ;
         map.put( "key2" , "B2" ) ;
         map.put( "key3" , "C1" ) ;
         
         var c:Collection = map.values() ;
         
         trace( c ) ;
         

Returns
Collection — a Collection of all values in the MultiValueMap.
valuesIterator()method 
public function valuesIterator():Iterator

Returns an Iterator representation of all values in the MultiValueMap.

         import system.data.Iterator ;
         import system.data.maps.MultiValueMap ;
         
         var map:MultiValueMap = new MultiValueMap() ;
         
         map.put( "key1" , "A1"   ) ;
         map.put( "key2" , "B1" ) ;
         map.put( "key2" , "B2" ) ;
         map.put( "key3" , "C1" ) ;
         
         var it:Iterator = map.valuesIterator() ;
         
         trace( it ) ;
         
         while( it.hasNext() )
         {
             trace( it.next() ) ;
         }
         

Returns
Iterator — an Iterator representation of all values in the MultiValueMap.