org.flexdock.util
Class TypedHashtable

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable
          extended by org.flexdock.util.TypedHashtable
All Implemented Interfaces:
Serializable, Cloneable, Map
Direct Known Subclasses:
BasicDockablePropertySet, BasicDockingPortPropertySet

public class TypedHashtable
extends Hashtable

Author:
Christopher Butler
See Also:
Serialized Form

Constructor Summary
TypedHashtable()
          Constructs a new, empty TypedHashtable with a default initial capacity (11) and load factor of 0.75.
TypedHashtable(int initialCapacity)
          Constructs a new, empty TypedHashtable with the specified initial capacity and default load factor of 0.75.
TypedHashtable(int initialCapacity, float loadFactor)
          Constructs a new, empty TypedHashtable with the specified initial capacity and the specified load factor.
TypedHashtable(Map t)
          Constructs a new TypedHashtable with the same mappings as the given Map.
 
Method Summary
 boolean get(Object key, boolean defaultValue)
          Returns the boolean value associated with the specified key in this hashtable.
 byte get(Object key, byte defaultValue)
          Returns the byte value associated with the specified key in this hashtable.
 char get(Object key, char defaultValue)
          Returns the char value associated with the specified key in this hashtable.
 double get(Object key, double defaultValue)
          Returns the double value associated with the specified key in this hashtable.
 float get(Object key, float defaultValue)
          Returns the float value associated with the specified key in this hashtable.
 int get(Object key, int defaultValue)
          Returns the int value associated with the specified key in this hashtable.
 long get(Object key, long defaultValue)
          Returns the long value associated with the specified key in this hashtable.
 short get(Object key, short defaultValue)
          Returns the short value associated with the specified key in this hashtable.
 Boolean getBoolean(Object key)
          Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.Boolean before returning.
 Byte getByte(Object key)
          Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.Byte before returning.
 Character getChar(Object key)
          Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.Character before returning.
 Double getDouble(Object key)
          Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.Double before returning.
 Float getFloat(Object key)
          Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.Float before returning.
 Integer getInt(Object key)
          Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.Integer before returning.
 Long getLong(Object key)
          Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.Long before returning.
 Short getShort(Object key)
          Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.Short before returning.
 String getString(Object key)
          Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.String before returning.
 void put(Object key, boolean value)
          Maps the specified key to the specified boolean value in this hashtable.
 void put(Object key, byte value)
          Maps the specified key to the specified byte value in this hashtable.
 void put(Object key, char value)
          Maps the specified key to the specified char value in this hashtable.
 void put(Object key, double value)
          Maps the specified key to the specified double value in this hashtable.
 void put(Object key, float value)
          Maps the specified key to the specified float value in this hashtable.
 void put(Object key, int value)
          Maps the specified key to the specified int value in this hashtable.
 void put(Object key, long value)
          Maps the specified key to the specified long value in this hashtable.
 Object put(Object key, Object value)
          Maps the specified key to the specified value in this hashtable.
 void put(Object key, short value)
          Maps the specified key to the specified short value in this hashtable.
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TypedHashtable

public TypedHashtable()
Constructs a new, empty TypedHashtable with a default initial capacity (11) and load factor of 0.75.


TypedHashtable

public TypedHashtable(int initialCapacity)
Constructs a new, empty TypedHashtable with the specified initial capacity and default load factor of 0.75.

Parameters:
initialCapacity - the initial capacity of the hashtable.
Throws:
IllegalArgumentException - if the initial capacity is less than zero.

TypedHashtable

public TypedHashtable(int initialCapacity,
                      float loadFactor)
Constructs a new, empty TypedHashtable with the specified initial capacity and the specified load factor.

Parameters:
initialCapacity - the initial capacity of the hashtable.
loadFactor - the load factor of the hashtable.
Throws:
IllegalArgumentException - if the initial capacity is less than zero, or if the load factor is nonpositive.

TypedHashtable

