KeyValueList
| Kind of class: | class |
|---|---|
| Inherits from: | none |
| Author: | Arthur Clemens |
| Classpath: | org.asapframework.data.KeyValueList |
| File last modified: | Wednesday, 20 September 2006, 01:34:10 |
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.
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
Class properties
- DEFAULT_ITEM_DELIMITER : String
Instance properties
- mKeyValues : Array
- Holds objects of type KeyValue.
Instance methods
- addValueForKey (inValue:Object, inKey:String) : Void
- Adds a new KeyValue object to the list.
- getValueForKey (inKey:String)
- Retrieves a stored object for a given key.
- setValueForKey (inValue:Object, inKey:String)
- Stores an object at an existing key.
- removeValueForKey (inKey:String) : Void
- Removes an object at a key.
- removeObjectAtIndex (inIndex:Number) : Void
- Removes an object at an array position.
- getArray : Array
- Reference to the internal KeyValue array.
- getCount : Number
- Gets the number of items in the list.
- filter (inFilterKeys:Array) : KeyValueList
- Creates a copy of the current KeyValueList except for the keys as passed in inFilterKeys.
- stringify (inKeyValueDelimiter:String, inItemDelimiter:String) : String
- Creates a String for all KeyValue objects in the list.
- stringifyWithFormattedString (inFormattedString:String, inItemDelimiter:String) : String
- Returns the list of values as formatted string.
- toString : String
- findValueForKey (inKey:String) : Number
- Retrieves an object for a given key.
Constructor
KeyValueList
function KeyValueList (
)
Creates a new KeyValueList.
Class properties
DEFAULT_ITEM_DELIMITER
static private DEFAULT_ITEM_DELIMITER:String = ","
(read)
Instance properties
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
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.
findValueForKey
private function findValueForKey (
inKey:String) : Number
Retrieves an object for a given key.
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 inItemDelimiter Parameters:
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 :
(optional) delimiter between items, for example '\n'; default DEFAULT_ITEM_DELIMITER
Returns:
- A new string with formatted key-value strings.
Example:
-
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
toString
private function toString (
) : String