org.jjoost.collections
Class MapMaker.HashMapMaker<K,V>

java.lang.Object
  extended by org.jjoost.collections.MapMaker<K,V>
      extended by org.jjoost.collections.MapMaker.HashMapMaker<K,V>
Enclosing class:
MapMaker<K,V>

public static class MapMaker.HashMapMaker<K,V>
extends MapMaker<K,V>

This class provides a user friendly means of constructing a variety of hash maps. Almost all hash based map options are exposed by this class.

Author:
b.elliottsmith

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jjoost.collections.MapMaker
MapMaker.HashMapMaker<K,V>
 
Constructor Summary
MapMaker.HashMapMaker()
          create a new HashMapMaker
 
Method Summary
 MapMaker.HashMapMaker<K,V> copy()
          Return a new MapMaker with the same properties as this one
 MapMaker.HashMapMaker<K,V> defaultsTo(Factory<V> factory)
          This options is only available for the construction of a regular Map.
 MapMaker.HashMapMaker<K,V> defaultsTo(Function<K,V> function)
          This options is only available for the construction of a regular Map.
 MapMaker.HashMapMaker<K,V> initialCapacity(int initialCapacity)
          Specify the minimum initial capacity a map should have on construction
 MapMaker.HashMapMaker<K,V> keyEq(Equality<? super K> eq)
          Set the key equality used by maps constructed by this MapMaker.
 MapMaker.HashMapMaker<K,V> loadFactor(float loadFactor)
          Define the load factor all maps should be constructed with.
 ListMap<K,V> newListMap(ListMapNesting<V> nesting)
          Construct and return a new ListMap with the provided nesting settings
 Map<K,V> newMap()
          Construct and return a new Map
 MultiMap<K,V> newMultiMap(MultiMapNesting<V> nesting)
          Construct and return a new MultiMap with the provided nesting settings
 MapMaker.HashMapMaker<K,V> rehasher(Rehasher rehasher)
          Set the Rehasher used by maps constructed by this MapMaker.
 MapMaker.HashMapMaker<K,V> type(HashStoreType type)
          Set the type of hash store to back the map by; this will affect performance and concurrency characteristics, primarily, but should have no impact on the basic functionality.
 MapMaker.HashMapMaker<K,V> valEq(Equality<? super V> eq)
          Set the equality used for value matching.
 
Methods inherited from class org.jjoost.collections.MapMaker
hash, newListMap, newListMapFactory, newMapFactory, newMultiMap, newMultiMapFactory
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapMaker.HashMapMaker

public MapMaker.HashMapMaker()
create a new HashMapMaker

Method Detail

rehasher

public MapMaker.HashMapMaker<K,V> rehasher(Rehasher rehasher)
Set the Rehasher used by maps constructed by this MapMaker. All hashes are passed through the rehasher before being used; it is the rehasher's job to prevent unfortunate inputs/hash functions causing the map to perform poorly. The default differs depending on the HashStoreType.

Parameters:
rehasher - rehasher
Returns:
this

keyEq

public MapMaker.HashMapMaker<K,V> keyEq(Equality<? super K> eq)
Set the key equality used by maps constructed by this MapMaker. The Equality defines both the hash and equality implementations to use instead of the default Object.hashCode() and Object.equals() methods. The default is Equalities.object() which delegates to these methods, however Equalities.identity() causes maps created by this MapMaker to behave like an IdentityHashMap (regarding key equality).

Parameters:
eq - the key Equality
Returns:
this

valEq

public MapMaker.HashMapMaker<K,V> valEq(Equality<? super V> eq)
Set the equality used for value matching. This is used less commonly than the key equality, however is still necessary. All methods that accept a value will use this Equality to determine equality of the value against those present in the map. This is particularly important for a MultiMap and ListMap with INLINE nesting, as it will be used to determine equality for the value portion of each entry, and calls to values().unique() are quite likely to construct a secondary hash map using the hash defined by this Equality. If the nesting type is NESTED then this options is ignored, as the nested set will have its own equality defined.

Parameters:
eq - the value Equality
Returns:
this

type

public MapMaker.HashMapMaker<K,V> type(HashStoreType type)
Set the type of hash store to back the map by; this will affect performance and concurrency characteristics, primarily, but should have no impact on the basic functionality.

Parameters:
type - the hash store type
Returns:
this

initialCapacity

public MapMaker.HashMapMaker<K,V> initialCapacity(int initialCapacity)
Specify the minimum initial capacity a map should have on construction

Parameters:
initialCapacity - the minimum initial capacity of the map constructed
Returns:
this

loadFactor

public MapMaker.HashMapMaker<K,V> loadFactor(float loadFactor)
Define the load factor all maps should be constructed with. This parameter is used to decide when to enlarge a hash structure, and will greatly affect both the size and speed of the map. The smaller this value (less than 1) it is, the more space the map will waste but the better it will cope with poor distribution of elements. A perfect hash would need a value of 1 to perform optimally, but since most hash functions are not perfect, a value below 1 is usually best. A value above 1 will begin to save space at the expense of extra overhead maintaining and querying the map. If the size of the map is expected to stay relatively static, with the occasional peaks and troughs, however, a high load factor may avoid expensive and unnecessary grow operations.

Parameters:
loadFactor - the load factory of the map constructed
Returns:
this

defaultsTo

public MapMaker.HashMapMaker<K,V> defaultsTo(Factory<V> factory)
This options is only available for the construction of a regular Map. If this property is set then any call to get(k) on the map where the key does not exist has the key inserted into the map with a value provided by the factory. The effect is that ensureAndGet(k, factory) is called instead of get(k)

Parameters:
factory - the factory to use to populate values against non-existent keys that are accessed via get()
Returns:
this

defaultsTo

public MapMaker.HashMapMaker<K,V> defaultsTo(Function<K,V> function)
This options is only available for the construction of a regular Map. If this property is set then any call to get(k) on the map where the key does not exist has the key inserted into the map with a value provided by the function. The effect is that ensureAndGet(k, function) is called instead of get(k)

Parameters:
function - the function to use to populate values against non-existent keys that are accessed via get()
Returns:
this

newMap

public Map<K,V> newMap()
Description copied from class: MapMaker
Construct and return a new Map

Specified by:
newMap in class MapMaker<K,V>
Returns:
a new Map

newMultiMap

public MultiMap<K,V> newMultiMap(MultiMapNesting<V> nesting)
Description copied from class: MapMaker
Construct and return a new MultiMap with the provided nesting settings

Specified by:
newMultiMap in class MapMaker<K,V>
Parameters:
nesting - nesting
Returns:
a new MultiMap with the provided nesting settings

newListMap

public ListMap<K,V> newListMap(ListMapNesting<V> nesting)
Description copied from class: MapMaker
Construct and return a new ListMap with the provided nesting settings

Specified by:
newListMap in class MapMaker<K,V>
Parameters:
nesting - nesting
Returns:
a new ListMap with the provided nesting settings

copy

public MapMaker.HashMapMaker<K,V> copy()
Description copied from class: MapMaker
Return a new MapMaker with the same properties as this one

Returns:
a copy of this MapMaker