Class LazyThrowingSingleton<T, X extends Exception>

java.lang.Object
uk.co.parnmatt.vector.util.LazyThrowingSingleton<T,X>
Type Parameters:
T - the type of the singleton value
X - the exception that can be thrown during the evaluation of the singleton
All Implemented Interfaces:
ThrowingSupplier<T,X>

public final class LazyThrowingSingleton<T, X extends Exception> extends Object implements ThrowingSupplier<T,X>
Represents a singleton that is lazily evaluated on the first call to get()
  • Constructor Details

    • LazyThrowingSingleton

      public LazyThrowingSingleton(ThrowingSupplier<T,X> supplier)
      Parameters:
      supplier - the supplier to provide the value of the singleton
  • Method Details

    • get

      public T get() throws X
      Specified by:
      get in interface ThrowingSupplier<T, X extends Exception>
      Returns:
      the value of the supplier
      Throws:
      X
      See Also:
    • getIfPresentOrNull

      public T getIfPresentOrNull()
      Returns:
      the singleton if it has been initialized, otherwise null
    • isInitialized

      public boolean isInitialized()
      Returns:
      true if the singleton has been initialized, otherwise false
    • toString

      public String toString()
      Overrides:
      toString in class Object