Package uk.co.terminological.rjava.utils
Class RStreams.Exceptional<T>
java.lang.Object
uk.co.terminological.rjava.utils.RStreams.Exceptional<T>
- Enclosing class:
- RStreams
-
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicates whether some other object is "equal to" thisExceptional.booleanfailed()If a exception was throwb, returnstrue, otherwisefalse.static <T,E extends Exception>
RStreams.Exceptional<T>If the exceptional has a value, and the value matches the given predicate, returns anExceptionaldescribing the value, otherwise aExceptionalfailing due to aFilteredException.filtered()<U> RStreams.Exceptional<U>flatMap(Function<? super T, ? extends RStreams.Exceptional<? extends U>> mapper) If a value is present, returns the result of applying the givenExceptional-bearing mapping function to the value, otherwise returns an emptyExceptional.get()If a value is present, returns the value, otherwise throwsNoSuchElementException.inthashCode()Returns the hash code of the value, if present, otherwise0(zero) if no value is present.<U> RStreams.Exceptional<U>map(RStreams.ExceptionalFunction<? super T, ? extends U> mapper) If a value is present, returns anExceptionalcontaining the result of applying the given mapping function to the value, otherwise returns a failingExceptional.voidIf a value is present, performs the given action with the value, otherwise does nothing.voidonSucessOrFailure(Consumer<? super T> action, Consumer<Exception> errorHandler) If a value is present, performs the given action with the value, otherwise performs the given empty-based action.If a value is present, returns the value, otherwise returnsother.If a value is present, returns the value, otherwise returns the result produced by the supplying function.If a value is present, returns the value, otherwise throwsNoSuchElementException.stream()If a value is present, returns a sequentialStreamcontaining only that value, otherwise returns an emptyStream.booleanIf a value is present, returnstrue, otherwisefalse.static <T,E extends Exception>
RStreams.Exceptional<T>success(T value) toString()Returns a non-empty string representation of thisExceptionalsuitable for debugging.
-
Method Details
-
success
-
failed
-
filtered
-
get
If a value is present, returns the value, otherwise throwsNoSuchElementException.- Returns:
- the non-
nullvalue described by thisOptional - Throws:
Exception- if no value is present
-
succeeded
public boolean succeeded()If a value is present, returnstrue, otherwisefalse.- Returns:
trueif a value is present, otherwisefalse
-
failed
public boolean failed()If a exception was throwb, returnstrue, otherwisefalse.- Returns:
trueif a value is present, otherwisefalse
-
onSuccess
If a value is present, performs the given action with the value, otherwise does nothing.- Parameters:
action- the action to be performed, if a value is present- Throws:
NullPointerException- if value is present and the given action isnull
-
onSucessOrFailure
If a value is present, performs the given action with the value, otherwise performs the given empty-based action.- Parameters:
action- the action to be performed, if a value is presenterrorHandler- the action to be performed, if an error was thrown- Throws:
NullPointerException- if a value is present and the given action isnull, or no value is present and the given empty-based action isnull.- Since:
- 9
-
filter
If the exceptional has a value, and the value matches the given predicate, returns anExceptionaldescribing the value, otherwise aExceptionalfailing due to aFilteredException.- Parameters:
predicate- the predicate to apply to a value, if present- Returns:
- an
Exceptionaldescribing the value of thisExceptional, if a value is present and the value matches the given predicate, otherwise a failingExceptional - Throws:
NullPointerException- if the predicate isnull
-
map
If a value is present, returns anExceptionalcontaining the result of applying the given mapping function to the value, otherwise returns a failingExceptional.If the mapping function returns a
nullresult then this method returns an emptyExceptional.- Type Parameters:
U- The type of the value returned from the mapping function- Parameters:
mapper- the mapping function to apply to a value, if present- Returns:
- an
Exceptionaldescribing the result of applying a mapping function to the value of thisExceptional, if a value is present, otherwise an emptyExceptional - Throws:
NullPointerException- if the mapping function isnull
-
flatMap
public <U> RStreams.Exceptional<U> flatMap(Function<? super T, ? extends RStreams.Exceptional<? extends U>> mapper) If a value is present, returns the result of applying the givenExceptional-bearing mapping function to the value, otherwise returns an emptyExceptional.This method is similar to
map(ExceptionalFunction), but the mapping function is one whose result is already anExceptional, and if invoked,flatMapdoes not wrap it within an additionalExceptional.- Type Parameters:
U- The type of value of theExceptionalreturned by the mapping function- Parameters:
mapper- the mapping function to apply to a value, if present- Returns:
- the result of applying an
Exceptional-bearing mapping function to the value of thisExceptional, if a value is present, otherwise an emptyExceptional - Throws:
NullPointerException- if the mapping function isnullor returns anullresult
-
stream
If a value is present, returns a sequentialStreamcontaining only that value, otherwise returns an emptyStream.- Returns:
- the Exceptional value as a
Stream - Since:
- 9
-
orElse
If a value is present, returns the value, otherwise returnsother.- Parameters:
other- the value to be returned, if no value is present. May benull.- Returns:
- the value, if present, otherwise
other
-
orElseGet
If a value is present, returns the value, otherwise returns the result produced by the supplying function.- Parameters:
supplier- the supplying function that produces a value to be returned- Returns:
- the value, if present, otherwise the result produced by the supplying function
- Throws:
NullPointerException- if no value is present and the supplying function isnull
-
orElseThrow
If a value is present, returns the value, otherwise throwsNoSuchElementException.- Returns:
- the non-
nullvalue described by thisExceptional - Throws:
Exception- Since:
- 10
-
equals
Indicates whether some other object is "equal to" thisExceptional. The other object is considered equal if:- it is also an
Exceptionaland; - both instances have no value present or;
- the present values are "equal to" each other via
equals().
- it is also an
-
hashCode
public int hashCode()Returns the hash code of the value, if present, otherwise0(zero) if no value is present. -
toString
Returns a non-empty string representation of thisExceptionalsuitable for debugging. The exact presentation format is unspecified and may vary between implementations and versions.
-