public TypedHashtable(Map t)
Constructs a new TypedHashtable with the same mappings as the given Map. The hashtable is created with an initial capacity sufficient to hold the mappings in the given Map and a default load factor of 0.75.

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

put

public void put(Object key,
                boolean value)
Maps the specified key to the specified boolean value in this hashtable. Since hashtables require Object values, this method will put either Boolean.TRUE or Boolean.FALSE in the hashtable. If key is null then this method returns with no action taken.

Parameters:
key - the hashtable key.
value - the boolean value to be mapped to the specified key.
See Also:
Boolean.TRUE, Boolean.FALSE, put(Object, Object)

put

public void put(Object key,
                byte value)
Maps the specified key to the specified byte value in this hashtable. Since hashtables require Object values, this method will wrap the specified byte in a java.lang.Byte before inserting. If key is null then this method returns with no action taken.

Parameters:
key - the hashtable key.
value - the byte value to be mapped to the specified key.
See Also:
Byte.Byte(byte), put(Object, Object)

put

public void put(Object key,
                short value)
Maps the specified key to the specified short value in this hashtable. Since hashtables require Object values, this method will wrap the specified short in a java.lang.Short before inserting. If key is null then this method returns with no action taken.

Parameters:
key - the hashtable key.
value - the short value to be mapped to the specified key.
See Also:
Short.Short(short), put(Object, Object)

put

public void put(Object key,
                int value)
Maps the specified key to the specified int value in this hashtable. Since hashtables require Object values, this method will wrap the specified int in a java.lang.Integer before inserting. If key is null then this method returns with no action taken.

Parameters:
key - the hashtable key.
value - the int value to be mapped to the specified key.
See Also:
Integer.Integer(int), put(Object, Object)

put

public void put(Object key,
                long value)
Maps the specified key to the specified long value in this hashtable. Since hashtables require Object values, this method will wrap the specified long in a java.lang.Long before inserting. If key is null then this method returns with no action taken.

Parameters:
key - the hashtable key.
value - the long value to be mapped to the specified key.
See Also:
Long.Long(long), put(Object, Object)

put

public void put(Object key,
                float value)
Maps the specified key to the specified float value in this hashtable. Since hashtables require Object values, this method will wrap the specified float in a java.lang.Float before inserting. If key is null then this method returns with no action taken.

Parameters:
key - the hashtable key.
value - the float value to be mapped to the specified key.
See Also:
Float.Float(float), put(Object, Object)

put

public void put(Object key,
                double value)
Maps the specified key to the specified double value in this hashtable. Since hashtables require Object values, this method will wrap the specified double in a java.lang.Double before inserting. If key is null then this method returns with no action taken.

Parameters:
key - the hashtable key.
value - the double value to be mapped to the specified key.
See Also:
Double.Double(double), put(Object, Object)

put

public void put(Object key,
                char value)
Maps the specified key to the specified char value in this hashtable. Since hashtables require Object values, this method will wrap the specified char in a java.lang.Character before inserting. If key is null then this method returns with no action taken.

Parameters:
key - the hashtable key.
value - the char value to be mapped to the specified key.
See Also:
Character.Character(char), put(Object, Object)

put

public Object put(Object key,
                  Object value)
Maps the specified key to the specified value in this hashtable. If the key is null, then this method returns with no action taken. If the value is null, then this method removes any existing mapping in the hashtable for the specified key by calling remove(Object key). The value can be retrieved by calling the get(Object key) method with a key that is equal to the original key.

Specified by:
put in interface Map
Overrides:
put in class Hashtable
Parameters:
key - the hashtable key.
value - the value.
See Also:
Object.equals(Object), Hashtable.get(Object), Hashtable.remove(java.lang.Object)

get

public boolean get(Object key,
                   boolean defaultValue)
Returns the boolean value associated with the specified key in this hashtable. This method attempts to cast the value in this hashtable for the specified key to a java.lang.Boolean and invoke its booleanValue() method. If the key does not exist in the hashtable, or it maps to a non-Boolean value, then this method returns the specified defaultValue.

