KeyValueList
| Kind of class: | class |
|---|---|
| Inherits from: | none |
| Author: | Arthur Clemens |
| Classpath: | org.asapframework.data.KeyValueList |
| File last modified: | Thursday, 12 October 2006, 11:09:24 |
KeyValueList is a dictionary/associative array that stores a list of key-value pairs (KeyValue objects).
KeyValueList uses an Array as storage, so the input order is preserved.
Usage:
This example stores a list of movieclips
var LETTERS:Array = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; mClientLetters = new KeyValueList(); var i:Number, ilen:Number = LETTERS.length; for (i=0; i<ilen; ++i) { var letter:String = LETTERS[i]; var letterClip:MovieClip = timeline.attachMovie("alphabet letter", letter, timeline.getNextHighestDepth()); // Each letter gets one letter movieclip mClientLetters.addValueForKey(letterClip, letter); }
Summary
Constructor
Constructor
KeyValueList
function KeyValueList (
)
Creates a new KeyValueList.
Instance methods
addValueForKey
function addValueForKey (
inValue:Object,
inKey:String) : Void
Adds a new KeyValue object to the list.
Parameters:
inValue:
value to store
inKey :
new key to store the value at
filter
function filter (
inFilterKeys:Array) : KeyValueList
Creates a copy of the current KeyValueList except for the keys as passed in inFilterKeys.
Parameters:
inFilterKeys:
array of keys that should be filtered out from the returned KeyValueList
Returns:
A copy of the current KeyValueList except for the keys as passed in inFilterKeys.
getArray
function getArray (
) : Array
Reference to the internal KeyValue array.
Returns:
The KeyValue array.
getCount
function getCount (
) : Number
Gets the number of items in the list.
Returns:
The number of items in the list.
getValueForKey
function getValueForKey (
inKey:String)
Retrieves a stored object for a given key.
Parameters:
inKey:
key where object is stored at
Returns:
(Deliberately untyped) stored object at given key.
removeObjectAtIndex
function removeObjectAtIndex (
inIndex:Number) : Void
Removes an object at an array position.
Parameters:
inIndex:
array position to remove the object at
removeValueForKey
function removeValueForKey (
inKey:String) : Void
Removes an object at a key.
Parameters:
inKey:
name of key to remove the object from
setValueForKey
function setValueForKey (
inValue:Object,
inKey:String)
Stores an object at an existing key. If the key does not exist yet, the key is added.
Parameters:
inValue:
value to store
inKey :
new key to store the value at
stringify
function stringify (
inKeyValueDelimiter:String,
inItemDelimiter:String) : String
Creates a String for all KeyValue objects in the list. Each key-value pair is stringified following the pattern
key inKeyValueDelimiter value. The key-value pair strings are separated with inItemDelimiterParameters:
inKeyValueDelimiter:
connecting string between key and value
inItemDelimiter :
connecting string between key-value pairs
Returns:
A new string with formatted key-value strings. Returns an empty String if the list has no items.
var myList:KeyValueList = new KeyValueList(); myList.addValueForKey("Tolstoj", "Name"); myList.addValueForKey("Saint Petersburg", "Place of birth"); var myText:String = myList.stringify(": ", "\n");Creates:
Name: Tolstoj Place of birth: Saint Petersburg
stringifyWithFormattedString
function stringifyWithFormattedString (
inFormattedString:String,
inItemDelimiter:String) : String
Returns the list of values as formatted string.
Parameters:
inFormattedString:
accepts %1 and %2 as format parameters
inItemDelimiter :
delimiter between items, for example '\n'
Returns:
A new string with formatted key-value strings.
Example:
Author Tolstoj
Country Russia
var list:KeyValueList= new KeyValueList(); list.addValueForKey("Tolstoj", "Author"); list.addValueForKey("Russia", "Country"); var myHtml:String = list.stringifyWithFormattedString("<font color='#666666'>%1</font> <font color='#000000'>%2</font>", "\n");Result:
Author Tolstoj
Country Russia