net.acomputerdog.BlazeLoader.util.java
Class DefaultValueHashMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by net.acomputerdog.BlazeLoader.util.java.DefaultValueHashMap<K,V>
Type Parameters:
K - The key type
V - The value type
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<K,V>

public class DefaultValueHashMap<K,V>
extends java.util.HashMap<K,V>

A HashMap with the added method public V get(K key, V def) that allows the user to specify a default value to return if key is not defined.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
DefaultValueHashMap()
          Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75).
DefaultValueHashMap(int initialCapacity)
          Constructs an empty HashMap with the specified initial capacity and the default load factor (0.75).
DefaultValueHashMap(int initialCapacity, float loadFactor)
          Constructs an empty HashMap with the specified initial capacity and load factor.
DefaultValueHashMap(java.util.Map<? extends K,? extends V> m)
          Constructs a new HashMap with the same mappings as the specified Map.
 
Method Summary
 V get(K key, V def)
          Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

DefaultValueHashMap

public DefaultValueHashMap(int initialCapacity,
                           float loadFactor)
Constructs an empty HashMap with the specified initial capacity and load factor.

Parameters:
initialCapacity - the initial capacity
loadFactor - the load factor
Throws:
java.lang.IllegalArgumentException - if the initial capacity is negative or the load factor is nonpositive

DefaultValueHashMap

public DefaultValueHashMap()
Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75).


DefaultValueHashMap

public DefaultValueHashMap(int initialCapacity)
Constructs an empty HashMap with the specified initial capacity and the default load factor (0.75).

Parameters:
initialCapacity - the initial capacity.
Throws:
java.lang.IllegalArgumentException - if the initial capacity is negative.

DefaultValueHashMap

public DefaultValueHashMap(java.util.Map<? extends K,? extends V> m)
Constructs a new HashMap with the same mappings as the specified Map. The HashMap is created with default load factor (0.75) and an initial capacity sufficient to hold the mappings in the specified Map.

Parameters:
m - the map whose mappings are to be placed in this map
Throws:
java.lang.NullPointerException - if the specified map is null
Method Detail

get

public V get(K key,
             V def)
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that (key==null ? k==null : key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Parameters:
key - The key to get the value for
def - The default value to return if key is not defined.
See Also:
HashMap.put(Object, Object)