/** * Returns the {@link Optional} value created by the configured {@link Supplier}, allowing the absence of values in * contrast to {@link #get()}. Will return the calculated instance for subsequent lookups. * * @return */ public Optional<T> getOptional() { return Optional.ofNullable(getNullable()); }
/** * Returns the value created by the configured {@link Supplier}. Will return the calculated instance for subsequent * lookups. * * @return */ public T get() { T value = getNullable(); if (value == null) { throw new IllegalStateException("Expected lazy evaluation to yield a non-null value but got null!"); } return value; }
/** * Returns the value of the lazy computation or the given default value in case the computation yields * {@literal null}. * * @param value * @return */ @Nullable public T orElse(@Nullable T value) { T nullable = getNullable(); return nullable == null ? value : nullable; }
/** * Returns the value of the lazy computation or the value produced by the given {@link Supplier} in case the original * value is {@literal null}. * * @param supplier must not be {@literal null}. * @return */ @Nullable private T orElseGet(Supplier<? extends T> supplier) { Assert.notNull(supplier, "Default value supplier must not be null!"); T value = getNullable(); return value == null ? supplier.get() : value; }