Packagecom.ericfeminella.collections
Classpublic class ResourceMap
ImplementsIMap

IMap implementation which dynamically creates a Map of key / value pairs and provides a standard API for working with an instance of an ResourceBundle


Example
The following example demonstrates a typical use-case in which a 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

mx.resources.IResourceBundle
mx.resources.ResourceBundle
com.ericfeminella.collections.IMap


Public Methods
 MethodDefined 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
Constructor detail
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.

Parameters
bundle:IResourceBundle — instance to convert to map

Example
The following example demonstrates how to create a new instance of 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 );
                  

Method detail
clear()method
public function clear():void

Resets all key / values in the ResourceMap instance to null


Example
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

Parameters
keyId:* — key which is not to be cleared from the map

Example
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

Parameters
key:* — key from which to determine existance in the map

Returns
Boolean — true if the key exists, otherwise false

Example
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

Parameters
value:* — value in which to determine existance in the map

Returns
Boolean — true if the value exisits, otherwise false

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

Returns
IList
getKey()method 
public function getKey(value:*):*

Returns a key based on the value of the key in the underlying ResourceMap instance

Parameters
value:* — the key in which to retrieve the value of

Returns
String — the value of the specified key

Example
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

Returns
Array — Array of key identifiers

Example
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

Parameters
key:* — the key in which to retrieve the value of

Returns
* — value of specified key, otherwise undefined

Example
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

Returns
Array — Array of values assigned for all keys in the map

Example
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

Returns
Boolean — true if the current map is empty, false if not

Example
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

Parameters
key:* — key to add to the underlying map
 
value:* — value of the specified key

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

Parameters
table:DictionaryObject of name / value pairs

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

Parameters
entry:IHashMapEntryIHashMapEntry implementation
remove()method 
public function remove(key:*):void

Removes a key and value from the ResourceMap instance

Parameters
key:* — key to remove from the map

Example
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


Example
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 ); map.reset(); trace( map.getValues() ); // null, 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

Parameters
keyId:* — key which is not to be cleared from the map

Example
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

Returns
int — the current size of the map instance

Example
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