Parameters:
key - the hashtable key
defaultValue - the value to return if a valid boolean cannot be found for the specified key
Returns:
the boolean value associated with the specified key in this hashtable.
See Also:
put(Object, boolean), getBoolean(Object), Boolean.booleanValue()

get

public byte get(Object key,
                byte defaultValue)
Returns the byte value associated with the specified key in this hashtable. This method attempts to cast the value in this hashtable for the specified key to a java.lang.Byte and invoke its byteValue() method. If the key does not exist in the hashtable, or it maps to a non-Byte value, then this method returns the specified defaultValue.

Parameters:
key - the hashtable key
defaultValue - the value to return if a valid byte cannot be found for the specified key
Returns:
the byte value associated with the specified key in this hashtable.
See Also:
put(Object, byte), getByte(Object), Byte.byteValue()

get

public short get(Object key,
                 short defaultValue)
Returns the short value associated with the specified key in this hashtable. This method attempts to cast the value in this hashtable for the specified key to a java.lang.Short and invoke its shortValue() method. If the key does not exist in the hashtable, or it maps to a non-Short value, then this method returns the specified defaultValue.

Parameters:
key - the hashtable key
defaultValue - the value to return if a valid short cannot be found for the specified key
Returns:
the short value associated with the specified key in this hashtable.
See Also:
put(Object, short), getShort(Object), Short.shortValue()

get

public int get(Object key,
               int defaultValue)
Returns the int value associated with the specified key in this hashtable. This method attempts to cast the value in this hashtable for the specified key to a java.lang.Integer and invoke its intValue() method. If the key does not exist in the hashtable, or it maps to a non-Integer value, then this method returns the specified defaultValue.

Parameters:
key - the hashtable key
defaultValue - the value to return if a valid int cannot be found for the specified key
Returns:
the int value associated with the specified key in this hashtable.
See Also:
put(Object, int), getInt(Object), Integer.intValue()

get

public long get(Object key,
                long defaultValue)
Returns the long value associated with the specified key in this hashtable. This method attempts to cast the value in this hashtable for the specified key to a java.lang.Long and invoke its longValue() method. If the key does not exist in the hashtable, or it maps to a non-Long value, then this method returns the specified defaultValue.

Parameters:
key - the hashtable key
defaultValue - the value to return if a valid long cannot be found for the specified key
Returns:
the long value associated with the specified key in this hashtable.
See Also:
put(Object, long), getLong(Object), Long.longValue()

get

public float get(Object key,
                 float defaultValue)
Returns the float value associated with the specified key in this hashtable. This method attempts to cast the value in this hashtable for the specified key to a java.lang.Float and invoke its floatValue() method. If the key does not exist in the hashtable, or it maps to a non-Float value, then this method returns the specified defaultValue.

Parameters:
key - the hashtable key
defaultValue - the value to return if a valid float cannot be found for the specified key
Returns:
the float value associated with the specified key in this hashtable.
See Also:
put(Object, float), getFloat(Object), Float.floatValue()

get

public double get(Object key,
                  double defaultValue)
Returns the double value associated with the specified key in this hashtable. This method attempts to cast the value in this hashtable for the specified key to a java.lang.Double and invoke its doubleValue() method. If the key does not exist in the hashtable, or it maps to a non-Double value, then this method returns the specified defaultValue.

Parameters:
key - the hashtable key
defaultValue - the value to return if a valid double cannot be found for the specified key
Returns:
the double value associated with the specified key in this hashtable.
See Also:
put(Object, double), getDouble(Object), Double.doubleValue()

get

public char get(Object key,
                char defaultValue)
Returns the char value associated with the specified key in this hashtable. This method attempts to cast the value in this hashtable for the specified key to a java.lang.Character and invoke its charValue() method. If the key does not exist in the hashtable, or it maps to a non-Character value, then this method returns the specified defaultValue.

