Class CallResult.FailureProjection<L,R>
java.lang.Object
com.github.badpop.jcoinbase.control.CallResult.FailureProjection<L,R>
- Type Parameters:
L
- The type of the Failure value of a CallResult.R
- The type of the Success value of a CallResult.
- All Implemented Interfaces:
FunctionalValue<L>
,java.lang.Iterable<L>
- Enclosing class:
- CallResult<L,R>
public static final class CallResult.FailureProjection<L,R> extends java.lang.Object implements FunctionalValue<L>
A failure projection of a CallResult.
-
Method Summary
Modifier and Type Method Description boolean
equals(java.lang.Object obj)
Clarifies that functionalValues have a proper equals() method implemented.io.vavr.control.Option<CallResult.FailureProjection<L,R>>
filter(java.util.function.Predicate<? super L> predicate)
ReturnsSome
value of type L if this is a failure projection of a Failure value and the predicate applies to the underlying value.<U> CallResult.FailureProjection<U,R>
flatMap(java.util.function.Function<? super L,? extends CallResult.FailureProjection<? extends U,R>> mapper)
FlatMaps this FailureProjection.L
get()
Gets theFailure
value or throws.L
getOrElse(L other)
Gets the Failure value or an alternate value, if the projected CallResult is a Success.L
getOrElseGet(java.util.function.Function<? super R,? extends L> other)
Gets the Failure value or an alternate value, if the projected CallResult is a Success.<X extends java.lang.Throwable>
LgetOrElseThrow(java.util.function.Function<? super R,X> exceptionFunction)
Gets the Failure value or throws, if the projected CallResult is a Success.int
hashCode()
Clarifies that functionalValues have a proper hashCode() method implemented.boolean
isEmpty()
Checks, thisValue
is empty, i.e. if the underlying functionalValue is absent.io.vavr.collection.Iterator<L>
iterator()
Returns a richio.vavr.collection.Iterator
.<U> CallResult.FailureProjection<U,R>
map(java.util.function.Function<? super L,? extends U> mapper)
Maps the failure value if the projected CallResult is a Failure.CallResult.FailureProjection<L,R>
orElse(CallResult.FailureProjection<? extends L,? extends R> other)
CallResult.FailureProjection<L,R>
orElse(java.util.function.Supplier<? extends CallResult.FailureProjection<? extends L,? extends R>> supplier)
void
orElseRun(java.util.function.Consumer<? super R> action)
Runs an action in the case this is a projection on a Success value.CallResult.FailureProjection<L,R>
peek(java.util.function.Consumer<? super L> action)
Applies the given action to the value if the projected callResult is a Failure.CallResult<L,R>
toCallResult()
Returns the underlying callResult of this projection.<U> U
transform(java.util.function.Function<? super CallResult.FailureProjection<L,R>,? extends U> f)
Transforms thisFailureProjection
.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.github.badpop.jcoinbase.control.FunctionalValue
contains, exists, forAll, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, isAsync, isLazy, isSingleValued, spliterator, toCallResult, toCallResult, toJavaOptional, toOption, toString
Methods inherited from interface java.lang.Iterable
forEach
-
Method Details
-
isEmpty
public boolean isEmpty()Description copied from interface:FunctionalValue
Checks, thisValue
is empty, i.e. if the underlying functionalValue is absent.- Specified by:
isEmpty
in interfaceFunctionalValue<L>
- Returns:
- false, if no underlying functionalValue is present, true otherwise.
-
get
Gets theFailure
value or throws.- Specified by:
get
in interfaceFunctionalValue<L>
- Returns:
- the failure value, if the underlying
CallResult
is aFailure
- Throws:
java.util.NoSuchElementException
- if the underlyingCallResult
of thisFailureProjection
is aSuccess
-
orElse
public CallResult.FailureProjection<L,R> orElse(CallResult.FailureProjection<? extends L,? extends R> other) -
orElse
public CallResult.FailureProjection<L,R> orElse(java.util.function.Supplier<? extends CallResult.FailureProjection<? extends L,? extends R>> supplier) -
getOrElse
Gets the Failure value or an alternate value, if the projected CallResult is a Success.- Specified by:
getOrElse
in interfaceFunctionalValue<L>
- Parameters:
other
- an alternative value- Returns:
- the failure value, if the underlying CallResult is a Failure or else
other
- Throws:
java.util.NoSuchElementException
- if the underlying callResult of this FailureProjection is a Success
-
getOrElseGet
Gets the Failure value or an alternate value, if the projected CallResult is a Success.- Parameters:
other
- a function which converts a Success value to an alternative Failure value- Returns:
- the failure value, if the underlying CallResult is a Failure or else the alternative
Failure value provided by
other
by applying the Success value.
-
orElseRun
Runs an action in the case this is a projection on a Success value.- Parameters:
action
- an action which consumes a Success value
-
getOrElseThrow
public <X extends java.lang.Throwable> L getOrElseThrow(java.util.function.Function<? super R,X> exceptionFunction) throws X extends java.lang.ThrowableGets the Failure value or throws, if the projected CallResult is a Success.- Type Parameters:
X
- a throwable type- Parameters:
exceptionFunction
- a function which creates an exception based on a Success value- Returns:
- the failure value, if the underlying CallResult is a Failure or else throws the
exception provided by
exceptionFunction
by applying the Success value. - Throws:
X
- if the projected CallResult is a Success
-
toCallResult
Returns the underlying callResult of this projection.- Returns:
- the underlying callResult
-
filter
public io.vavr.control.Option<CallResult.FailureProjection<L,R>> filter(java.util.function.Predicate<? super L> predicate)ReturnsSome
value of type L if this is a failure projection of a Failure value and the predicate applies to the underlying value.- Parameters:
predicate
- A predicate- Returns:
- A new Option
-
flatMap
public <U> CallResult.FailureProjection<U,R> flatMap(java.util.function.Function<? super L,? extends CallResult.FailureProjection<? extends U,R>> mapper)FlatMaps this FailureProjection.- Type Parameters:
U
- Component type of the mapped failure value- Parameters:
mapper
- A mapper- Returns:
- this as
FailureProjection<L, U>
if a Success is underlying, otherwise a the mapping result of the failure value. - Throws:
java.lang.NullPointerException
- ifmapper
is null
-
map
public <U> CallResult.FailureProjection<U,R> map(java.util.function.Function<? super L,? extends U> mapper)Maps the failure value if the projected CallResult is a Failure.- Specified by:
map
in interfaceFunctionalValue<L>
- Type Parameters:
U
- The new type of a Failure value- Parameters:
mapper
- A mapper which takes a failure value and returns a value of type U- Returns:
- A new FailureProjection
-
peek
Applies the given action to the value if the projected callResult is a Failure. Otherwise nothing happens.- Specified by:
peek
in interfaceFunctionalValue<L>
- Parameters:
action
- An action which takes a failure value- Returns:
- this FailureProjection
-
transform
public <U> U transform(java.util.function.Function<? super CallResult.FailureProjection<L,R>,? extends U> f)Transforms thisFailureProjection
.- Type Parameters:
U
- Type of transformation result- Parameters:
f
- A transformation- Returns:
- An instance of type
U
- Throws:
java.lang.NullPointerException
- iff
is null
-
iterator
Description copied from interface:FunctionalValue
Returns a richio.vavr.collection.Iterator
.- Specified by:
iterator
in interfaceFunctionalValue<L>
- Specified by:
iterator
in interfacejava.lang.Iterable<L>
- Returns:
- A new Iterator
-
equals
public boolean equals(java.lang.Object obj)Description copied from interface:FunctionalValue
Clarifies that functionalValues have a proper equals() method implemented.- Specified by:
equals
in interfaceFunctionalValue<L>
- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- An object- Returns:
- true, if this equals o, false otherwise
-
hashCode
public int hashCode()Description copied from interface:FunctionalValue
Clarifies that functionalValues have a proper hashCode() method implemented.See Object.hashCode().
- Specified by:
hashCode
in interfaceFunctionalValue<L>
- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- The hashcode of this object
-