package com.ericfeminella.collections
{
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.utils.Dictionary;
/**
*
* <code>BindableMap</code> provides a wrapper API which facilitates
* data binding of an <code>IMap</code> implementation.
*
* <p>
* An object which implements the <code>IMap</code> interface can
* be specified as the source of data binding via an instance of
* <code>BindableMap</code>.
* </p>
*
* <p>
* The typical implementation is to utilize <code>BindableMap</code>
* to provide data binding capabilities to a <code>HashMap</code>.
* </p>
*
* @example The following example demonstrates the typical client
* implementation of <code>BindableMap</code>.
*
* <listing version="3.0">
*
* [Bindable]
* private var _map:BindableMap = new BindableMap( new HashMap() );
*
* private function init() : void
* {
* map.put( "a", "value A" );
* map.put( "b", "value B" );
* map.put( "c", "value C" );
* }
*
* </listing>
*
* <p>
* <code>BindableMap</code> can be used with any <code>IMap</code>
* implementation, such as <code>LocalPersistanceMap</code> as well
* as <code>ResourceMap</code>, so as to provide data bindable to
* a <code>LocalSharedObject</code> or <code>ResourceBundle</code>,
* respectively.
* </p>
*
* @example The following example demonstrates the typical client
* implementation of <code>BindableMap</code> utilized to provide
* data binding capabilities to a <code>LocalSharedObject</code>
* via a <code>LocalPersistanceMap</code> instance.
*
* <listing version="3.0">
*
* [Bindable]
* private var _map:BindableMap = new BindableMap( new LocalPersistanceMap() );
*
* private function init() : void
* {
* map.put( "a", "value A" );
* map.put( "b", "value B" );
* map.put( "c", "value C" );
* }
*
* </listing>
*
* @see com.ericfeminella.collections.IMap
* @see com.ericfeminella.collections.HashMap
* @see com.ericfeminella.collections.LocalPersistanceMap
* @see com.ericfeminella.collections.ResourceMap
*
*
*/
public class BindableMap extends EventDispatcher implements IMap
{
/**
*
* Defines a reference to the underlying <code>IMap</code> instance
* to which the <code>BindableMap</code> <code>keys</code> and
* <code>values</code> are stored and bound.
*
*/
protected var map:IMap = null;
/**
*
* <code>BindableMap</code> constructor requires an <code>IMap</code>
* instance to which data binding capabilities are to be provided.
*
*/
public function BindableMap(map:IMap)
{
this.map = map;
}
[Bindable("mapChangeEvent")]
/**
*
* @inheritDoc
*
*/
public function containsKey(key:*) : Boolean
{
return map.containsKey( key );
}
[Bindable("mapChangeEvent")]
/**
*
* @inheritDoc
*
*/
public function containsValue(value:*) : Boolean
{
return map.containsValue( value );
}
[Bindable("mapChangeEvent")]
/**
*
* @inheritDoc
*
*/
public function getKey(value:*) : *
{
return map.getKey( value );
}
[Bindable("mapChangeEvent")]
/**
*
* @inheritDoc
*
*/
public function getKeys() : Array
{
return map.getKeys();
}
[Bindable("mapChangeEvent")]
/**
*
* @inheritDoc
*
*/
public function getValue(key:*) : *
{
var value:* = map.getValue( key );
return value;
}
[Bindable("mapChangeEvent")]
/**
*
* @inheritDoc
*
*/
public function getValues() : Array
{
return map.getValues();
}
[Bindable("mapChangeEvent")]
/**
*
* @inheritDoc
*
*/
public function getEntries() : Array
{
return map.getEntries();
}
[Bindable("mapChangeEvent")]
/**
*
* @inheritDoc
*
*/
public function size() : int
{
return map.size();
}
[Bindable("mapChangeEvent")]
/**
*
* @inheritDoc
*
*/
public function isEmpty() : Boolean
{
return map.isEmpty();
}
/**
*
* @inheritDoc
*
*/
public function put(key:*, value:*) : void
{
map.put( key, value );
dispatchEvent( new Event( "mapChangeEvent" ) );
}
/**
*
* @inheritDoc
*
*/
public function putAll(table:Dictionary) : void
{
map.putAll( table );
dispatchEvent( new Event( "mapChangeEvent" ) );
}
/**
*
* @inheritDoc
*
*/
public function putEntry(entry:IHashMapEntry) : void
{
map.putEntry( entry );
dispatchEvent( new Event( "mapChangeEvent" ) );
}
/**
*
* @inheritDoc
*
*/
public function remove(key:*) : void
{
map.remove( key );
dispatchEvent( new Event( "mapChangeEvent" ) );
}
/**
*
* @inheritDoc
*
*/
public function reset() : void
{
map.reset();
dispatchEvent( new Event( "mapChangeEvent" ) );
}
/**
*
* @inheritDoc
*
*/
public function resetAllExcept(keyId:*) : void
{
map.resetAllExcept( keyId );
dispatchEvent( new Event( "mapChangeEvent" ) );
}
/**
*
* @inheritDoc
*
*/
public function clear() : void
{
map.clear();
dispatchEvent( new Event( "mapChangeEvent" ) );
}
/**
*
* @inheritDoc
*
*/
public function clearAllExcept(keyId:*) : void
{
map.clearAllExcept( keyId );
dispatchEvent( new Event( "mapChangeEvent" ) );
}
}
}