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 TypeMethodDescriptionboolean
Indicates whether some other object is "equal to" thisExceptional
.boolean
failed()
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 anExceptional
describing the value, otherwise aExceptional
failing 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
.int
hashCode()
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 anExceptional
containing the result of applying the given mapping function to the value, otherwise returns a failingExceptional
.void
If a value is present, performs the given action with the value, otherwise does nothing.void
onSucessOrFailure
(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 sequentialStream
containing only that value, otherwise returns an emptyStream
.boolean
If 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 thisExceptional
suitable for debugging.
-
Method Details
-
success
-
failed
-
filtered
-
get
If a value is present, returns the value, otherwise throwsNoSuchElementException
.- Returns:
- the non-
null
value described by thisOptional
- Throws:
Exception
- if no value is present
-
succeeded
public boolean succeeded()If a value is present, returnstrue
, otherwisefalse
.- Returns:
true
if a value is present, otherwisefalse
-
failed
public boolean failed()If a exception was throwb, returnstrue
, otherwisefalse
.- Returns:
true
if 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 anExceptional
describing the value, otherwise aExceptional
failing due to aFilteredException
.- Parameters:
predicate
- the predicate to apply to a value, if present- Returns:
- an
Exceptional
describing 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 anExceptional
containing the result of applying the given mapping function to the value, otherwise returns a failingExceptional
.If the mapping function returns a
null
result 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
Exceptional
describing 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,flatMap
does not wrap it within an additionalExceptional
.- Type Parameters:
U
- The type of value of theExceptional
returned 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 isnull
or returns anull
result
-
stream
If a value is present, returns a sequentialStream
containing 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-
null
value 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
Exceptional
and; - 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 thisExceptional
suitable for debugging. The exact presentation format is unspecified and may vary between implementations and versions.
-