T
- the type of the lazy-loaded object.public interface Lazy<T>
Declares lazy-loading 1:1 relationships in resource models. In addition, as lazy-loading always has to deal with nonexistent values, this
interface both features a Optional
representation via asOptional()
and provides the same API semantics
as Optional
for convenience.
NEBA automatically detects Lazy
fields and provides a suitable lazy-loading implementation.
Note that this interface is not required to lazy-load collections, as NEBA automatically
provides collection-typed members, such as Reference
or Children
collections, as lazy-loading proxies.
To declare a lazy reference from resource model "A" to resource model "B", write:
@ResourceModel
(types = "...") public class A { @Reference
private Lazy<B> b; }
This interface may also be used to explicitly lazy-load collection-typed resource model relationships, such as
Children
or Reference
collections:
@ResourceModel
(types = "...") public class A { @Children
private Lazy<List<B>> children; }
However, collection-typed relationships are automatically provided as lazy-loading proxies, thus there usually is no
reason to make them Lazy
.
Modifier and Type | Method and Description |
---|---|
Optional<T> |
asOptional() |
default Lazy<T> |
filter(Predicate<? super T> predicate) |
default <U> Lazy<U> |
flatMap(Function<? super T,Lazy<U>> f) |
default T |
get() |
default void |
ifPresent(Consumer<? super T> c) |
default boolean |
isPresent() |
default <U> Lazy<U> |
map(Function<? super T,? extends U> f) |
default T |
orElse(T other) |
default T |
orElseGet(Supplier<? extends T> other) |
default <X extends Throwable> |
orElseThrow(Supplier<? extends X> exceptionSupplier) |
@Nonnull Optional<T> asOptional()
Optional
representation of the lazy-loaded value, never null
.@Nonnull default T get()
Optional.get()
default boolean isPresent()
Optional.isPresent()
@CheckForNull default T orElse(T other)
Optional.orElse(T)
@CheckForNull default T orElseGet(Supplier<? extends T> other)
Copyright © 2024. All rights reserved.