T - the object type@NonnullByDefault public interface Chain<T>
Stream API.
Chains are not threadsafe or immutable, and should not be reused. They are intended only as a way to reduce boilerplate.
Unlike Streams, Chains are only able to process one object.
| Modifier and Type | Method and Description |
|---|---|
Chain<T> |
apply(Consumer<? super T> action)
Applies an action to the backing object
|
Chain<T> |
applyIf(Predicate<? super T> test,
Consumer<? super T> action)
Applies an action to the backing object if the test passes.
|
Chain<T> |
applyIfNonNull(Consumer<? super T> action)
Applies an action to the backing object, if the object is not null.
|
Optional<T> |
end()
Gets an optional containing the object backing this chain.
|
T |
endOrNull()
Gets the object, or null.
|
<R> Chain<R> |
flatMap(Function<? super T,? extends Chain<? extends R>> mapper)
Transforms the backing object, and returns a new chain instance
containing the result of the transformation.
|
<R> Chain<R> |
ifElse(Predicate<? super T> test,
R passValue,
R failValue)
Returns a new chain instance containing a new value, depending on if the current
object passed the given test.
|
<R> Chain<R> |
map(Function<? super T,? extends R> mapper)
Transforms the backing object, and returns a new chain instance
containing the result of the transformation.
|
<R> Chain<R> |
mapNullSafe(Function<? super T,? extends R> nonNullMapper,
R otherValue)
Transforms the backing object and returns a new chain instance
containing the result of the transformation, if the backing object is
not null.
|
<R> Chain<R> |
mapNullSafeGet(Function<? super T,? extends R> nonNullMapper,
Supplier<? extends R> nullSupplier)
Transforms the backing object and returns a new chain instance
containing the result of the transformation, if the backing object is
not null.
|
<R> Chain<R> |
mapOrElse(Predicate<? super T> test,
Function<? super T,? extends R> passedMapper,
Function<? super T,? extends R> failedMapper)
Transforms the backing object, and returns a new chain instance
containing the result of the chosen transformation function.
|
<R> Chain<R> |
mapOrElse(Predicate<? super T> test,
Function<? super T,? extends R> passedMapper,
R otherValue)
Transforms the backing object, and returns a new chain instance
containing the result of the transformation function, if the test is passed.
|
Chain<T> |
orElse(Predicate<? super T> test,
T failValue)
Updates the backing object if the test fails, otherwise returns an identical chain.
|
Chain<T> |
orElseGet(Predicate<? super T> test,
Supplier<? extends T> failSupplier)
Updates the backing object if the test fails, otherwise returns an identical chain.
|
Chain<T> |
orElseGetIfNull(Supplier<? extends T> supplier)
Updates the backing object if it is null, otherwise returns an identical chain.
|
Chain<T> |
orElseIfNull(T otherValue)
Updates the backing object if it is null, otherwise returns an identical chain.
|
static <T> Chain<T> |
start(T object)
Creates a new chain
|
static <T> Chain<T> |
startOpt(Optional<T> optional)
Creates a new chain
|
static <T> Chain<T> start(@Nullable T object)
T - the object typeobject - the initial objectstatic <T> Chain<T> startOpt(@Nonnull Optional<T> optional)
T - the object typeoptional - the initial objectChain<T> apply(Consumer<? super T> action)
action - the action to applyChain<T> applyIf(Predicate<? super T> test, Consumer<? super T> action)
test - the testaction - the action to applyChain<T> applyIfNonNull(Consumer<? super T> action)
action - the action to applyChain<T> orElse(Predicate<? super T> test, T failValue)
failValue - the fail valueChain<T> orElseIfNull(T otherValue)
otherValue - the other valueChain<T> orElseGet(Predicate<? super T> test, Supplier<? extends T> failSupplier)
failSupplier - the fail supplierChain<T> orElseGetIfNull(Supplier<? extends T> supplier)
supplier - the null supplier<R> Chain<R> ifElse(Predicate<? super T> test, R passValue, R failValue)
R - the resultant chain typetest - the testpassValue - the value to use if the object passesfailValue - the value to use if the object fails<R> Chain<R> map(Function<? super T,? extends R> mapper)
R - the resultant chain typemapper - the mapping function<R> Chain<R> mapOrElse(Predicate<? super T> test, Function<? super T,? extends R> passedMapper, R otherValue)
R - the resultant chain typetest - the testpassedMapper - the function to use if the object passes the testotherValue - the value to use if the object fails the test<R> Chain<R> mapOrElse(Predicate<? super T> test, Function<? super T,? extends R> passedMapper, Function<? super T,? extends R> failedMapper)
R - the resultant chain typetest - the testpassedMapper - the function to use if the object passes the testfailedMapper - the function to use if the object fails the test<R> Chain<R> mapNullSafe(Function<? super T,? extends R> nonNullMapper, R otherValue)
R - the resultant chain typenonNullMapper - the function to use if the object is not nullotherValue - the value to use if the object is null<R> Chain<R> mapNullSafeGet(Function<? super T,? extends R> nonNullMapper, Supplier<? extends R> nullSupplier)
R - the resultant chain typenonNullMapper - the function to use if the object is not nullnullSupplier - the supplier to use if the object is null<R> Chain<R> flatMap(Function<? super T,? extends Chain<? extends R>> mapper)
R - the resultant chain typemapper - the mapping functionOptional<T> end()
Copyright © 2020. All rights reserved.