Class HashMapObjectLong<E>

  • All Implemented Interfaces:
    java.io.Serializable

    public final class HashMapObjectLong<E>
    extends java.lang.Object
    implements java.io.Serializable
    A map from Object to long. More efficient than a general map null not allowed as key.
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  HashMapObjectLong.Entry<E>
      An entry from the map
    • Constructor Summary

      Constructors 
      Constructor Description
      HashMapObjectLong()
      Create a map of default size
      HashMapObjectLong​(int initialCapacity)
      Create a map of given size
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Remove all the existing mappings, leaving the capacity unchanged.
      boolean containsKey​(E key)
      find if key is present in map
      java.util.Iterator<HashMapObjectLong.Entry<E>> entries()
      Iterate over all the map entries
      long get​(E key)
      Retrieve the value corresponding to the key
      java.lang.Object[] getAllKeys()
      Get all the used keys.
      <T> T[] getAllKeys​(T[] a)
      Get all the used keys.
      long[] getAllValues()
      Get all the values corresponding to the used keys.
      boolean isEmpty()
      Is the map empty
      java.util.Iterator<E> keys()
      Get a way of iterating over the keys
      boolean put​(E key, long value)
      Add a mapping
      boolean remove​(E key)
      Remove an mapping from the map
      int size()
      The number of mappings
      IteratorLong values()
      Get a way of iterating over the values.
      • Methods inherited from class java.lang.Object

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

      • HashMapObjectLong

        public HashMapObjectLong()
        Create a map of default size
      • HashMapObjectLong

        public HashMapObjectLong​(int initialCapacity)
        Create a map of given size
        Parameters:
        initialCapacity - the initial capacity of the HashMap
    • Method Detail

      • put

        public boolean put​(E key,
                           long value)
        Add a mapping
        Parameters:
        key - the key
        value - the corresponding value
        Returns:
        true if an entry with the key already exists
      • remove

        public boolean remove​(E key)
        Remove an mapping from the map
        Parameters:
        key - the key to remove
        Returns:
        true if entry was found
      • containsKey

        public boolean containsKey​(E key)
        find if key is present in map
        Parameters:
        key - the key
        Returns:
        true if the key was found
      • get

        public long get​(E key)
        Retrieve the value corresponding to the key
        Parameters:
        key - the key
        Returns:
        the value
        Throws:
        java.util.NoSuchElementException - if the key is not found
      • getAllKeys

        public java.lang.Object[] getAllKeys()
        Get all the used keys. Consider using getAllKeys(Object[]) for better type safety
        Returns:
        an array of the used keys
      • getAllKeys

        public <T> T[] getAllKeys​(T[] a)
        Get all the used keys.
        Type Parameters:
        T - the type of the keys
        Parameters:
        a - an array of the right type for the output, which will be used if it is big enough, otherwise another array of this type will be allocated.
        Returns:
        an array of the used keys
      • size

        public int size()
        The number of mappings
        Returns:
        the size of the map
      • isEmpty

        public boolean isEmpty()
        Is the map empty
        Returns:
        true if no current mappings
      • clear

        public void clear()
        Remove all the existing mappings, leaving the capacity unchanged.
      • keys

        public java.util.Iterator<E> keys()
        Get a way of iterating over the keys
        Returns:
        an iterator over the keys
      • values

        public IteratorLong values()
        Get a way of iterating over the values.
        Returns:
        an iterator over the values
      • entries

        public java.util.Iterator<HashMapObjectLong.Entry<E>> entries()
        Iterate over all the map entries
        Returns:
        the iterator over the entries
      • getAllValues

        public long[] getAllValues()
        Get all the values corresponding to the used keys. Duplicate values are possible if they correspond to different keys.
        Returns:
        an array of the used values