Package trclib.dataprocessor
Class TrcHashMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
trclib.dataprocessor.TrcHashMap<K,V>
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<K,
V>
This class implements the TrcHashMap. TrcHashMap extends HashMap and added the add method so you can easily
append multiple hash map entries in a single statement. It can also differentiate the case of key not found
from the case of key maps to null. In the case of key not found, instead of returning null, it throws an
exception. TrcHashMap can accommodate different types of object in the same map. So it provides methods to
get the appropriate data type from the map. It throws an exception if the type is not what you expect.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionTrcHashMap<K,
V> This method adds an entry to the hash map and returns this hashmap object so you can chain multiple calls to the add method in a single statement.This method returns the value mapped the given key and throws an exception if the key cannot be found in the hashmap.getBoolean
(Object key) This method returns the boolean value mapped the given key and throws an exception if the key cannot be found in the hashmap or if the value is not the correct type.This method returns the double value mapped the given key and throws an exception if the key cannot be found in the hashmap or if the value is not the correct type.This method returns the float value mapped the given key and throws an exception if the key cannot be found in the hashmap or if the value is not the correct type.getInteger
(Object key) This method returns the integer value mapped the given key and throws an exception if the key cannot be found in the hashmap or if the value is not the correct type.This method returns the string value mapped the given key and throws an exception if the key cannot be found in the hashmap or if the value is not the correct type.Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Constructor Details
-
TrcHashMap
public TrcHashMap()
-
-
Method Details
-
add
This method adds an entry to the hash map and returns this hashmap object so you can chain multiple calls to the add method in a single statement.- Parameters:
key
- specifies the key of the mapping.value
- specifies the value of the mappng.- Returns:
- this hashmap instance.
-
get
This method returns the value mapped the given key and throws an exception if the key cannot be found in the hashmap. -
getInteger
This method returns the integer value mapped the given key and throws an exception if the key cannot be found in the hashmap or if the value is not the correct type.- Parameters:
key
- specifies the key of the mapping to look for.- Returns:
- the integer value mapped to the key.
- Throws:
IllegalArgumentException
- if key is not in hashmap.ClassCastException
- if value is not the correct type.
-
getFloat
This method returns the float value mapped the given key and throws an exception if the key cannot be found in the hashmap or if the value is not the correct type.- Parameters:
key
- specifies the key of the mapping to look for.- Returns:
- the float value mapped to the key.
- Throws:
IllegalArgumentException
- if key is not in hashmap.ClassCastException
- if value is not the correct type.
-
getDouble
This method returns the double value mapped the given key and throws an exception if the key cannot be found in the hashmap or if the value is not the correct type.- Parameters:
key
- specifies the key of the mapping to look for.- Returns:
- the double value mapped to the key.
- Throws:
IllegalArgumentException
- if key is not in hashmap.ClassCastException
- if value is not the correct type.
-
getBoolean
This method returns the boolean value mapped the given key and throws an exception if the key cannot be found in the hashmap or if the value is not the correct type.- Parameters:
key
- specifies the key of the mapping to look for.- Returns:
- the boolean value mapped to the key.
- Throws:
IllegalArgumentException
- if key is not in hashmap.ClassCastException
- if value is not the correct type.
-
getString
This method returns the string value mapped the given key and throws an exception if the key cannot be found in the hashmap or if the value is not the correct type.- Parameters:
key
- specifies the key of the mapping to look for.- Returns:
- the string value mapped to the key.
- Throws:
IllegalArgumentException
- if key is not in hashmap.ClassCastException
- if value is not the correct type.
-