Class CustomHashtable<V>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,​V>

    public class CustomHashtable<V>
    extends java.util.Hashtable<java.lang.String,​V>
    CustomHashtable extends the Hashtable class and adds some methods for generating keys for new elements to the Hashtable. This is designed for storing the active images, but can also be used for image frames or any other list that needs to enforce unique keys.
    Version:
    0.1 November 16, 2001
    Author:
    Lynne M. Pusanik
    See Also:
    Hashtable, Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static long serialVersionUID
      Use serialVersionUID for interoperability.
    • Constructor Summary

      Constructors 
      Constructor Description
      CustomHashtable()
      Constructs a new, empty hashtable with a default capacity and load factor, which is 0.75.
      CustomHashtable​(int capacity)
      Constructs a new, empty hashtable with the specified initial capacity and default load factor, which is 0.75.
      CustomHashtable​(int capacity, float loadFactor)
      Constructs a new, empty hashtable with the specified initial capacity and the specified load factor.
      CustomHashtable​(java.util.Map<java.lang.String,​V> t)
      Constructs a new hashtable with the same mappings as the given Map.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.lang.String appendKey​(java.lang.String key)
      Starts with a key that already exists in the hashtable and appends integers to its toString().
      java.lang.String makeUniqueKey​(java.lang.String key)
      Returns a unique key string for the hashtable based on a given key string.
      • Methods inherited from class java.util.Hashtable

        clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keys, keySet, merge, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, size, toString, values
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        Use serialVersionUID for interoperability.
        See Also:
        Constant Field Values
    • Constructor Detail

      • CustomHashtable

        public CustomHashtable()
        Constructs a new, empty hashtable with a default capacity and load factor, which is 0.75.
      • CustomHashtable

        public CustomHashtable​(java.util.Map<java.lang.String,​V> t)
        Constructs a new hashtable with the same mappings as the given Map. The hashtable is created with a capacity of twice the number of entries in the given Map or 11 (whichever is greater), and a default load factor, which is 0.75.
        Parameters:
        t - Map to base the hashtable on
      • CustomHashtable

        public CustomHashtable​(int capacity)
        Constructs a new, empty hashtable with the specified initial capacity and default load factor, which is 0.75.
        Parameters:
        capacity - initial capacity of the hashtable
      • CustomHashtable

        public CustomHashtable​(int capacity,
                               float loadFactor)
        Constructs a new, empty hashtable with the specified initial capacity and the specified load factor.
        Parameters:
        capacity - initial capacity of the hashtable
        loadFactor - the load factor of the hashtable
    • Method Detail

      • makeUniqueKey

        public java.lang.String makeUniqueKey​(java.lang.String key)
        Returns a unique key string for the hashtable based on a given key string.
        Parameters:
        key - A string that we want to base a hashtable key on.
        Returns:
        A unique key, which should be used as an input to the put() method.
      • appendKey

        protected java.lang.String appendKey​(java.lang.String key)
                                      throws java.lang.NullPointerException
        Starts with a key that already exists in the hashtable and appends integers to its toString(). Throws a NullPointer Exception if a unique key can't be found after appending all the integer values.
        Parameters:
        key - DOCUMENT ME!
        Returns:
        returns the newly formed key.
        Throws:
        java.lang.NullPointerException - thrown when key cannot be appended to make a unique key.