Parameters:
key - the hashtable key
defaultValue - the value to return if a valid char cannot be found for the specified key
Returns:
the char value associated with the specified key in this hashtable.
See Also:
put(Object, char), getChar(Object), Character.charValue()

getString

public String getString(Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.String before returning. If the specified key maps to an object type other than a String value, then this method throws a ClassCastException.

Parameters:
key - a key in the hashtable.
Returns:
the String value to which the key is mapped in this hashtable; null if the key is not mapped to any value in this hashtable.
Throws:
NullPointerException - if the key is null.
ClassCastException - if the returns value is not a String
See Also:
put(Object, Object)

getBoolean

public Boolean getBoolean(Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.Boolean before returning. If the specified key maps to an object type other than a Boolean value, then this method throws a ClassCastException.

Parameters:
key - a key in the hashtable.
Returns:
the Boolean value to which the key is mapped in this hashtable; null if the key is not mapped to any value in this hashtable.
Throws:
NullPointerException - if the key is null.
ClassCastException - if the returns value is not a Boolean
See Also:
put(Object, Object)

getByte

public Byte getByte(Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.Byte before returning. If the specified key maps to an object type other than a Byte value, then this method throws a ClassCastException.

Parameters:
key - a key in the hashtable.
Returns:
the Byte value to which the key is mapped in this hashtable; null if the key is not mapped to any value in this hashtable.
Throws:
NullPointerException - if the key is null.
ClassCastException - if the returns value is not a Byte
See Also:
put(Object, Object)

getShort

public Short getShort(Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.Short before returning. If the specified key maps to an object type other than a Short value, then this method throws a ClassCastException.

Parameters:
key - a key in the hashtable.
Returns:
the Short value to which the key is mapped in this hashtable; null if the key is not mapped to any value in this hashtable.
Throws:
NullPointerException - if the key is null.
ClassCastException - if the returns value is not a Short
See Also:
put(Object, Object)

getInt

public Integer getInt(Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.Integer before returning. If the specified key maps to an object type other than a Integer value, then this method throws a ClassCastException.

Parameters:
key - a key in the hashtable.
Returns:
the Integer value to which the key is mapped in this hashtable; null if the key is not mapped to any value in this hashtable.
Throws:
NullPointerException - if the key is null.
ClassCastException - if the returns value is not a Integer
See Also:
put(Object, Object)

getLong

public Long getLong(Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.Long before returning. If the specified key maps to an object type other than a Long value, then this method throws a ClassCastException.

Parameters:
key - a key in the hashtable.
Returns:
the Long value to which the key is mapped in this hashtable; null if the key is not mapped to any value in this hashtable.
Throws:
NullPointerException - if the key is null.
ClassCastException - if the returns value is not a Long
See Also:
put(Object, Object)

getFloat

public Float getFloat(Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.Float before returning. If the specified key maps to an object type other than a Float value, then this method throws a ClassCastException.

Parameters:
key - a key in the hashtable.
Returns:
the Float value to which the key is mapped in this hashtable; null if the key is not mapped to any value in this hashtable.
Throws:
NullPointerException - if the key is null.
ClassCastException - if the returns value is not a Float
See Also:
put(Object, Object)

getDouble

public Double getDouble(Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.Double before returning. If the specified key maps to an object type other than a Double value, then this method throws a ClassCastException.

Parameters:
key - a key in the hashtable.
Returns:
the Double value to which the key is mapped in this hashtable; null if the key is not mapped to any value in this hashtable.
Throws:
NullPointerException - if the key is null.
ClassCastException - if the returns value is not a Double
See Also:
put(Object, Object)

getChar

public Character getChar(Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to a java.lang.Character before returning. If the specified key maps to an object type other than a Character value, then this method throws a ClassCastException.

Parameters:
key - a key in the hashtable.
Returns:
the Character value to which the key is mapped in this hashtable; null if the key is not mapped to any value in this hashtable.
Throws:
NullPointerException - if the key is null.
ClassCastException - if the returns value is not a Character
See Also:
put(Object, Object)