📄 localpersistencemap.as
字号:
*
* import com.ericfeminella.collections.LocalPersistenceMap;
* import com.ericfeminella.collections.IMap;
*
* var map:IMap = new LocalPersistenceMap("sharedObjectName");
* map.put( "admin", adminVO );
* map.put( "editor", editorVO );
*
* trace( map.getKeys() ); //admin, editor
*
* </listing>
*
* @return Array of key identifiers
*
*/
public function getKeys() : Array
{
var keys:Array = new Array();
for ( var prop:String in sharedObject.data )
{
keys.push( prop );
}
return keys;
}
/**
*
* Retrieves each value assigned to the <code>data</code> object of
* the underlying the <code>SharedObject</code> instance.
*
* @example
* <listing version="3.0">
*
* import com.ericfeminella.collections.LocalPersistenceMap;
* import com.ericfeminella.collections.IMap;
*
* var map:IMap = new LocalPersistenceMap("sharedObjectName");
* map.put( "admin", adminVO );
* map.put( "editor", editorVO );
*
* trace( map.getValues() ); //[object, adminVO],[object, editorVO]
*
* </listing>
*
* @return Array of values assigned for all keys in the map
*
*/
public function getValues() : Array
{
var values:Array = new Array();
for ( var prop:String in sharedObject.data )
{
values.push( sharedObject.data[prop] );
}
return values;
}
/**
*
* Determines the size of the <code>data</code> object of the
* underlying the <code>SharedObject</code> instance.e
*
* @example
* <listing version="3.0">
*
* import com.ericfeminella.collections.LocalPersistenceMap;
* import com.ericfeminella.collections.IMap;
*
* var map:IMap = new LocalPersistenceMap("sharedObjectName");
* map.put( "admin", adminVO );
* map.put( "editor", editorVO );
*
* trace( map.size() ); //2
*
* </listing>
*
* @return the current size of the map instance
*
*/
public function size() : int
{
var length:int = 0;
for ( var key:* in sharedObject.data )
{
length++;
}
return length;
}
/**
*
* Determines if the current <code>data</code> object of the
* underlying the <code>SharedObject</code> instance is empty.
*
* @example
* <listing version="3.0">
*
* import com.ericfeminella.collections.LocalPersistenceMap;
* import com.ericfeminella.collections.IMap;
*
* var map:IMap = new LocalPersistenceMap("sharedObjectName");
* trace( map.isEmpty() ); //true
*
* map.put( "admin", adminVO );
* trace( map.isEmpty() ); //false
*
* </listing>
*
* @return true if the current map is empty, false if not
*
*/
public function isEmpty() : Boolean
{
return size() <= 0;
}
/**
*
* Resets all key / value assignment in the <code>data</code> object
* of the underlying the <code>SharedObject</code> instance is empty
* to null.
*
* @example
* <listing version="3.0">
*
* import com.ericfeminella.collections.LocalPersistenceMap;
* import com.ericfeminella.collections.IMap;
*
* var map:IMap = new LocalPersistenceMap("sharedObjectName");
* map.put( "admin", adminVO );
* map.put( "editor", editorVO );
* map.reset();
*
* trace( map.getValues() ); //null, null
*
* </listing>
*
*/
public function reset() : void
{
for ( var prop:String in sharedObject.data )
{
sharedObject.data[prop] = null;
}
sharedObject.flush( minimumStorage );
}
/**
*
* Resets all key / values defined in the <code>data</code> object of
* the underlying the <code>SharedObject</code> instance is empty to
* null with the exception of the specified key.
*
* @example
* <listing version="3.0">
*
* import com.ericfeminella.collections.LocalPersistenceMap;
* import com.ericfeminella.collections.IMap;
*
* var map:IMap = new LocalPersistenceMap("sharedObjectName");
* 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]
*
* </listing>
*
* @param the key which is not to be cleared from the map
*
*/
public function resetAllExcept(key:*) : void
{
for ( var prop:String in sharedObject.data )
{
if ( prop != key )
{
sharedObject.data[prop] = null;
}
}
sharedObject.flush( minimumStorage );
}
/**
*
* Resets all key / values in the <code>data</code> object of the
* underlying the <code>SharedObject</code> instance to null.
*
* @example
*
* <listing version="3.0">
*
* import com.ericfeminella.collections.LocalPersistenceMap;
* import com.ericfeminella.collections.IMap;
*
* var map:IMap = new LocalPersistenceMap("sharedObjectName");
* map.put( "admin", adminVO );
* map.put( "editor", editorVO );
*
* trace( map.size() ); //2
*
* map.clear();
*
* trace( map.size() ); //0
*
* </listing>
*
*/
public function clear() : void
{
for ( var key:* in sharedObject.data )
{
remove( key );
}
sharedObject.flush( minimumStorage );
}
/**
*
* Clears all key / values defined in the <code>data</code> object
* of the underlying the <code>SharedObject</code> instance with the
* exception of the specified key.
*
* @example
*
* <listing version="3.0">
*
* import com.ericfeminella.collections.LocalPersistenceMap;
* import com.ericfeminella.collections.IMap;
*
* var map:IMap = new LocalPersistenceMap("sharedObjectName");
* 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
*
* </listing>
*
* @param the key which is not to be cleared from the map
*
*/
public function clearAllExcept(key:*) : void
{
for ( var prop:String in sharedObject.data )
{
if ( prop != key )
{
delete sharedObject.data[prop];
}
}
sharedObject.flush( minimumStorage );
}
/**
*
* Retrieves the underlying <code>SharedObject</code> instance
* used by the <code>LocalPersistenceMap</code>.
*
* @example
* <listing version="3.0">
*
* import com.ericfeminella.collections.LocalPersistenceMap;
* import com.ericfeminella.collections.IMap;
*
* var map:LocalPersistenceMap = new LocalPersistenceMap("sharedObjectName");
* trace( map.sharedObjectInstance );
*
* </listing>
*
* @return underlying <code>SharedObject</code> instance
*
*/
public function get sharedObjectInstance() : SharedObject
{
return sharedObject;
}
/**
*
* Removes invalid charachters from a <code>SharedObject</code> name
* and substitutes the invalid charachters with an underscore.
*
* @return a valid <code>SharedObject</code> name
*
*/
protected static function stripInvalidChars(identifier:String) : String
{
var pattern:RegExp = /[~%&\;:\"\'<>\?#]/g;
return identifier.replace(pattern, "_");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -