Interface CloseableMemoize<S extends AutoCloseable>

Type Parameters:
S - Type of the value returned.
All Superinterfaces:
AutoCloseable, Memoize<S>, Supplier<S>
All Known Implementing Classes:
CloseableMemoizingSupplier

public interface CloseableMemoize<S extends AutoCloseable> extends Memoize<S>, AutoCloseable
Closable memoizing supplier.

This type extends Memoize and AutoCloseable.

  • Method Details

    • closeableSupplier

      static <T extends AutoCloseable> CloseableMemoize<T> closeableSupplier(Supplier<? extends T> supplier)
      Creates an AutoClosable supplier which memoizes the AutoCloseable value returned by the specified supplier.

      When the returned supplier is called to get a value, it will call the specified supplier at most once to obtain a value.

      When close() is called on the returned supplier, it will call close() on the memoized value, if present, and dereference the value. After close() is called on the returned supplier, the get() method of the returned supplier will throw an IllegalStateException.

      Type Parameters:
      T - Type of the value returned by the supplier.
      Parameters:
      supplier - The source supplier. Must not be null. The supplier should not return a null value. If the supplier does return a null value, the returned supplier will be marked closed and its get() method will throw an IllegalStateException.
      Returns:
      A memoized supplier wrapping the specified supplier.
    • isClosed

      boolean isClosed()
      Returns whether this memoizing supplier is closed.
      Returns:
      true If this memoizing supplier is closed; otherwise false.
    • accept

      CloseableMemoize<S> accept(Consumer<? super S> consumer)
      Call the consumer with the value of this memoized supplier.

      This method will block closing this memoized supplier while this method is executing.

      Specified by:
      accept in interface Memoize<S extends AutoCloseable>
      Parameters:
      consumer - The consumer to accept the value of this memoized supplier. Must not be null.
      Returns:
      This memoized supplier.