Factory methods for creating various Maps.
Example
// maps userId (int) to name (String)
var userNames :Map = Maps.newMapOf(int);
// maps a Hashable Page class to page objects, in a cache: pages will expire when they
// are no longer externally referenced.
var pages :Map = Maps.newBuilder(Page).makeWeakValues().build();
public static function equals(map1:Map, map2:Map):Boolean
Do the two Maps contain the same keys and values?
Parameters
Returns
public static function filter(map:Map, condition:Function, transform:Function = null):Array
Filters all the entries in a map against a condition, transforms those that meet the
condition and returns an array of the transformed, filtered entries.
Parameters
| map:Map — the map whose entries are to be filtered
|
|
| condition:Function — the function to test whether to include an entry:
function condition (key :Object, value :Object) :Boolean
|
|
| transform:Function (default = null ) — the function to obtain an entry in the resulting array:
function transform (key :Object, value :Object) :Object
If the transform is null, the map values are returned.
|
Returns
public static function findKey(map:Map, value:Object):*
Return the first key found for the specified value, or undefined if not found.
Parameters
Returns
public static function newBuilder(keyClazz:Class):MapBuilder
Create a MapBuilder for creating a more complicated Map type.
Parameters
Returns
Example
// builds a sorted, weak-value Map.
var myMap :Map = Maps.newBuilder(String)
.makeSorted()
.makeWeakValues()
.build();
public static function newMapOf(keyClazz:Class):Map
Create a new Map designed to hold keys of the specified class.
If the class is Hashable (but not an Enum), or is String, then a HashMap will be used,
otherwise a DictionaryMap. If your key type is not Hashable, then be sure that
reference equality (the == operator) can be used to compare your keys!
Parameters
Returns
public static function newSortedMapOf(keyClazz:Class, comp:Function = null):Map
Create a new sorted Map designed to hold keys of the specified class.
If the comparator is omitted, it is determined from the keyClazz, or falls back to
Comparators.compareUnknown.
This is a convenience for calling newBuilder(keyClazz).makeSorted(comp).build();
Parameters
| keyClazz:Class |
|
| comp:Function (default = null )
|
Returns
public static function selectKey(key:Object, value:Object):Object
Returns the key of a map entry (for use as a transform function in filter
).
Parameters
Returns
public static function selectValue(key:Object, value:Object):Object
Returns the value of a map entry (for use as a transform function in filter
).
Parameters
Returns
public static function some(map:Map, condition:Function):Boolean
Tests if at least one entry in a map meets a condition.
Parameters
| map:Map — the map whose entries are to be tested
|
|
| condition:Function — a function that tests a map entry:
function predicate (key :Object, value :Object) :Boolean
|
Returns
Copyright © 2007-2009 Three Rings Design, Inc.