T - The value typepublic class FieldInitializer<T>
extends java.lang.Object
| Constructor and Description |
|---|
FieldInitializer() |
| Modifier and Type | Method and Description |
|---|---|
static <T> FieldInitializer<T> |
attempt(ThrowingSupplier<T> supplier)
Create a FieldInitializer that attempts to get the value from the supplier.
|
FieldInitializer<T> |
ensure(java.util.function.Supplier<java.lang.Throwable> exceptionSupplier)
Ensure that the value is not null, otherwise throw the provided exception.
|
static <T> FieldInitializer<T> |
firstOf(ThrowingSupplier<T>... suppliers)
Create a FieldInitializer that tries multiple suppliers and returns the first non-null value.
If all suppliers throw an exception or return null, an IllegalStateException is thrown. |
T |
get()
Get the value from this FieldInitializer.
May return null or throw an exception. |
FieldInitializer<T> |
handleException(java.util.function.Function<java.lang.Throwable,java.lang.Throwable> exceptionMapper)
Handle exceptions thrown by the supplier using the provided exception mapper.
|
<R> FieldInitializer<R> |
map(ThrowingFunction<T,R> mapper)
Map the value of this FieldInitializer.
|
static <T> FieldInitializer<T> |
of(T value)
Create a FieldInitializer with a constant value.
|
FieldInitializer<T> |
onlyIf(boolean condition)
Only get the value if the condition is true, otherwise return null.
|
FieldInitializer<T> |
onlyIf(ThrowingSupplier<java.lang.Boolean> conditionSupplier)
Only get the value if the condition supplier returns true, otherwise return null.
|
FieldInitializer<T> |
or(ThrowingSupplier<T> supplier)
Try to get the value from this FieldInitializer, if it is null or throws an exception, try the fallback supplier.
|
T |
orElse(T other)
Get the value from this FieldInitializer, if it is null, return the provided other value.
May also throw exceptions from the supplier. |
FieldInitializer<T> |
peek(ThrowingConsumer<T> consumer)
Peek at the value of this FieldInitializer without modifying it.
|
T |
require(java.util.function.Supplier<java.lang.Throwable> exceptionSupplier)
Get the value from this FieldInitializer, if it is null, throw the provided exception.
May also throw exceptions from the supplier. |
FieldInitializer<T> |
silent()
Silently catch any exceptions thrown by the supplier and return null instead.
|
<R> FieldInitializer<R> |
uncheckedCast()
Unchecked cast of this FieldInitializer to a different type.
Beware of potential ClassCastExceptions when using this method. |
public static <T> FieldInitializer<T> of(T value)
T - The value typevalue - The valuepublic static <T> FieldInitializer<T> attempt(ThrowingSupplier<T> supplier)
T - The value typesupplier - The supplier@SafeVarargs public static <T> FieldInitializer<T> firstOf(ThrowingSupplier<T>... suppliers)
T - The value typesuppliers - The suppliers to tryjava.lang.IllegalStateException - If all suppliers failpublic <R> FieldInitializer<R> map(ThrowingFunction<T,R> mapper)
R - The new value typemapper - The mapper functionpublic FieldInitializer<T> peek(ThrowingConsumer<T> consumer)
consumer - The consumer to accept the valuepublic FieldInitializer<T> or(ThrowingSupplier<T> supplier)
supplier - The fallback supplierpublic FieldInitializer<T> onlyIf(boolean condition)
condition - The conditionpublic FieldInitializer<T> onlyIf(ThrowingSupplier<java.lang.Boolean> conditionSupplier)
conditionSupplier - The condition supplierpublic FieldInitializer<T> ensure(java.util.function.Supplier<java.lang.Throwable> exceptionSupplier)
exceptionSupplier - The exception supplierpublic FieldInitializer<T> handleException(java.util.function.Function<java.lang.Throwable,java.lang.Throwable> exceptionMapper)
exceptionMapper - The exception mapperpublic FieldInitializer<T> silent()
public <R> FieldInitializer<R> uncheckedCast()
R - The new value typepublic T get()
public T require(java.util.function.Supplier<java.lang.Throwable> exceptionSupplier)
exceptionSupplier - The exception supplier