Interface Context<T>

Type Parameters:
T - the context value type
All Superinterfaces:
AutoCloseable, Supplier<T>
All Known Implementing Classes:
AbstractContext

public interface Context<T> extends Supplier<T>, AutoCloseable
Encapsulates some context that is applicable until close().
Author:
Paul Ferraro
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Context<?>
    An empty context
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    static <T> Context<T>
    Returns an empty context.
    static <T> Context<T>
    of(T value, Runnable closeTask)
    Returns a context that provides the specified value and invokes the specified task on close.

    Methods inherited from interface Supplier

    get
  • Field Details

    • EMPTY

      static final Context<?> EMPTY
      An empty context
  • Method Details

    • close

      void close()
      Specified by:
      close in interface AutoCloseable
    • empty

      static <T> Context<T> empty()
      Returns an empty context.
      Type Parameters:
      T - the context value type
      Returns:
      an empty context.
    • of

      static <T> Context<T> of(T value, Runnable closeTask)
      Returns a context that provides the specified value and invokes the specified task on close.
      Type Parameters:
      T - the context value type
      Parameters:
      value - the context value
      closeTask - the action to perform on close().
      Returns:
      a context that provides the specified value and invokes the specified task on close.