saker.build Documentation TaskDoc JavaDoc Packages
public final class LazySupplier<Timplements Supplier<T>
Supplier implementation that will lazily compute its result value once and return that in the following calls.

This class will take a computer function that computes its final result value. The computer function will be called the first time get() is called on this supplier. The computer function is only called once during the lifetime of this object, and its return value will be retained. Any following calls to get() will return the computed object.

Use the static of(...) methods to create a new instance.

TThe type of the lazily computed object.
Methods
public T
get()
Gets a result.
public T
Gets the computed result of this lazy supplier if ready.
public T
Gets the computed result of this lazy supplier if ready, or prevents the computation of it in future calls.
public boolean
Checks if the result value of this lazy supplier has already been computed.
public static <FirstArgType, SecondArgType, Type> LazySupplier<Type>
of(FirstArgType arg1, SecondArgType arg2, BiFunction<super FirstArgType, ? super SecondArgType, Type> initer)
Creates a new lazy supplier that passes the given arguments to the calculator function.
public static <ArgType, Type> LazySupplier<Type>
of(ArgType arg, Function<super ArgType, Type> initer)
Creates a new lazy supplier that passes the given argument to the calculator function.
public static <Type> LazySupplier<Type>
of(Function<super LazySupplier<extends Type>, Type> initer)
Creates a new lazy supplier that uses the argument function to compute the lazy value.
public static <Type> LazySupplier<Type>
of(Supplier<extends Type> initer)
Creates a new lazy supplier that uses the argument supplier to compute the lazy value.
public String
Returns a string representation of the object.
public T get()
Overridden from: Supplier
Gets a result.
a result
public T getIfComputed()
Gets the computed result of this lazy supplier if ready.

If the computer function returns null, this function will still return null even if the result is already computed.

The computed result or null if not yet computed.
Gets the computed result of this lazy supplier if ready, or prevents the computation of it in future calls.

If the value of this lazy supplier has been already computed, or is being computed concurrently, this method returns the computed value. If it hasn't been computed yet, and is not being concurrently computed, it will return null, and prevent the initialization of this supplier. (All future get() and other calls will return null.)

The computed value or null if not yet computed.
public boolean isComputed()
Checks if the result value of this lazy supplier has already been computed.
true if the result is ready.
public static <FirstArgType, SecondArgType, Type> LazySupplier<Type> of(FirstArgType arg1, SecondArgType arg2, BiFunction<super FirstArgType, ? super SecondArgType, Type> initer)
Creates a new lazy supplier that passes the given arguments to the calculator function.
FirstArgTypeThe type of the first argument to pass to the initialization function.
SecondArgTypeThe type of the second argument to pass to the initialization function.
TypeThe type of the lazily computed object.
arg1The first argument to pass to the initializer. May be null.
arg2The second argument to pass to the initializer. May be null.
initerThe value computer.
The created lazy supplier.
saker.util 0.8.4
public static <ArgType, Type> LazySupplier<Type> of(ArgType arg, Function<super ArgType, Type> initer)
Creates a new lazy supplier that passes the given argument to the calculator function.
ArgTypeThe type of the argument to pass to the initialization function.
TypeThe type of the lazily computed object.
argThe argument to pass to the initializer. May be null.
initerThe value computer.
The created lazy supplier.
saker.util 0.8.4
public static <Type> LazySupplier<Type> of(Function<super LazySupplier<extends Type>, Type> initer)
Creates a new lazy supplier that uses the argument function to compute the lazy value.

The function will be applied with the returned lazy supplier as its function argument.

Using this function to create a lazy supplier can avoid the chicken-egg problem when the computing function wishes to reference the created lazy supplier in its computing function. Some computer functions may have an use-case for this, as the computer function may have side effects.

TypeThe type of the lazily computed object.
initerThe value computer.
The created lazy supplier.
public static <Type> LazySupplier<Type> of(Supplier<extends Type> initer)
Creates a new lazy supplier that uses the argument supplier to compute the lazy value.
TypeThe type of the lazily computed object.
initerThe value computer.
The created lazy supplier.
public String toString()
Overridden from: Object
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 
a string representation of the object.