Class ReferenceHashMap

    • Method Detail

      • getMaxSize

        public int getMaxSize()
        Description copied from interface: SizedMap
        The maximum number of entries, or Integer.MAX_VALUE for no limit.
        Specified by:
        getMaxSize in interface SizedMap
      • setMaxSize

        public void setMaxSize​(int maxSize)
        Description copied from interface: SizedMap
        The maximum number of entries, or Integer.MAX_VALUE for no limit.
        Specified by:
        setMaxSize in interface SizedMap
      • isFull

        public boolean isFull()
        Description copied from interface: SizedMap
        Whether the map is full.
        Specified by:
        isFull in interface SizedMap
      • overflowRemoved

        public void overflowRemoved​(java.lang.Object key,
                                    java.lang.Object value)
        Description copied from interface: SizedMap
        Overridable callback for when an overflow entry is automatically removed.
        Specified by:
        overflowRemoved in interface SizedMap
      • valueExpired

        public void valueExpired​(java.lang.Object key)
        Description copied from interface: ReferenceMap
        Overridable callback for when a value reference expires.
        Specified by:
        valueExpired in interface ReferenceMap
        Parameters:
        key - the key for the expired value
      • keyExpired

        public void keyExpired​(java.lang.Object value)
        Description copied from interface: ReferenceMap
        Overridable callback for when a key reference expires.
        Specified by:
        keyExpired in interface ReferenceMap
        Parameters:
        value - the value for the expired key
      • addMapping

        protected void addMapping​(int hashIndex,
                                  int hashCode,
                                  java.lang.Object key,
                                  java.lang.Object value)
        Description copied from class: AbstractHashedMap
        Adds a new key-value mapping into this map.

        This implementation calls createEntry(), addEntry() and checkCapacity(). It also handles changes to modCount and size. Subclasses could override to fully control adds to the map.

        Overrides:
        addMapping in class AbstractHashedMap
        Parameters:
        hashIndex - the index into the data array to store at
        hashCode - the hash code of the key to add
        key - the key to add
        value - the value to add
      • doWriteObject

        protected void doWriteObject​(java.io.ObjectOutputStream out)
                              throws java.io.IOException
        Description copied from class: AbstractReferenceMap
        Replaces the superclass method to store the state of this class.

        Serialization is not one of the JDK's nicest topics. Normal serialization will initialise the superclass before the subclass. Sometimes however, this isn't what you want, as in this case the put() method on read can be affected by subclass state.

        The solution adopted here is to serialize the state data of this class in this protected method. This method must be called by the writeObject() of the first serializable subclass.

        Subclasses may override if they have a specific field that must be present on read before this implementation will work. Generally, the read determines what must be serialized here, if anything.

        Overrides:
        doWriteObject in class AbstractReferenceMap
        Parameters:
        out - the output stream
        Throws:
        java.io.IOException - if an error occurs while writing to the stream
      • doReadObject

        protected void doReadObject​(java.io.ObjectInputStream in)
                             throws java.lang.ClassNotFoundException,
                                    java.io.IOException
        Description copied from class: AbstractReferenceMap
        Replaces the superclass method to read the state of this class.

        Serialization is not one of the JDK's nicest topics. Normal serialization will initialise the superclass before the subclass. Sometimes however, this isn't what you want, as in this case the put() method on read can be affected by subclass state.

        The solution adopted here is to deserialize the state data of this class in this protected method. This method must be called by the readObject() of the first serializable subclass.

        Subclasses may override if the subclass has a specific field that must be present before put() or calculateThreshold() will work correctly.

        Overrides:
        doReadObject in class AbstractReferenceMap
        Parameters:
        in - the input stream
        Throws:
        java.lang.ClassNotFoundException - if an object read from the stream can not be loaded
        java.io.IOException - if an error occurs while reading from the stream