Class HardMemoizer<A,V>

java.lang.Object
org.faktorips.runtime.caching.HardMemoizer<A,V>
All Implemented Interfaces:
IComputable<A,V>

public class HardMemoizer<A,V> extends Object implements IComputable<A,V>
This memoizer is implemented as suggested by Brian Goetz in Java Concurrency in Practice. It is a thread safe caching mechanism that loads not stored objects by calling an IComputable. It is called "hard" to differentiate it from the previous Memoizer using SoftReferences.
  • Method Details

    • of

      public static <K, V> HardMemoizer<K,V> of(IComputable<K,V> computable)
      Creates a new HardMemoizer for the given value class using the given IComputable to compute the values from keys.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      computable - the function to compute a value from a key
      Returns:
      a new IComputable that includes caching
    • of

      public static <K, V> HardMemoizer<K,V> of(Class<? super V> valueClass, Function<K,V> function)
      Creates a new HardMemoizer for the given value class using the given Function to compute the values from keys.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      valueClass - the class of the values
      function - the function to compute a value from a key
      Returns:
      a new IComputable that includes caching
    • getValueClass

      public Class<? super V> getValueClass()
      Description copied from interface: IComputable
      Getting the Class of the value this computable produces.
      Specified by:
      getValueClass in interface IComputable<A,V>
    • compute

      public V compute(A arg) throws InterruptedException
      Description copied from interface: IComputable
      Compute an object of type V identified by the key of type K
      Specified by:
      compute in interface IComputable<A,V>
      Parameters:
      arg - the key to identify the object
      Returns:
      the computed Object of type V
      Throws:
      InterruptedException - When computation was interrupted