@RequiredArgsConstructor
@EqualsAndHashCode
public class Lazy<T> implements Supplier<T> {
private final Supplier<T> supplier;
private T value = null;
private boolean resolved = false;
/**
* Creates a new {@link Lazy} to produce an object lazily.
*
* @param <T>
* the type of which to produce an object of eventually.
* @param supplier
* the {@link Supplier} to create the object lazily.
* @return
*/
public static <T> Lazy<T> of(Supplier<T> supplier) {
return new Lazy<>(supplier);
}
/**
* Returns the value created by the configured {@link Supplier}. Will return
* the calculated instance for subsequent lookups.
*
* @return
*/
@Override
public T get() {
return getNullable();
}
/**
* Returns the value of the lazy computation or the given default value in
* case the computation yields {&