Class LazySupplier<T>

java.lang.Object
it.tidalwave.util.LazySupplier<T>
All Implemented Interfaces:
Supplier<T>

public class LazySupplier<T> extends Object implements Supplier<T>
A supplier of an object that is lazily evaluated (when its value is requested for the first time). It warranties that the real wrapped supplier is called only once.
Since:
3.2-ALPHA-13
Author:
Fabrizio Giudici
  • Constructor Details

    • LazySupplier

      public LazySupplier()
  • Method Details

    • get

      @Nonnull public T get()
      Specified by:
      get in interface Supplier<T>
    • peek

      @Nonnull public Optional<T> peek()
      Returns the value without computing it: unlike get(), this method never calls the wrapped supplier, so it can be used to find out whether the value is available without the side effects of computing it. The returned Optional contains the value if it has been computed and is not null.
      Returns:
      the value, if available, or an empty Optional
      Since:
      5.0-ALPHA-4
    • clear

      public void clear()
      Clears the supplier.
    • set

      public void set(@Nonnull T ref)
      Changes the reference.
      Parameters:
      ref - the new reference
    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class Object