Class LockableHashtable

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

    public class LockableHashtable
    extends java.util.Hashtable
    This subclass of the java Hashtable allows individual entries to be "locked" so that their values cannot be overwritten or removed. Note, only the put() and remove() methods have been overridden. The clear() method still removes all entries whether they've been locked or not.
    Author:
    James Snell (jasnell@us.ibm.com)
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object get​(java.lang.Object key)
      Get an entry from this hashtable, and if we don't find anything, defer to our parent, if any.
      java.util.Set getAllKeys()
      Returns the keys in this hashtable, and its parent chain
      java.util.Hashtable getParent()
      Gets the parent Hashtable for this object (if any)
      boolean isKeyLocked​(java.lang.Object key)
      Returns true if a given key is in our locked list
      java.lang.Object put​(java.lang.Object p1, java.lang.Object p2)
      Overrides the Hashtable.put() method to mark items as not being locked.
      java.lang.Object put​(java.lang.Object p1, java.lang.Object p2, boolean locked)
      New version of the put() method that allows for explicitly marking items added to the hashtable as locked.
      java.lang.Object remove​(java.lang.Object p1)
      Checks to see if an item is locked before it is removed.
      void setParent​(java.util.Hashtable parent)
      Set the parent Hashtable for this object
      • Methods inherited from class java.util.Hashtable

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

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

      • LockableHashtable

        public LockableHashtable()
      • LockableHashtable

        public LockableHashtable​(int p1,
                                 float p2)
      • LockableHashtable

        public LockableHashtable​(java.util.Map p1)
      • LockableHashtable

        public LockableHashtable​(int p1)
    • Method Detail

      • setParent

        public void setParent​(java.util.Hashtable parent)
        Set the parent Hashtable for this object
      • getParent

        public java.util.Hashtable getParent()
        Gets the parent Hashtable for this object (if any)
      • getAllKeys

        public java.util.Set getAllKeys()
        Returns the keys in this hashtable, and its parent chain
      • get

        public java.lang.Object get​(java.lang.Object key)
        Get an entry from this hashtable, and if we don't find anything, defer to our parent, if any.
        Specified by:
        get in interface java.util.Map
        Overrides:
        get in class java.util.Hashtable
      • put

        public java.lang.Object put​(java.lang.Object p1,
                                    java.lang.Object p2,
                                    boolean locked)
        New version of the put() method that allows for explicitly marking items added to the hashtable as locked.
      • put

        public java.lang.Object put​(java.lang.Object p1,
                                    java.lang.Object p2)
        Overrides the Hashtable.put() method to mark items as not being locked.
        Specified by:
        put in interface java.util.Map
        Overrides:
        put in class java.util.Hashtable
      • remove

        public java.lang.Object remove​(java.lang.Object p1)
        Checks to see if an item is locked before it is removed.
        Specified by:
        remove in interface java.util.Map
        Overrides:
        remove in class java.util.Hashtable
      • isKeyLocked

        public boolean isKeyLocked​(java.lang.Object key)
        Returns true if a given key is in our locked list