Package com.linkedin.venice.utils.lazy
Class LazyResettableImpl<C>
- java.lang.Object
-
- com.linkedin.venice.utils.lazy.LazyResettableImpl<C>
-
- All Implemented Interfaces:
Lazy<C>
,LazyResettable<C>
- Direct Known Subclasses:
LazyResettableWithTearDown
public class LazyResettableImpl<C> extends java.lang.Object implements LazyResettable<C>
-
-
Constructor Summary
Constructors Constructor Description LazyResettableImpl(java.util.function.Supplier<C> supplier)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<C>
filter(java.util.function.Predicate<? super C> predicate)
If a value is initialized, and the value matches the given predicate, return anOptional
describing the value, otherwise return an emptyOptional
.<U> java.util.Optional<U>
flatMap(java.util.function.Function<? super C,java.util.Optional<U>> mapper)
If a value is initialized, apply the providedOptional
-bearing mapping function to it, return that result, otherwise return an emptyOptional
.C
get()
void
ifPresent(java.util.function.Consumer<? super C> consumer)
boolean
isPresent()
<U> java.util.Optional<U>
map(java.util.function.Function<? super C,? extends U> mapper)
If a value is initialized, apply the provided mapping function to it, and if the result is non-null, return anOptional
describing the result.C
orElse(C other)
Return the value if initialized, otherwise returnother
.C
orElseGet(java.util.function.Supplier<? extends C> other)
Return the value if initialized, otherwise invokeother
and return the result of that invocation.<X extends java.lang.Throwable>
CorElseThrow(java.util.function.Supplier<? extends X> exceptionSupplier)
Return the contained value, if initialized, otherwise throw an exception to be created by the provided supplier.void
reset()
Returns to the uninitialized state.
-
-
-
Constructor Detail
-
LazyResettableImpl
public LazyResettableImpl(java.util.function.Supplier<C> supplier)
-
-
Method Detail
-
reset
public void reset()
Description copied from interface:LazyResettable
Returns to the uninitialized state.- Specified by:
reset
in interfaceLazyResettable<C>
-
get
public C get()
-
ifPresent
public void ifPresent(java.util.function.Consumer<? super C> consumer)
-
isPresent
public boolean isPresent()
-
filter
public java.util.Optional<C> filter(java.util.function.Predicate<? super C> predicate)
Description copied from interface:Lazy
If a value is initialized, and the value matches the given predicate, return anOptional
describing the value, otherwise return an emptyOptional
.
-
map
public <U> java.util.Optional<U> map(java.util.function.Function<? super C,? extends U> mapper)
Description copied from interface:Lazy
If a value is initialized, apply the provided mapping function to it, and if the result is non-null, return anOptional
describing the result. Otherwise return an emptyOptional
.- Specified by:
map
in interfaceLazy<C>
- Type Parameters:
U
- The type of the result of the mapping function- Parameters:
mapper
- a mapping function to apply to the value, if initialized- Returns:
- an
Optional
describing the result of applying a mapping function to the value of thisOptional
, if a value is initialized, otherwise an emptyOptional
-
flatMap
public <U> java.util.Optional<U> flatMap(java.util.function.Function<? super C,java.util.Optional<U>> mapper)
Description copied from interface:Lazy
If a value is initialized, apply the providedOptional
-bearing mapping function to it, return that result, otherwise return an emptyOptional
. This method is similar toLazy.map(Function)
, but the provided mapper is one whose result is already anOptional
, and if invoked,flatMap
does not wrap it with an additionalOptional
.- Specified by:
flatMap
in interfaceLazy<C>
- Type Parameters:
U
- The type parameter to theOptional
returned by the mapping function- Parameters:
mapper
- a mapping function to apply to the value, if initialized- Returns:
- the result of applying an
Optional
-bearing mapping function to the value of thisOptional
, if a value is initialized, otherwise an emptyOptional
-
orElse
public C orElse(C other)
Description copied from interface:Lazy
Return the value if initialized, otherwise returnother
.
-
orElseGet
public C orElseGet(java.util.function.Supplier<? extends C> other)
Description copied from interface:Lazy
Return the value if initialized, otherwise invokeother
and return the result of that invocation.
-
orElseThrow
public <X extends java.lang.Throwable> C orElseThrow(java.util.function.Supplier<? extends X> exceptionSupplier) throws X extends java.lang.Throwable
Description copied from interface:Lazy
Return the contained value, if initialized, otherwise throw an exception to be created by the provided supplier.- Specified by:
orElseThrow
in interfaceLazy<C>
- Type Parameters:
X
- Type of the exception to be thrown- Parameters:
exceptionSupplier
- The supplier which will return the exception to be thrown- Returns:
- the initialized value
- Throws:
X
- if there is no value initializedX extends java.lang.Throwable
-
-