Packagecom.threerings.util
Classpublic class Maps

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 Methods
 MethodDefined by
  
equals(map1:Map, map2:Map):Boolean
[static] Do the two Maps contain the same keys and values?
Maps
  
filter(map:Map, condition:Function, transform:Function = null):Array
[static] 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.
Maps
  
findKey(map:Map, value:Object):*
[static] Return the first key found for the specified value, or undefined if not found.
Maps
  
newBuilder(keyClazz:Class):MapBuilder
[static] Create a MapBuilder for creating a more complicated Map type.
Maps
  
newMapOf(keyClazz:Class):Map
[static] Create a new Map designed to hold keys of the specified class.
Maps
  
newSortedMapOf(keyClazz:Class, comp:Function = null):Map
[static] Create a new sorted Map designed to hold keys of the specified class.
Maps
  
selectKey(key:Object, value:Object):Object
[static] Returns the key of a map entry (for use as a transform function in filter).
Maps
  
selectValue(key:Object, value:Object):Object
[static] Returns the value of a map entry (for use as a transform function in filter).
Maps
  
some(map:Map, condition:Function):Boolean
[static] Tests if at least one entry in a map meets a condition.
Maps
Method detail
equals()method
public static function equals(map1:Map, map2:Map):Boolean

Do the two Maps contain the same keys and values?

Parameters
map1:Map
 
map2:Map

Returns
Boolean
filter()method 
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
Array
findKey()method 
public static function findKey(map:Map, value:Object):*

Return the first key found for the specified value, or undefined if not found.

Parameters
map:Map
 
value:Object

Returns
*
newBuilder()method 
public static function newBuilder(keyClazz:Class):MapBuilder

Create a MapBuilder for creating a more complicated Map type.

Parameters
keyClazz:Class

Returns
MapBuilder

Example
     // builds a sorted, weak-value Map.
     var myMap :Map = Maps.newBuilder(String)
         .makeSorted()
         .makeWeakValues()
         .build();
     

newMapOf()method 
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
keyClazz:Class

Returns
Map
newSortedMapOf()method 
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
Map
selectKey()method 
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
key:Object
 
value:Object

Returns
Object
selectValue()method 
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
key:Object
 
value:Object

Returns
Object
some()method 
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
Boolean