Class Result.Success<T,E>
java.lang.Object
ru.progrm_jarvis.javacommons.object.Result.Success<T,E>
- Type Parameters:
T- type of successful resultE- type of error result
Representation of a
successful result.-
Nested Class Summary
Nested classes/interfaces inherited from interface ru.progrm_jarvis.javacommons.object.Result
Result.Error<T,E>, Result.Extensions, Result.NotErrorException, Result.NotSuccessException, Result.NullError, Result.NullSuccess, Result.Success<T, E> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the given result if this is asuccessful resultotherwise keeping theerror result.Converts this result into anOptionalof its error.Converts this result into aStreamof its error value.@NotNull ValueContainer<E>Converts this result into aValueContainerof its error value.Converts this result into anOptionalof its successful value.asStream()Converts this result into aStreamof its successful value.@NotNull ValueContainer<T>Converts this result into aValueContainerof its successful value.booleanerrorOrComputeDefault(@NonNull Function<? super T, ? extends @Any E> defaultErrorFactory) Gets the value of this result if this is asuccessfulotherwise returning the value computed by applying the given function to theerror value.errorOrDefault(@Any E defaultError) Gets the error of this result if this is anerrorotherwise returning default value.errorOrElseThrow(@NonNull Function<? super T, ? extends X> exceptionSupplier) Gets the error of this result throwingXgot by using the specified supplier if this is asuccessful result.errorOrGetDefault(@NonNull Supplier<? extends @Any E> defaultErrorSupplier) Gets the value of this result if this is anerrorotherwise returning the value got by using the specified supplier.Gets the error of this result if this is anerrorotherwise returningnull.Gets the value of this result throwing aResult.NotSuccessExceptionif this is anerror result.expectError(String message) Gets the error of this result throwing aResult.NotErrorExceptionif this is asuccessful result.Also known asandThen.voidhandle(@NonNull Consumer<? super T> successConsumer, @NonNull Consumer<? super @Any E> errorConsumer) Invokes the corresponding function depending on this result's type.inthashCode()voidInvokes the given function if this result is anerror result.voidInvokes the given function if this result is asuccessful result.booleanisError()Checks is this result is an error.booleanChecks is this result is successful.Maps the result if it issuccessfulreturning a new result with the result of mapping otherwise keeping theerror result.Maps the result if it is anerror resultreturning a new result with the result of mapping otherwise keeping theerror result.Returns this result if this is asuccessful resultotherwise returning the given result.orComputeDefault(@NonNull Function<? super @Any E, ? extends T> defaultValueFactory) Gets the value of this result if this is asuccessfulotherwise returning the value computed by applying the given function to theerror value.Gets the value of this result if this is asuccessfulotherwise returning default value.Maps the result if this is anerror resultreturning the result of mapping otherwise keeping thesuccessful result.orElseThrow(@NonNull Function<? super @Any E, ? extends X> exceptionFactory) Gets the value of this result throwingXgot by using the specified supplier if this is anerror result.orGetDefault(@NonNull Supplier<? extends T> defaultValueSupplier) Gets the value of this result if this is asuccessfulotherwise returning the value got by using the specified supplier.orNull()Gets the value of this result if this is asuccessfulotherwise returningnull.Consumes the result if it issuccessfulreturning the same result.Consumes the result if it is anerror resultreturning the same result.swap()Swaps this result making anerror resultfrom asuccessful resultand asuccessful resultfrom anerror result.toString()unwrap()Gets the value of this result throwing aResult.NotSuccessExceptionif this is anerror result.Gets the error of this result throwing aResult.NotErrorExceptionif this is asuccessful result.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface ru.progrm_jarvis.javacommons.object.Result
errorOrElseSneakyThrow, get, orElseSneakyThrow
-
Constructor Details
-
Success
-
-
Method Details
-
isSuccess
public boolean isSuccess()Description copied from interface:ResultChecks is this result is successful. -
isError
public boolean isError()Description copied from interface:ResultChecks is this result is an error. -
unwrap
Description copied from interface:ResultGets the value of this result throwing aResult.NotSuccessExceptionif this is anerror result. -
expect
Description copied from interface:ResultGets the value of this result throwing aResult.NotSuccessExceptionif this is anerror result.- Specified by:
expectin interfaceResult<T,E> - Parameters:
message- message to be specified toResult.NotSuccessException- Returns:
- successful value of this result
- See Also:
-
orElseThrow
public <X extends Throwable> T orElseThrow(@NonNull @NonNull Function<? super @Any E, ? extends X> exceptionFactory) Description copied from interface:ResultGets the value of this result throwingXgot by using the specified supplier if this is anerror result.- Specified by:
orElseThrowin interfaceResult<T,E> - Type Parameters:
X- type of exception thrown if this is anerror result- Parameters:
exceptionFactory- factory of a thrown exception consuming the error value of this result- Returns:
- successful value of this result
- See Also:
-
orDefault
Description copied from interface:ResultGets the value of this result if this is asuccessfulotherwise returning default value.- Specified by:
orDefaultin interfaceResult<T,E> - Parameters:
defaultValue- default value to be returned if this is anerror value- Returns:
- successful value if this a
successful resultordefaultValueotherwise
-
orNull
Description copied from interface:ResultGets the value of this result if this is asuccessfulotherwise returningnull.- Specified by:
orNullin interfaceResult<T,E> - Returns:
- successful value if this a
successful resultornullotherwise
-
orGetDefault
Description copied from interface:ResultGets the value of this result if this is asuccessfulotherwise returning the value got by using the specified supplier.- Specified by:
orGetDefaultin interfaceResult<T,E> - Parameters:
defaultValueSupplier- supplier of the default value to be returned if this is anerror value- Returns:
- successful value if this a
successful resultor got default otherwise
-
orComputeDefault
public T orComputeDefault(@NonNull @NonNull Function<? super @Any E, ? extends T> defaultValueFactory) Description copied from interface:ResultGets the value of this result if this is asuccessfulotherwise returning the value computed by applying the given function to theerror value.- Specified by:
orComputeDefaultin interfaceResult<T,E> - Parameters:
defaultValueFactory- factory used for creation of the default value to be returned if this is anerror value- Returns:
- successful value if this a
successful resultor the computed default otherwise
-
unwrapError
Description copied from interface:ResultGets the error of this result throwing aResult.NotErrorExceptionif this is asuccessful result.- Specified by:
unwrapErrorin interfaceResult<T,E> - Returns:
- error value of this result
- See Also:
-
expectError
Description copied from interface:ResultGets the error of this result throwing aResult.NotErrorExceptionif this is asuccessful result.- Specified by:
expectErrorin interfaceResult<T,E> - Parameters:
message- message to be specified toResult.NotErrorException- Returns:
- error value of this result
- See Also:
-
errorOrElseThrow
public <X extends Throwable> E errorOrElseThrow(@NonNull @NonNull Function<? super T, ? extends X> exceptionSupplier) throws XDescription copied from interface:ResultGets the error of this result throwingXgot by using the specified supplier if this is asuccessful result.- Specified by:
errorOrElseThrowin interfaceResult<T,E> - Type Parameters:
X- type of exception thrown if this is asuccessful result- Parameters:
exceptionSupplier- factory of a thrown exception consuming the successful value of this result- Returns:
- error value of this result
- Throws:
X- if this is anerror result- See Also:
-
errorOrDefault
Description copied from interface:ResultGets the error of this result if this is anerrorotherwise returning default value.- Specified by:
errorOrDefaultin interfaceResult<T,E> - Parameters:
defaultError- default value to be returned if this is ansuccessful result- Returns:
- error value if this an
error resultordefaultErrorotherwise
-
errorOrNull
Description copied from interface:ResultGets the error of this result if this is anerrorotherwise returningnull.- Specified by:
errorOrNullin interfaceResult<T,E> - Returns:
- error value if this an
error resultornullotherwise
-
errorOrGetDefault
Description copied from interface:ResultGets the value of this result if this is anerrorotherwise returning the value got by using the specified supplier.- Specified by:
errorOrGetDefaultin interfaceResult<T,E> - Parameters:
defaultErrorSupplier- supplier of the default error to be returned if this is asuccessful value- Returns:
- error value if this an
error resultor got default otherwise
-
errorOrComputeDefault
public E errorOrComputeDefault(@NonNull @NonNull Function<? super T, ? extends @Any E> defaultErrorFactory) Description copied from interface:ResultGets the value of this result if this is asuccessfulotherwise returning the value computed by applying the given function to theerror value.- Specified by:
errorOrComputeDefaultin interfaceResult<T,E> - Parameters:
defaultErrorFactory- factory used for creation of the default error to be returned if this is asuccessful value- Returns:
- successful value if this an
error resultor the computed default otherwise
-
ifSuccess
Description copied from interface:ResultInvokes the given function if this result is asuccessful result.- Specified by:
ifSuccessin interfaceResult<T,E> - Parameters:
successConsumer- consumer accepting thesuccessful value
-
ifError
Description copied from interface:ResultInvokes the given function if this result is anerror result.- Specified by:
ifErrorin interfaceResult<T,E> - Parameters:
errorConsumer- consumer accepting theerror value
-
handle
public void handle(@NonNull @NonNull Consumer<? super T> successConsumer, @NonNull @NonNull Consumer<? super @Any E> errorConsumer) Description copied from interface:ResultInvokes the corresponding function depending on this result's type.- Specified by:
handlein interfaceResult<T,E> - Parameters:
successConsumer- consumer accepting thesuccessful valueerrorConsumer- consumer accepting theerror value
-
map
@NotNull public <R> @NotNull Result<R,E> map(@NonNull @NonNull Function<? super T, ? extends R> mappingFunction) Description copied from interface:ResultMaps the result if it issuccessfulreturning a new result with the result of mapping otherwise keeping theerror result.- Specified by:
mapin interfaceResult<T,E> - Type Parameters:
R- type of the resulting successful value- Parameters:
mappingFunction- function to map the successful result- Returns:
- mapped successful result if it was a
successful resultor an error result if it was anerror result
-
peek
Description copied from interface:ResultConsumes the result if it issuccessfulreturning the same result. -
mapError
@NotNull public <@Any R> @NotNull Result<T,R> mapError(@NonNull @NonNull Function<? super @Any E, ? extends @Any R> mappingFunction) Description copied from interface:ResultMaps the result if it is anerror resultreturning a new result with the result of mapping otherwise keeping theerror result.- Specified by:
mapErrorin interfaceResult<T,E> - Type Parameters:
R- type of the resulting error value- Parameters:
mappingFunction- function to map the error result- Returns:
- mapped error result if it was an
an error resultor a successful result if it was asuccessful result
-
peekError
Description copied from interface:ResultConsumes the result if it is anerror resultreturning the same result. -
and
Description copied from interface:ResultReturns the given result if this is asuccessful resultotherwise keeping theerror result.- Specified by:
andin interfaceResult<T,E> - Type Parameters:
R- type of the resulting successful value- Parameters:
nextResult- result to be returned if this is asuccessful result- Returns:
nextResultif this is asuccessful resultor this error result otherwise- See Also:
-
flatMap
@NotNull public <R> @NotNull Result<R,E> flatMap(@NonNull @NonNull Function<? super T, ? extends @NotNull Result<R, @Any E>> mapper) Description copied from interface:ResultAlso known asandThen. Maps the result if this is asuccessful resultreturning the result of mapping otherwise keeping theerror result.- Specified by:
flatMapin interfaceResult<T,E> - Type Parameters:
R- type of the resulting successful value- Parameters:
mapper- function to create a new result fromcurrent successful one- Returns:
- mapped
successful resultif this wasthe oneor this error result otherwise - See Also:
-
or
@NotNull public <@Any R> @NotNull Result<T,R> or(@NonNull @NonNull Result<T, @Any R> alternateResult) Description copied from interface:ResultReturns this result if this is asuccessful resultotherwise returning the given result. -
orElse
@NotNull public <@Any R> @NotNull Result<T,R> orElse(@NonNull @NonNull Function<? super @Any E, ? extends @NotNull Result<T, @Any R>> mapper) Description copied from interface:ResultMaps the result if this is anerror resultreturning the result of mapping otherwise keeping thesuccessful result.- Specified by:
orElsein interfaceResult<T,E> - Type Parameters:
R- type of the resulting error value- Parameters:
mapper- function to create a new result fromcurrent error one- Returns:
- mapped
error resultif this wasthe oneor this successful result otherwise - See Also:
-
swap
Description copied from interface:ResultSwaps this result making anerror resultfrom asuccessful resultand asuccessful resultfrom anerror result.- Specified by:
swapin interfaceResult<T,E> - Returns:
error resultif this was asuccessful resultand asuccessful resultif this was anerror result
-
asOptional
Description copied from interface:ResultConverts this result into anOptionalof its successful value.- Specified by:
asOptionalin interfaceResult<T,E> - Returns:
optionalcontaining the value if this is asuccessful resultor anempty optionalotherwise
-
asErrorOptional
Description copied from interface:ResultConverts this result into anOptionalof its error.- Specified by:
asErrorOptionalin interfaceResult<T,E> - Returns:
optionalcontaining the error if this is anerror resultor anempty optionalotherwise
-
asValueContainer
Description copied from interface:ResultConverts this result into aValueContainerof its successful value.- Specified by:
asValueContainerin interfaceResult<T,E> - Returns:
value containercontaining the value if this is asuccessful resultor anempty value-containerotherwise
-
asErrorValueContainer
Description copied from interface:ResultConverts this result into aValueContainerof its error value.- Specified by:
asErrorValueContainerin interfaceResult<T,E> - Returns:
value containercontaining the error if this is anerror resultor anempty value-containerotherwise
-
asStream
Description copied from interface:ResultConverts this result into aStreamof its successful value.- Specified by:
asStreamin interfaceResult<T,E> - Returns:
streamof the value if this is asuccessful resultor anempty streamotherwise
-
asErrorStream
Description copied from interface:ResultConverts this result into aStreamof its error value.- Specified by:
asErrorStreamin interfaceResult<T,E> - Returns:
streamcontaining the error if this is anerror resultor anempty streamotherwise
-
equals
-
hashCode
public int hashCode() -
toString
-