Class CachedSupplierBase<T>

Object
CachedSupplierBase<T>
Type Parameters:
T - result-type
Direct Known Subclasses:
CachedSupplier

public abstract class CachedSupplierBase<T> extends Object
Base class for functions that memoize (cache) a call to an interface.
Author:
Owen Feehan
  • Constructor Details

    • CachedSupplierBase

      public CachedSupplierBase()
  • Method Details

    • isEvaluated

      public boolean isEvaluated()
      Has the function already been evaluated?

      i.e. does a value already exist in the cache.

      Returns:
      true iff a value exists in the cache.
    • call

      protected <E extends Exception> T call(CheckedSupplier<T,E> supplier) throws E
      Gets the value supplied by supplier via the cache if it exists, or otherwise via the supplier.

      The value is then cached, and the object is considered as evaluated.

      Type Parameters:
      E - an exception that can be thrown by supplier.
      Parameters:
      supplier - the operation used to create the value.
      Returns:
      the value, either created or from the cache.
      Throws:
      E - if thrown by supplier.
    • reset

      public void reset()
      Ensures the object is unevaluated, deleting any cached result if it exists.