Packagecom.threerings.util.maps
Classpublic class MapBuilder

Builds Maps.


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



Public Methods
 MethodDefined by
  
MapBuilder(keyClazz:Class)
MapBuilder
  
Build the Map!
MapBuilder
  
makeComputing(computer:Function):MapBuilder
Make the map compute values for missing keys with the given function.
MapBuilder
  
makeExpiring(ttl:int, expireHandler:Function = null):MapBuilder
Make the Map auto-expire elements.
MapBuilder
  
Make the Map immutable.
MapBuilder
  
makeLR(maxSize:int, accessOrder:Boolean = true):MapBuilder
Make the Map a cache, disposing of the least-recently-accessed (or least-recently-inserted) mappings whenever size exceeds maxSize.
MapBuilder
  
makeSorted(comp:Function = null):MapBuilder
Make the Map sorted.
MapBuilder
  
Make the Map have weakly-held values.
MapBuilder
  
put(key:Object, value:Object):MapBuilder
Put a mapping into the Map, once built.
MapBuilder
  
Make the Map have a default value other than undefined.
MapBuilder
Constructor detail
MapBuilder()constructor
public function MapBuilder(keyClazz:Class)Parameters
keyClazz:Class
Method detail
build()method
public function build():Map

Build the Map!

Returns
Map
makeComputing()method 
public function makeComputing(computer:Function):MapBuilder

Make the map compute values for missing keys with the given function. If setDefaultValue is also used, the compute function will first create a value for a missing key, and if it returns undefined, then the default value will be used.

Parameters
computer:Function

Returns
MapBuilder
makeExpiring()method 
public function makeExpiring(ttl:int, expireHandler:Function = null):MapBuilder

Make the Map auto-expire elements.

Parameters
ttl:int — the time to live
 
expireHandler:Function (default = null) — function to receive notifications when a mapping expires. signature: function (key :Object, value :Object) :void;

Returns
MapBuilder — this MapBuilder, for chaining.
makeImmutable()method 
public function makeImmutable():MapBuilder

Make the Map immutable.

Returns
MapBuilder
makeLR()method 
public function makeLR(maxSize:int, accessOrder:Boolean = true):MapBuilder

Make the Map a cache, disposing of the least-recently-accessed (or least-recently-inserted) mappings whenever size exceeds maxSize. Iterating over this map (via keys(), values(), or forEach()) will visit the oldest mappings first.

Parameters
maxSize:int
 
accessOrder:Boolean (default = true)

Returns
MapBuilder — this MapBuilder, for chaining.
makeSorted()method 
public function makeSorted(comp:Function = null):MapBuilder

Make the Map sorted. If no Comparator is specified, then one is picked based on the keyClazz, falling back to Comparators.compareUnknowns.

Parameters
comp:Function (default = null)

Returns
MapBuilder — this MapBuilder, for chaining.
makeWeakValues()method 
public function makeWeakValues():MapBuilder

Make the Map have weakly-held values.

Returns
MapBuilder — this MapBuilder, for chaining.
put()method 
public function put(key:Object, value:Object):MapBuilder

Put a mapping into the Map, once built. If put is called more than once with the same key, the last value put will be contained in the Map.

Parameters
key:Object
 
value:Object

Returns
MapBuilder
setDefaultValue()method 
public function setDefaultValue(value:*):MapBuilder

Make the Map have a default value other than undefined. If makeComputing is also used, this will only be returned if the computing function returns undefined for a key.

Parameters
value:*

Returns
MapBuilder