Package | com.ericfeminella.collections |
Class | public class ResourceMap |
Implements | IMap |
IMap
implementation which dynamically
creates a Map of key / value pairs and provides a
standard API for working with an instance of an
ResourceBundle
ResourceMap
instance
has keys and values: created, retrieved, updated and
deleted (CRUD) via an IMap
implementation
import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.IMap; import mx.resources.ResourceBundle; [ResourceBundle("resources")] private static const rb:ResourceBundle; // resources.properties content: // PROPERTY_A = value A // PROPERTY_B = value B var map:IMap = new ResourceMap(); map.put("PROPERTY_A", "value A"); map.put("PROPERTY_B", "new value..."); trace( map.getKeys() ); trace( map.getValues() ); trace( map.size() ); // outputs the following: // PROERTY_A, PROERTY_B // value A, new value... // 2
See also
Method | Defined by | ||
---|---|---|---|
ResourceMap(bundle:IResourceBundle)
Creates a new
ResourceMap instance which
contains a map of key / value pairs initially defined
in the specified ResourceBundle
By default, weak key references are used in order to ensure that objects are eligible for Garbage Collection immediatly after they are no longer being referenced. | ResourceMap | ||
clear():void
Resets all key / values in the
ResourceMap
instance to null
| ResourceMap | ||
clearAllExcept(keyId:*):void
Clears all key / values defined in the
ResourceMap
instance with the exception of the specified key
| ResourceMap | ||
containsKey(key:*):Boolean
Determines if a key exists in the
ResourceMap
instance
| ResourceMap | ||
containsValue(value:*):Boolean
Determines if a value exists in the
ResourceMap
instance
| ResourceMap | ||
getEntries():IList
Returns an
IList of IHashMapEntry
objects based on the underlying internal map. | ResourceMap | ||
getKey(value:*):*
Returns a key based on the value of the key in the
underlying
ResourceMap instance
| ResourceMap | ||
getKeys():Array
Returns each key added to the
ResourceMap
instance
| ResourceMap | ||
getValue(key:*):*
Retrieves the value of the specified key from the
ResourceMap instance
| ResourceMap | ||
getValues():Array
Retrieves each value assigned to each key in the
ResourceMap instance
| ResourceMap | ||
isEmpty():Boolean
Determines if the current
ResourceMap
instance is empty
| ResourceMap | ||
put(key:*, value:*):void
Adds a key and value to the
ResourceMap
instance
| ResourceMap | ||
putAll(table:Dictionary):void
[new]
putAll places all name / value pairs defined in an Object or Dictionary instance into the ResourceBundle instance. | ResourceMap | ||
putEntry(entry:IHashMapEntry):void
[new]
putEntry is intended as a pseudo-overloaded
put implementation whereby clients may call
putEntry to pass an IHashMapEntry
implementation. | ResourceMap | ||
remove(key:*):void
Removes a key and value from the
ResourceMap
instance
| ResourceMap | ||
reset():void
Resets all key value assignments in the
ResourceMap
instance to null
| ResourceMap | ||
resetAllExcept(keyId:*):void
Resets all key / values defined in the
ResourceMap
instance to null with the exception of the specified key
| ResourceMap | ||
size():int
Determines the size of the
ResourceMap
instance
| ResourceMap |
ResourceMap | () | constructor |
public function ResourceMap(bundle:IResourceBundle)
Creates a new ResourceMap
instance which
contains a map of key / value pairs initially defined
in the specified ResourceBundle
By default, weak key references are used in order to ensure that objects are eligible for Garbage Collection immediatly after they are no longer being referenced.
Parametersbundle:IResourceBundle — instance to convert to map
|
ResourceMap
import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.IMap; import mx.resources.ResourceBundle; [ResourceBundle("resources")] private static const rb:ResourceBundle; var map:IMap = new ResourceMap( rb, false );
clear | () | method |
public function clear():void
Resets all key / values in the ResourceMap
instance to null
import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.IMap; import mx.resources.ResourceBundle; [ResourceBundle("resources")] private static const rb:ResourceBundle; var map:IMap = new ResourceMap( rb, false ); map.put( "admin", adminVO ); map.put( "editor", editorVO ); trace( map.size() ); //2 map.clear(); trace( map.size() ); //0
clearAllExcept | () | method |
public function clearAllExcept(keyId:*):void
Clears all key / values defined in the ResourceMap
instance with the exception of the specified key
keyId:* — key which is not to be cleared from the map
|
import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.IMap; import mx.resources.ResourceBundle; [ResourceBundle("resources")] private static const rb:ResourceBundle; var map:IMap = new ResourceMap( rb, false ); map.put( "admin", adminVO ); map.put( "editor", editorVO ); trace( map.size() ); //2 map.clearAllExcept( "editor", editorVO ); trace( map.getValues() ); //[object, editorVO] trace( map.size() ); //1
containsKey | () | method |
public function containsKey(key:*):Boolean
Determines if a key exists in the ResourceMap
instance
key:* — key from which to determine existance in the map
|
Boolean — true if the key exists, otherwise false
|
import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.IMap; import mx.resources.ResourceBundle; [ResourceBundle("resources")] private static const rb:ResourceBundle; var map:IMap = new ResourceMap( rb, false ); map.put( "admin", adminVO ); trace( map.containsKey( "admin" ) ); //true
containsValue | () | method |
public function containsValue(value:*):Boolean
Determines if a value exists in the ResourceMap
instance
value:* — value in which to determine existance in the map
|
Boolean — true if the value exisits, otherwise false
|
import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.IMap; import mx.resources.ResourceBundle; [ResourceBundle("resources")] private static const rb:ResourceBundle; var map:IMap = new ResourceMap( rb, false ); map.put( "admin", adminVO ); trace( map.containsValue( adminVO ) ); //true
getEntries | () | method |
public function getEntries():IList
Returns an IList
of IHashMapEntry
objects based on the underlying internal map.
IList |
getKey | () | method |
public function getKey(value:*):*
Returns a key based on the value of the key in the
underlying ResourceMap
instance
value:* — the key in which to retrieve the value of
|
String — the value of the specified key
|
import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.IMap; import mx.resources.ResourceBundle; [ResourceBundle("resources")] private static const rb:ResourceBundle; var map:IMap = new ResourceMap( rb, false ); map.put( "admin", adminVO ); trace( map.getKey( adminVO ) ); //admin
getKeys | () | method |
public function getKeys():Array
Returns each key added to the ResourceMap
instance
Array — Array of key identifiers
|
import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.IMap; import mx.resources.ResourceBundle; [ResourceBundle("resources")] private static const rb:ResourceBundle; var map:IMap = new ResourceMap( rb, false ); map.put( "admin", adminVO ); map.put( "editor", editorVO ); trace( map.getKeys() ); //admin, editor
getValue | () | method |
public function getValue(key:*):*
Retrieves the value of the specified key from the
ResourceMap
instance
key:* — the key in which to retrieve the value of
|
* — value of specified key, otherwise undefined
|
import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.IMap; import mx.resources.ResourceBundle; [ResourceBundle("resources")] private static const rb:ResourceBundle; var map:IMap = new ResourceMap( rb, false ); map.put( "admin", adminVO ); map.put( "editor", editorVO ); trace( map.getValue( "editor" ) ); // [object, editorVO]
getValues | () | method |
public function getValues():Array
Retrieves each value assigned to each key in the
ResourceMap
instance
Array — Array of values assigned for all keys in the map
|
import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.IMap; import mx.resources.ResourceBundle; [ResourceBundle("resources")] private static const rb:ResourceBundle; var map:IMap = new ResourceMap( rb, false ); map.put( "admin", adminVO ); map.put( "editor", editorVO ); trace( map.getValues() ); //[object, adminVO],[object, editorVO]
isEmpty | () | method |
public function isEmpty():Boolean
Determines if the current ResourceMap
instance is empty
Boolean — true if the current map is empty, false if not
|
import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.IMap; import mx.resources.ResourceBundle; [ResourceBundle("resources")] private static const rb:ResourceBundle; var map:IMap = new ResourceMap( rb, false ); trace( map.isEmpty() ); //true map.put( "admin", adminVO ); trace( map.isEmpty() ); // false
put | () | method |
public function put(key:*, value:*):void
Adds a key and value to the ResourceMap
instance
key:* — key to add to the underlying map
|
|
value:* — value of the specified key
|
import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.IMap; import mx.resources.ResourceBundle; [ResourceBundle("resources")] private static const rb:ResourceBundle; var map:IMap = new ResourceMap( rb, false ); map.put( "amount", 200.32 );
putAll | () | method |
public function putAll(table:Dictionary):void
Places all name / value pairs into the current
IMap
instance.
table:Dictionary — Object of name / value pairs
|
import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.IMap; import mx.resources.ResourceBundle; [ResourceBundle("resources")] private static const rb:ResourceBundle; var map:IMap = new ResourceMap( rb, false ); var table:Object = {a: "foo", b: "bar"}; map.putAll( table ); trace( map.getKeys() ); // a, b trace( map.getValues() ); // foo, bar
putEntry | () | method |
public function putEntry(entry:IHashMapEntry):void
putEntry
is intended as a pseudo-overloaded
put
implementation whereby clients may call
putEntry
to pass an IHashMapEntry
implementation.
entry:IHashMapEntry — IHashMapEntry implementation
|
remove | () | method |
public function remove(key:*):void
Removes a key and value from the ResourceMap
instance
key:* — key to remove from the map
|
import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.IMap; import mx.resources.ResourceBundle; [ResourceBundle("resources")] private static const rb:ResourceBundle; var map:IMap = new ResourceMap( rb, false ); map.put( "admin", adminVO ); map.remove( "admin" );
reset | () | method |
public function reset():void
Resets all key value assignments in the ResourceMap
instance to null
resetAllExcept | () | method |
public function resetAllExcept(keyId:*):void
Resets all key / values defined in the ResourceMap
instance to null with the exception of the specified key
keyId:* — key which is not to be cleared from the map
|
import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.IMap; import mx.resources.ResourceBundle; [ResourceBundle("resources")] private static const rb:ResourceBundle; var map:IMap = new ResourceMap( rb, false ); map.put( "admin", adminVO ); map.put( "editor", editorVO ); trace( map.getValues() ); // [object, adminVO],[object, editorVO] map.resetAllExcept( "editor", editorVO ); trace( map.getValues() ); // null,[object, editorVO]
size | () | method |
public function size():int
Determines the size of the ResourceMap
instance
int — the current size of the map instance
|
import com.ericfeminella.collections.ResourceMap; import com.ericfeminella.collections.IMap; import mx.resources.ResourceBundle; [ResourceBundle("resources")] private static const rb:ResourceBundle; var map:IMap = new ResourceMap( rb, false ); map.put( "admin", adminVO ); map.put( "editor", editorVO ); trace( map.size() ); //2