Class LinkedMap

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public class LinkedMap
    extends java.lang.Object
    implements java.lang.Cloneable, java.io.Serializable
    A fast linked-hashmap that avoids any unneccessay work. It is slightly slower than an ordinary hashmap but faster than a combined hashmap and list-index that would be needed to get this functionality on JDK 1.2. The map is as fast as the LinkedHashMap of JDK 1.4+.
    Author:
    Thomas Morgner
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      LinkedMap()
      Default constructor.
      LinkedMap​(int initialCapacity, float loadFactor)
      Creates a new map with the given initial number of buckets and the given loadfactor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clears the map and removes all map records.
      java.lang.Object clone()
      Clones this map.
      boolean containsKey​(java.lang.Object key)
      Checks, whether the map contains an entry for the key.
      java.lang.Object get​(java.lang.Object key)
      Retrieves the object stored under the given key from the map.
      boolean isEmpty()
      Checks whether this collection is empty.
      java.lang.Object[] keys()
      Returns the keys used in this map as array.
      java.lang.Object[] keys​(java.lang.Object[] data)
      Returns the keys used in this map as array.
      java.lang.Object put​(java.lang.Object key, java.lang.Object value)
      Stores the given value in the map using the provided key.
      java.lang.Object remove​(java.lang.Object key)
      Removes the object stored under the given key from the map.
      int size()
      Returns the number of entries in the map.
      java.lang.Object[] values()
      Returns the values used in this map as array.
      java.lang.Object[] values​(java.lang.Object[] data)
      Returns the values used in this map as array.
      • Methods inherited from class java.lang.Object

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

      • LinkedMap

        public LinkedMap()
        Default constructor. Creates a map for 16 entries with a default load-factor of 0.75.
      • LinkedMap

        public LinkedMap​(int initialCapacity,
                         float loadFactor)
        Creates a new map with the given initial number of buckets and the given loadfactor. A load factor greater 1 will always cause hash-collisions, while lower loadfactors reduce the likelyhood of collisions.
        Parameters:
        initialCapacity - the initial capacity.
        loadFactor - the load factor of the bucket-array.
    • Method Detail

      • size

        public int size()
        Returns the number of entries in the map.
        Returns:
        the number of entries.
      • put

        public java.lang.Object put​(java.lang.Object key,
                                    java.lang.Object value)
        Stores the given value in the map using the provided key. Both key and value can be null.
        Parameters:
        key - the key.
        value - the value to be stored under the key.
        Returns:
        the previous value stored under this key or null of the entry is new.
      • get

        public java.lang.Object get​(java.lang.Object key)
        Retrieves the object stored under the given key from the map.
        Parameters:
        key - the key for which a value should be located.
        Returns:
        the value or null, if the map did not contain a value for the key.
      • remove

        public java.lang.Object remove​(java.lang.Object key)
        Removes the object stored under the given key from the map.
        Parameters:
        key - the key for which a value should be located.
        Returns:
        the value or null, if the map did not contain a value for the key.
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Checks, whether the map contains an entry for the key.
        Parameters:
        key - the key for which a value should be located.
        Returns:
        true if the map contains a value for the key, false otherwise.
      • keys

        public java.lang.Object[] keys​(java.lang.Object[] data)
        Returns the keys used in this map as array. The keys are returned in the insertation order.
        Parameters:
        data - the object array that should receive the keys.
        Returns:
        the array filled with the keys.
      • keys

        public java.lang.Object[] keys()
        Returns the keys used in this map as array. The keys are returned in the insertation order.
        Returns:
        the array filled with the keys.
      • values

        public java.lang.Object[] values()
        Returns the values used in this map as array. The values are returned in the insertation order.
        Returns:
        the array filled with the values.
      • values

        public java.lang.Object[] values​(java.lang.Object[] data)
        Returns the values used in this map as array. The values are returned in the insertation order.
        Parameters:
        data - the object array that should receive the values.
        Returns:
        the array filled with the values.
      • clear

        public void clear()
        Clears the map and removes all map records.
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Clones this map.
        Returns:
        the cloned map.
        Throws:
        java.lang.CloneNotSupportedException
      • isEmpty

        public boolean isEmpty()
        Checks whether this collection is empty.
        Returns:
        true, if the collection is empty, false otherwise.