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>

public class TrcHashMap<K,V> extends HashMap<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:
  • Constructor Details

    • TrcHashMap

      public TrcHashMap()
  • Method Details

    • add

      public TrcHashMap<K,V> add(K key, V value)
      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

      public V get(Object key)
      This method returns the value mapped the given key and throws an exception if the key cannot be found in the hashmap.
      Specified by:
      get in interface Map<K,V>
      Overrides:
      get in class HashMap<K,V>
      Parameters:
      key - specifies the key of the mapping to look for.
      Returns:
      the value mapped to the key.
      Throws:
      NoSuchElementException - if key is not in hashmap.
    • getInteger

      public Integer 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.
      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

      public Float getFloat(Object key)
      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

      public Double getDouble(Object key)
      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

      public Boolean 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.
      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

      public String getString(Object key)
      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.