Package org.flexdock.util
Class TypedHashtable
- java.lang.Object
-
- java.util.Dictionary<K,V>
-
- java.util.Hashtable
-
- org.flexdock.util.TypedHashtable
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map
- Direct Known Subclasses:
BasicDockablePropertySet
,BasicDockingPortPropertySet
public class TypedHashtable extends java.util.Hashtable
- Author:
- Christopher Butler
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description TypedHashtable()
Constructs a new, emptyTypedHashtable
with a default initial capacity (11) and load factor of0.75
.TypedHashtable(int initialCapacity)
Constructs a new, emptyTypedHashtable
with the specified initial capacity and default load factor of0.75
.TypedHashtable(int initialCapacity, float loadFactor)
Constructs a new, emptyTypedHashtable
with the specified initial capacity and the specified load factor.TypedHashtable(java.util.Map t)
Constructs a newTypedHashtable
with the same mappings as the given Map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
get(java.lang.Object key, boolean defaultValue)
Returns the boolean value associated with the specifiedkey
in this hashtable.byte
get(java.lang.Object key, byte defaultValue)
Returns the byte value associated with the specifiedkey
in this hashtable.char
get(java.lang.Object key, char defaultValue)
Returns the char value associated with the specifiedkey
in this hashtable.double
get(java.lang.Object key, double defaultValue)
Returns the double value associated with the specifiedkey
in this hashtable.float
get(java.lang.Object key, float defaultValue)
Returns the float value associated with the specifiedkey
in this hashtable.int
get(java.lang.Object key, int defaultValue)
Returns the int value associated with the specifiedkey
in this hashtable.long
get(java.lang.Object key, long defaultValue)
Returns the long value associated with the specifiedkey
in this hashtable.short
get(java.lang.Object key, short defaultValue)
Returns the short value associated with the specifiedkey
in this hashtable.java.lang.Boolean
getBoolean(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.Boolean
before returning.java.lang.Byte
getByte(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.Byte
before returning.java.lang.Character
getChar(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.Character
before returning.java.lang.Double
getDouble(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.Double
before returning.java.lang.Float
getFloat(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.Float
before returning.java.lang.Integer
getInt(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.Integer
before returning.java.lang.Long
getLong(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.Long
before returning.java.lang.Short
getShort(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.Short
before returning.java.lang.String
getString(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.String
before returning.void
put(java.lang.Object key, boolean value)
Maps the specifiedkey
to the specified booleanvalue
in this hashtable.void
put(java.lang.Object key, byte value)
Maps the specifiedkey
to the specified bytevalue
in this hashtable.void
put(java.lang.Object key, char value)
Maps the specifiedkey
to the specified charvalue
in this hashtable.void
put(java.lang.Object key, double value)
Maps the specifiedkey
to the specified doublevalue
in this hashtable.void
put(java.lang.Object key, float value)
Maps the specifiedkey
to the specified floatvalue
in this hashtable.void
put(java.lang.Object key, int value)
Maps the specifiedkey
to the specified intvalue
in this hashtable.void
put(java.lang.Object key, long value)
Maps the specifiedkey
to the specified longvalue
in this hashtable.void
put(java.lang.Object key, short value)
Maps the specifiedkey
to the specified shortvalue
in this hashtable.java.lang.Object
put(java.lang.Object key, java.lang.Object value)
Maps the specifiedkey
to the specifiedvalue
in this hashtable.-
Methods inherited from class java.util.Hashtable
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keys, keySet, merge, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, size, toString, values
-
-
-
-
Constructor Detail
-
TypedHashtable
public TypedHashtable()
Constructs a new, emptyTypedHashtable
with a default initial capacity (11) and load factor of0.75
.
-
TypedHashtable
public TypedHashtable(int initialCapacity)
Constructs a new, emptyTypedHashtable
with the specified initial capacity and default load factor of0.75
.- Parameters:
initialCapacity
- the initial capacity of the hashtable.- Throws:
java.lang.IllegalArgumentException
- if the initial capacity is less than zero.
-
TypedHashtable
public TypedHashtable(int initialCapacity, float loadFactor)
Constructs a new, emptyTypedHashtable
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:
java.lang.IllegalArgumentException
- if the initial capacity is less than zero, or if the load factor is nonpositive.
-
TypedHashtable
public TypedHashtable(java.util.Map t)
Constructs a newTypedHashtable
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 of0.75
.- Parameters:
t
- the map whose mappings are to be placed in this map.- Throws:
java.lang.NullPointerException
- if the specified map is null.
-
-
Method Detail
-
put
public void put(java.lang.Object key, boolean value)
Maps the specifiedkey
to the specified booleanvalue
in this hashtable. Since hashtables requireObject
values, this method will put eitherBoolean.TRUE
orBoolean.FALSE
in the hashtable. Ifkey
isnull
then this method returns with no action taken.- Parameters:
key
- the hashtable key.value
- the boolean value to be mapped to the specifiedkey
.- See Also:
Boolean.TRUE
,Boolean.FALSE
,put(Object, Object)
-
put
public void put(java.lang.Object key, byte value)
Maps the specifiedkey
to the specified bytevalue
in this hashtable. Since hashtables requireObject
values, this method will wrap the specified byte in ajava.lang.Byte
before inserting. Ifkey
isnull
then this method returns with no action taken.- Parameters:
key
- the hashtable key.value
- the byte value to be mapped to the specifiedkey
.- See Also:
Byte(byte)
,put(Object, Object)
-
put
public void put(java.lang.Object key, short value)
Maps the specifiedkey
to the specified shortvalue
in this hashtable. Since hashtables requireObject
values, this method will wrap the specified short in ajava.lang.Short
before inserting. Ifkey
isnull
then this method returns with no action taken.- Parameters:
key
- the hashtable key.value
- the short value to be mapped to the specifiedkey
.- See Also:
Short(short)
,put(Object, Object)
-
put
public void put(java.lang.Object key, int value)
Maps the specifiedkey
to the specified intvalue
in this hashtable. Since hashtables requireObject
values, this method will wrap the specified int in ajava.lang.Integer
before inserting. Ifkey
isnull
then this method returns with no action taken.- Parameters:
key
- the hashtable key.value
- the int value to be mapped to the specifiedkey
.- See Also:
Integer(int)
,put(Object, Object)
-
put
public void put(java.lang.Object key, long value)
Maps the specifiedkey
to the specified longvalue
in this hashtable. Since hashtables requireObject
values, this method will wrap the specified long in ajava.lang.Long
before inserting. Ifkey
isnull
then this method returns with no action taken.- Parameters:
key
- the hashtable key.value
- the long value to be mapped to the specifiedkey
.- See Also:
Long(long)
,put(Object, Object)
-
put
public void put(java.lang.Object key, float value)
Maps the specifiedkey
to the specified floatvalue
in this hashtable. Since hashtables requireObject
values, this method will wrap the specified float in ajava.lang.Float
before inserting. Ifkey
isnull
then this method returns with no action taken.- Parameters:
key
- the hashtable key.value
- the float value to be mapped to the specifiedkey
.- See Also:
Float(float)
,put(Object, Object)
-
put
public void put(java.lang.Object key, double value)
Maps the specifiedkey
to the specified doublevalue
in this hashtable. Since hashtables requireObject
values, this method will wrap the specified double in ajava.lang.Double
before inserting. Ifkey
isnull
then this method returns with no action taken.- Parameters:
key
- the hashtable key.value
- the double value to be mapped to the specifiedkey
.- See Also:
Double(double)
,put(Object, Object)
-
put
public void put(java.lang.Object key, char value)
Maps the specifiedkey
to the specified charvalue
in this hashtable. Since hashtables requireObject
values, this method will wrap the specified char in ajava.lang.Character
before inserting. Ifkey
isnull
then this method returns with no action taken.- Parameters:
key
- the hashtable key.value
- the char value to be mapped to the specifiedkey
.- See Also:
Character(char)
,put(Object, Object)
-
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
Maps the specifiedkey
to the specifiedvalue
in this hashtable. If thekey
isnull
, then this method returns with no action taken. If thevalue
isnull
, then this method removes any existing mapping in the hashtable for the specifiedkey
by callingremove(Object key)
. The value can be retrieved by calling theget(Object key)
method with a key that is equal to the original key.- Specified by:
put
in interfacejava.util.Map
- Overrides:
put
in classjava.util.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(java.lang.Object key, boolean defaultValue)
Returns the boolean value associated with the specifiedkey
in this hashtable. This method attempts to cast the value in this hashtable for the specifiedkey
to ajava.lang.Boolean
and invoke itsbooleanValue()
method. If the key does not exist in the hashtable, or it maps to a non-Boolean
value, then this method returns the specifieddefaultValue
.- Parameters:
key
- the hashtable keydefaultValue
- 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(java.lang.Object key, byte defaultValue)
Returns the byte value associated with the specifiedkey
in this hashtable. This method attempts to cast the value in this hashtable for the specifiedkey
to ajava.lang.Byte
and invoke itsbyteValue()
method. If the key does not exist in the hashtable, or it maps to a non-Byte
value, then this method returns the specifieddefaultValue
.- Parameters:
key
- the hashtable keydefaultValue
- 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(java.lang.Object key, short defaultValue)
Returns the short value associated with the specifiedkey
in this hashtable. This method attempts to cast the value in this hashtable for the specifiedkey
to ajava.lang.Short
and invoke itsshortValue()
method. If the key does not exist in the hashtable, or it maps to a non-Short
value, then this method returns the specifieddefaultValue
.- Parameters:
key
- the hashtable keydefaultValue
- 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(java.lang.Object key, int defaultValue)
Returns the int value associated with the specifiedkey
in this hashtable. This method attempts to cast the value in this hashtable for the specifiedkey
to ajava.lang.Integer
and invoke itsintValue()
method. If the key does not exist in the hashtable, or it maps to a non-Integer
value, then this method returns the specifieddefaultValue
.- Parameters:
key
- the hashtable keydefaultValue
- 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(java.lang.Object key, long defaultValue)
Returns the long value associated with the specifiedkey
in this hashtable. This method attempts to cast the value in this hashtable for the specifiedkey
to ajava.lang.Long
and invoke itslongValue()
method. If the key does not exist in the hashtable, or it maps to a non-Long
value, then this method returns the specifieddefaultValue
.- Parameters:
key
- the hashtable keydefaultValue
- 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(java.lang.Object key, float defaultValue)
Returns the float value associated with the specifiedkey
in this hashtable. This method attempts to cast the value in this hashtable for the specifiedkey
to ajava.lang.Float
and invoke itsfloatValue()
method. If the key does not exist in the hashtable, or it maps to a non-Float
value, then this method returns the specifieddefaultValue
.- Parameters:
key
- the hashtable keydefaultValue
- 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(java.lang.Object key, double defaultValue)
Returns the double value associated with the specifiedkey
in this hashtable. This method attempts to cast the value in this hashtable for the specifiedkey
to ajava.lang.Double
and invoke itsdoubleValue()
method. If the key does not exist in the hashtable, or it maps to a non-Double
value, then this method returns the specifieddefaultValue
.- Parameters:
key
- the hashtable keydefaultValue
- 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(java.lang.Object key, char defaultValue)
Returns the char value associated with the specifiedkey
in this hashtable. This method attempts to cast the value in this hashtable for the specifiedkey
to ajava.lang.Character
and invoke itscharValue()
method. If the key does not exist in the hashtable, or it maps to a non-Character
value, then this method returns the specifieddefaultValue
.- Parameters:
key
- the hashtable keydefaultValue
- 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 java.lang.String getString(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.String
before returning. If the specifiedkey
maps to an object type other than aString
value, then this method throws aClassCastException
.- 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:
java.lang.NullPointerException
- if the key isnull
.java.lang.ClassCastException
- if the returns value is not aString
- See Also:
put(Object, Object)
-
getBoolean
public java.lang.Boolean getBoolean(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.Boolean
before returning. If the specifiedkey
maps to an object type other than aBoolean
value, then this method throws aClassCastException
.- 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:
java.lang.NullPointerException
- if the key isnull
.java.lang.ClassCastException
- if the returns value is not aBoolean
- See Also:
put(Object, Object)
-
getByte
public java.lang.Byte getByte(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.Byte
before returning. If the specifiedkey
maps to an object type other than aByte
value, then this method throws aClassCastException
.- 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:
java.lang.NullPointerException
- if the key isnull
.java.lang.ClassCastException
- if the returns value is not aByte
- See Also:
put(Object, Object)
-
getShort
public java.lang.Short getShort(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.Short
before returning. If the specifiedkey
maps to an object type other than aShort
value, then this method throws aClassCastException
.- 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:
java.lang.NullPointerException
- if the key isnull
.java.lang.ClassCastException
- if the returns value is not aShort
- See Also:
put(Object, Object)
-
getInt
public java.lang.Integer getInt(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.Integer
before returning. If the specifiedkey
maps to an object type other than aInteger
value, then this method throws aClassCastException
.- 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:
java.lang.NullPointerException
- if the key isnull
.java.lang.ClassCastException
- if the returns value is not aInteger
- See Also:
put(Object, Object)
-
getLong
public java.lang.Long getLong(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.Long
before returning. If the specifiedkey
maps to an object type other than aLong
value, then this method throws aClassCastException
.- 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:
java.lang.NullPointerException
- if the key isnull
.java.lang.ClassCastException
- if the returns value is not aLong
- See Also:
put(Object, Object)
-
getFloat
public java.lang.Float getFloat(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.Float
before returning. If the specifiedkey
maps to an object type other than aFloat
value, then this method throws aClassCastException
.- 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:
java.lang.NullPointerException
- if the key isnull
.java.lang.ClassCastException
- if the returns value is not aFloat
- See Also:
put(Object, Object)
-
getDouble
public java.lang.Double getDouble(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.Double
before returning. If the specifiedkey
maps to an object type other than aDouble
value, then this method throws aClassCastException
.- 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:
java.lang.NullPointerException
- if the key isnull
.java.lang.ClassCastException
- if the returns value is not aDouble
- See Also:
put(Object, Object)
-
getChar
public java.lang.Character getChar(java.lang.Object key)
Retrieves the value to which the specified key is mapped in this hashtable and casts to ajava.lang.Character
before returning. If the specifiedkey
maps to an object type other than aCharacter
value, then this method throws aClassCastException
.- 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:
java.lang.NullPointerException
- if the key isnull
.java.lang.ClassCastException
- if the returns value is not aCharacter
- See Also:
put(Object, Object)
-
-