Class Functions.WeakMemoizer<A,​B>

  • Type Parameters:
    A - comparable descriptor, the usual rules for any HashMap key apply.
    B - the value
    All Implemented Interfaces:
    java.util.function.Function<A,​B>
    Enclosing class:
    Functions

    static final class Functions.WeakMemoizer<A,​B>
    extends java.lang.Object
    implements java.util.function.Function<A,​B>
    Class supports the implementation of Functions.weakMemoize(Function) and is not intended for general use. Functions.WeakMemoizer caches the result of another function. The result is weakly referenced internally. This is useful if the result is expensive to compute or the identity of the result is particularly important.

    If the results from this function are further cached then they will tend to stay in this cache for longer.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  Functions.WeakMemoizer.MappedReference<K,​V>
      A weak reference that maintains a reference to the key so that it can be removed from the map when the value is garbage collected.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      B apply​(A descriptor)
      Get a result for the supplied Descriptor.
      private void expungeStaleEntries()  
      (package private) static <A,​B>
      Functions.WeakMemoizer<A,​B>
      weakMemoizer​(java.util.function.Function<A,​B> delegate)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.function.Function

        andThen, compose
    • Field Detail

      • queue

        private final java.lang.ref.ReferenceQueue<B> queue
      • delegate

        private final java.util.function.Function<A,​B> delegate
    • Constructor Detail

      • WeakMemoizer

        WeakMemoizer​(java.util.function.Function<A,​B> delegate)
        Construct a new Functions.WeakMemoizer instance.
        Parameters:
        delegate - for creating the initial values.
    • Method Detail

      • weakMemoizer

        static <A,​B> Functions.WeakMemoizer<A,​B> weakMemoizer​(java.util.function.Function<A,​B> delegate)
      • apply

        public B apply​(A descriptor)
        Get a result for the supplied Descriptor.
        Specified by:
        apply in interface java.util.function.Function<A,​B>
        Parameters:
        descriptor - must not be null
        Returns:
        descriptor lock
      • expungeStaleEntries

        private void expungeStaleEntries()