java.lang.Object
org.pentaho.reporting.libraries.base.util.HashNMap
All Implemented Interfaces:
Serializable, Cloneable

public class HashNMap extends Object implements Serializable, Cloneable
The HashNMap can be used to store multiple values by a single key value. The values stored can be retrieved using a direct query or by creating an enumeration over the stored elements.
Author:
Thomas Morgner
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(Object key, Object val)
    Adds a new key/value pair into this map.
    void
    Clears all keys and values of this map.
    Creates a deep copy of this HashNMap.
    boolean
    Tests whether this map contains the given key or value.
    boolean
    Tests whether this map contains the given key.
    boolean
    Tests whether this map contains the given value.
    boolean
    Tests whether this map contains the given value.
    get(Object key, int n)
    Retrieves the n-th value registered for an key or null if there was no such key in the list.
    Returns an iterator over all elements registered to the given key.
    Retrieves the first value registered for an key or null if there was no such key in the list.
    int
    Returns the number of elements registered with the given key.
    boolean
    Checks, whether the map is empty.
    Returns all registered keys as an enumeration.
    Returns all registered keys as set.
    boolean
    put(Object key, Object val)
    Inserts a new key/value pair into the map.
    boolean
    remove(Object key, Object value)
    Removes the key/value pair from the map.
    void
    Removes all elements for the given key.
    Returns the contents for the given key as object array.
    toArray(Object key, Object[] data)
    Returns the contents for the given key as object array.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HashNMap

      public HashNMap()
      Default constructor.
  • Method Details

    • put

      public boolean put(Object key, Object val)
      Inserts a new key/value pair into the map. If such a pair already exists, it gets replaced with the given values.
      Parameters:
      key - the key.
      val - the value.
      Returns:
      A boolean.
    • add

      public boolean add(Object key, Object val)
      Adds a new key/value pair into this map. If the key is not yet in the map, it gets added to the map and the call is equal to put(Object,Object).
      Parameters:
      key - the key.
      val - the value.
      Returns:
      true, if the value has been added, false otherwise
    • getFirst

      public Object getFirst(Object key)
      Retrieves the first value registered for an key or null if there was no such key in the list.
      Parameters:
      key - the key.
      Returns:
      the value.
    • get

      public Object get(Object key, int n)
      Retrieves the n-th value registered for an key or null if there was no such key in the list. An index out of bounds exception is thrown if there are less than n elements registered to this key.
      Parameters:
      key - the key.
      n - the index.
      Returns:
      the object.
    • getAll

      public Iterator getAll(Object key)
      Returns an iterator over all elements registered to the given key.
      Parameters:
      key - the key.
      Returns:
      an iterator.
    • keys

      public Iterator keys()
      Returns all registered keys as an enumeration.
      Returns:
      an enumeration of the keys.
    • keySet

      public Set keySet()
      Returns all registered keys as set.
      Returns:
      a set of keys.
    • remove

      public boolean remove(Object key, Object value)
      Removes the key/value pair from the map. If the removed entry was the last entry for this key, the key gets also removed.
      Parameters:
      key - the key.
      value - the value.
      Returns:
      true, if removing the element was successfull, false otherwise.
    • removeAll

      public void removeAll(Object key)
      Removes all elements for the given key.
      Parameters:
      key - the key.
    • clear

      public void clear()
      Clears all keys and values of this map.
    • containsKey

      public boolean containsKey(Object key)
      Tests whether this map contains the given key.
      Parameters:
      key - the key.
      Returns:
      true if the key is contained in the map
    • containsValue

      public boolean containsValue(Object value)
      Tests whether this map contains the given value.
      Parameters:
      value - the value.
      Returns:
      true if the value is registered in the map for an key.
    • containsValue

      public boolean containsValue(Object key, Object value)
      Tests whether this map contains the given value.
      Parameters:
      key - the key under which to find the value
      value - the value.
      Returns:
      true if the value is registered in the map for an key.
    • contains

      public boolean contains(Object value)
      Tests whether this map contains the given key or value.
      Parameters:
      value - the value.
      Returns:
      true if the key or value is contained in the map
    • clone

      public Object clone() throws CloneNotSupportedException
      Creates a deep copy of this HashNMap.
      Returns:
      a clone.
      Throws:
      CloneNotSupportedException - this should never happen.
    • toArray

      public Object[] toArray(Object key, Object[] data)
      Returns the contents for the given key as object array. If there were no objects registered with that key, an empty object array is returned.
      Parameters:
      key - the key.
      data - the object array to receive the contents.
      Returns:
      the contents.
    • toArray

      public Object[] toArray(Object key)
      Returns the contents for the given key as object array. If there were no objects registered with that key, an empty object array is returned.
      Parameters:
      key - the key.
      Returns:
      the contents.
    • getValueCount

      public int getValueCount(Object key)
      Returns the number of elements registered with the given key.
      Parameters:
      key - the key.
      Returns:
      the number of element for this key, or 0 if there are no elements registered.
    • isEmpty

      public boolean isEmpty()
      Checks, whether the map is empty.
      Returns:
      true, if the map does not contain any keys.