Class MonitoredReturnValue<T>
- java.lang.Object
-
- net.groboclown.retval.impl.MonitoredReturnValue<T>
-
- Type Parameters:
T- type of the contained value.
- All Implemented Interfaces:
ProblemContainer,RetNullable<T>,RetVal<T>,RetVoid,ValuedProblemContainer<T>
public class MonitoredReturnValue<T> extends java.lang.Object implements RetVal<T>, RetNullable<T>, RetVoid
Intended to be a version of the Ret* classes, with no error and a value.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Collection<Problem>anyProblems()Return all the problems in this object, even if the container is "ok".RetNullable<T>asNullable()Convert this instance into a nullable instance with the same value type.java.util.Optional<T>asOptional()Convert the value into an optional typed value.RetVoidconsume(java.util.function.Consumer<T> consumer)Pass the value of this instance to the consumer, only if there are no problems.RetVoidconsume(NonnullConsumer<T> consumer)Pass the value of this instance to the consumer, only if there are no problems.RetVoidconsumeIfNonnull(NonnullConsumer<T> consumer)If this value has a problem, then it is returned as aRetVoid.java.lang.StringdebugProblems(java.lang.String joinedWith)Return the problems as a single string, which combines theObject.toString()output of each problem with the given joining string parameter.RetVal<T>defaultAs(T defaultValue)Returns this object as aRetValif it is not null, otherwise a value with the returned value.<R> RetVal<R>defaultOrMap(R defaultValue, NonnullFunction<T,R> func)If this value has a problem, then it is returned.<V> RetNullable<V>forwardNullableProblems()Forward this instance as a nullable with a different value type, but only if it has problems.<V> MonitoredReturnValue<V>forwardProblems()Forward this object to a different typed RetVal instance.RetVoidforwardVoidProblems()Forward this instance as a value-less object, but only if it has problems.TgetValue()Get the value contained in this instance.booleanhasProblems()Returns whether this object contains 1 or more problems.booleanisOk()Returns whether this object contains zero problems.booleanisProblem()Returns whether this object contains 1 or more problems.voidjoinProblemsWith(java.util.Collection<Problem> problemList)Add all problems in this container into the argument.<R> RetVal<R>map(NonnullFunction<T,R> func)Return a non-nullRetValvalue, using a function that returns a non-null value, taking the current non-null value as an argument.<R> RetVal<R>map(NonnullReturnFunction<T,R> func)Return a non-nullRetValvalue, using a function that returns a non-null value, taking the current non-null value as an argument.<R> RetVal<R>map(NonnullSupplier<R> supplier)Return a non-nullRetValvalue using a supplier that returns a value.<R> RetNullable<R>mapNullable(java.util.function.Function<T,R> func)If this instance has no problems, then it runs the parameter with the current value.<R> RetNullable<R>mapNullable(java.util.function.Supplier<R> supplier)Return a non-nullRetNullablevalue using a supplier that returns a value.<R> RetNullable<R>mapNullable(NonnullParamFunction<T,R> func)If this instance has no problems, then it runs the parameter with the current value.<R> RetNullable<R>nullOrMap(NonnullParamFunction<T,R> func)If this value has a problem, then it is returned.<R> RetNullable<R>nullOrThenNullable(NonnullFunction<T,RetNullable<R>> func)If this value has a problem, then it is returned.RetVoidproduceVoid(NonnullFunction<T,RetVoid> func)Pass the value of this instance to the consumer, only if there are no problems.RetVoidproduceVoid(NonnullReturnFunction<T,RetVoid> func)Pass the value of this instance to the consumer, only if there are no problems.RetVoidproduceVoidIfNonnull(NonnullFunction<T,RetVoid> func)If this value has a problem, then it is returned as aRetVoid.RetVal<T>requireNonNull(Problem problem, Problem... problems)Require that this value contains a non-null value, otherwise produce a value with the problem arguments.java.util.Optional<T>requireOptional()Convert the value into an optional typed value only if there are no problems.Tresult()Get the result, which is always non-null.<R> RetVal<R>then(NonnullFunction<T,RetVal<R>> func)<R> RetVal<R>then(NonnullReturnFunction<T,RetVal<R>> func)<R> RetVal<R>then(NonnullSupplier<RetVal<R>> supplier)<R> RetNullable<R>thenNullable(NonnullFunction<T,RetNullable<R>> func)Return a non-nullRetNullablevalue using a function that itself returns aRetNullable, taking the current non-null value as an argument.<R> RetNullable<R>thenNullable(NonnullReturnFunction<T,RetNullable<R>> func)Return a non-nullRetNullablevalue using a function that itself returns aRetNullable, taking the current non-null value as an argument.<R> RetNullable<R>thenNullable(NonnullSupplier<RetNullable<R>> supplier)If there is no problem, run the supplier and return its value.MonitoredReturnValue<T>thenRun(java.lang.Runnable runner)Run the parameter, only if this instance has no problems.MonitoredReturnValue<T>thenRun(NonnullConsumer<T> consumer)Run the consumer with the current value, only if this instance has no problems.RetNullable<T>thenRunNullable(java.lang.Runnable runner)Run the parameter, only if this instance has no problems.RetNullable<T>thenRunNullable(java.util.function.Consumer<T> consumer)Run the consumer with the current value, only if this instance has no problems.RetNullable<T>thenValidate(java.util.function.Function<T,ProblemContainer> checker)Validate the value in the checker.RetVal<T>thenValidate(NonnullParamFunction<T,ProblemContainer> checker)Validate the value in the checker.RetVoidthenVoid(java.util.function.Consumer<T> consumer)Pass the value of this instance to the consumer, only if there are no problems.RetVoidthenVoid(NonnullConsumer<T> consumer)Pass the value of this instance to the consumer, only if there are no problems.RetVoidthenVoid(NonnullFunction<T,RetVoid> func)Pass the value of this instance to the function, only if there are no problems.RetVoidthenVoid(NonnullReturnFunction<T,RetVoid> func)Pass the value of this instance to the consumer, only if there are no problems.RetVoidthenVoid(NonnullSupplier<RetVoid> supplier)Return the supplier if there is no problem.java.lang.StringtoString()java.util.Collection<Problem>validProblems()Returns all contained problems in this object, but only if this object contains 1 or more problems.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.groboclown.retval.RetNullable
defaultOrThen, fromProblem, fromProblem, fromProblems, fromProblems, ok, result
-
Methods inherited from interface net.groboclown.retval.RetVal
fromProblem, fromProblem, fromProblems, fromProblems, ok
-
Methods inherited from interface net.groboclown.retval.RetVoid
fromProblem, fromProblem, fromProblems, fromProblems, ok
-
-
-
-
Method Detail
-
getValue
@Nullable public T getValue()
Description copied from interface:RetValGet the value contained in this instance. If this is an problem state, then the value will be null.This is usually helpful for log messages where a correctness check would impose extra runtime overhead that logging doesn't care about. This can also be used to return a simple value to other parts of a program that use null to indicate an invalid setup but that are separate from user notifications.
- Specified by:
getValuein interfaceRetNullable<T>- Specified by:
getValuein interfaceRetVal<T>- Specified by:
getValuein interfaceValuedProblemContainer<T>- Returns:
- the value, which will be null if there are problems.
-
asOptional
@Nonnull public java.util.Optional<T> asOptional()
Description copied from interface:RetValConvert the value into an optional typed value. Note that doing this will lose any problem state, so checking for problems should be done before calling this.This function has limited use. It's provided here to allow support for systems that use
Optionalvalues.- Specified by:
asOptionalin interfaceRetNullable<T>- Specified by:
asOptionalin interfaceRetVal<T>- Returns:
- the value as an optional type. No checks are made against the problem state.
-
result
public T result()
Description copied from interface:RetValGet the result, which is always non-null. If this instance has problems, then a runtime exception is thrown. Therefore, it's necessary to perform a validity check before calling.
-
requireOptional
@Nonnull public java.util.Optional<T> requireOptional()
Description copied from interface:RetValConvert the value into an optional typed value only if there are no problems.- Specified by:
requireOptionalin interfaceRetNullable<T>- Specified by:
requireOptionalin interfaceRetVal<T>- Returns:
- the value as an optional type. No checks are made against the problem state.
-
forwardProblems
@Nonnull public <V> MonitoredReturnValue<V> forwardProblems()
Description copied from interface:RetValForward this object to a different typed RetVal instance. This will only work when the instance has problems.The most common use case is when a value construction requires multiple steps, and an early step requires early exit from the function. This allows a memory efficient type casting of the problems to the construction function's type.
- Specified by:
forwardProblemsin interfaceRetNullable<T>- Specified by:
forwardProblemsin interfaceRetVal<T>- Specified by:
forwardProblemsin interfaceRetVoid- Type Parameters:
V- altered type.- Returns:
- the type-altered version
-
forwardNullableProblems
@Nonnull public <V> RetNullable<V> forwardNullableProblems()
Description copied from interface:RetValForward this instance as a nullable with a different value type, but only if it has problems. If it does not have problems, then a runtime exception is thrown.The most common use case is when a value construction requires multiple steps, and an early step requires early exit from the function. This allows a memory efficient type casting of the problems to the construction function's type.
- Specified by:
forwardNullableProblemsin interfaceRetNullable<T>- Specified by:
forwardNullableProblemsin interfaceRetVal<T>- Specified by:
forwardNullableProblemsin interfaceRetVoid- Type Parameters:
V- destination type- Returns:
- the value, only if this instance has problems.
-
forwardVoidProblems
@Nonnull public RetVoid forwardVoidProblems()
Description copied from interface:RetValForward this instance as a value-less object, but only if it has problems. If it does not have problems, then a runtime exception is thrown.The most common use case is when a value construction requires multiple steps, and an early step requires early exit from the function. This allows a memory efficient type casting of the problems to the construction function's type.
- Specified by:
forwardVoidProblemsin interfaceRetNullable<T>- Specified by:
forwardVoidProblemsin interfaceRetVal<T>- Specified by:
forwardVoidProblemsin interfaceRetVoid- Returns:
- the value, only if this instance has problems.
-
thenValidate
@Nonnull public RetVal<T> thenValidate(@Nonnull NonnullParamFunction<T,ProblemContainer> checker)
Description copied from interface:RetValValidate the value in the checker. The checker can perform any amount of validation against the value as necessary, and returns an optional container of problems. If no problem is found, the checker can return null. The checker is only invoked if the value has no current problems.Be careful with over-using this method.
ValueBuilderandProblemCollectorprovide better solutions for constructing validation problems within a method. This particular method finds practical use when a builder method returns an initially valid value, then another method performs cross-value validation.- Specified by:
thenValidatein interfaceRetVal<T>- Parameters:
checker- function that checks the validity of the value.- Returns:
- a retval with additional problems, or this value if no problem is found.
-
thenValidate
@Nonnull public RetNullable<T> thenValidate(@Nonnull java.util.function.Function<T,ProblemContainer> checker)
Description copied from interface:RetNullableValidate the value in the checker. The checker can perform any amount of validation against the value as necessary, and returns an optional container of problems. If no problem is found, the checker can return null.Be careful with over-using this method.
ValueBuilderandProblemCollectorprovide better solutions for constructing validation problems within a method. This particular method finds practical use when a builder method returns an initially valid value, then another method performs cross-value validation.- Specified by:
thenValidatein interfaceRetNullable<T>- Parameters:
checker- function that checks the validity of the value.- Returns:
- a retval with additional problems, or this value if no problem is found.
-
thenRunNullable
@Nonnull public RetNullable<T> thenRunNullable(@Nonnull java.lang.Runnable runner)
Description copied from interface:RetNullableRun the parameter, only if this instance has no problems.- Specified by:
thenRunNullablein interfaceRetNullable<T>- Parameters:
runner- the runnable to execute if no problems exist- Returns:
- this instance
-
thenRunNullable
@Nonnull public RetNullable<T> thenRunNullable(@Nonnull java.util.function.Consumer<T> consumer)
Description copied from interface:RetNullableRun the consumer with the current value, only if this instance has no problems.- Specified by:
thenRunNullablein interfaceRetNullable<T>- Parameters:
consumer- the consumer of this value to run if no problems exist- Returns:
- this instance.
-
asNullable
@Nonnull public RetNullable<T> asNullable()
Description copied from interface:RetValConvert this instance into a nullable instance with the same value type. If this instance has problems, they are returned. This differs fromRetVal.forwardNullableProblems()by 1. keeping the same type, and 2. allowing for a non-problem state in the returned value.A convenience function for situations where a receiver can expect valid uses of a null value when the source is known to never return a null value.
- Specified by:
asNullablein interfaceRetVal<T>- Returns:
- a nullable version of the same instance.
-
then
@Nonnull public <R> RetVal<R> then(@Nonnull NonnullFunction<T,RetVal<R>> func)
Description copied from interface:RetValReturn a non-nullRetValvalue using a function that itself returns aRetVal, taking the current non-nullable value as an argument. The function is called only if this object has no problem. If it has a problem, then the current list of problems is returned as the new type.This is similar to
RetVal.map(NonnullFunction), but logically different. This method implies the functional argument will use the value and perform new processing to create a different value.- Specified by:
thenin interfaceRetVal<T>- Type Parameters:
R- type of the returned value.- Parameters:
func- functional object that returns a RetVal and takes the current value as argument.- Returns:
- the problems of the current value, or the object returned by the function if there are no problems (but the returned value may have its own set of problems).
-
then
@Nonnull public <R> RetVal<R> then(@Nonnull NonnullReturnFunction<T,RetVal<R>> func)
Description copied from interface:RetNullableReturn a non-nullRetValvalue using a function that itself returns aRetVal, taking the current non-nullable value as an argument. The function is called only if this object has no problem. If it has a problem, then the current list of problems is returned as the new type.This is similar to
RetNullable.map(NonnullReturnFunction), but logically different. This method implies the functional argument will use the value and perform new processing to create a different value.- Specified by:
thenin interfaceRetNullable<T>- Type Parameters:
R- type of the returned value.- Parameters:
func- functional object that returns a RetVal and takes the current value as argument.- Returns:
- the problems of the current value, or the object returned by the function if there are no problems (but the returned value may have its own set of problems).
-
then
@Nonnull public <R> RetVal<R> then(@Nonnull NonnullSupplier<RetVal<R>> supplier)
Description copied from interface:RetVoid
-
map
@Nonnull public <R> RetVal<R> map(@Nonnull NonnullSupplier<R> supplier)
Description copied from interface:RetVoidReturn a non-nullRetValvalue using a supplier that returns a value. The supplier is called only if this object has no problem.Formally, this doesn't "map" one value to another. However, for symmetry with the other Ret classes, it is here called map.
-
map
@Nonnull public <R> RetVal<R> map(@Nonnull NonnullReturnFunction<T,R> func)
Description copied from interface:RetNullableReturn a non-nullRetValvalue, using a function that returns a non-null value, taking the current non-null value as an argument. The function is called only if this object has no problem. If it has a problem, then the current list of problems is returned as the new type.This is similar to
RetNullable.then(NonnullReturnFunction), but logically different. This method implies the functional argument performs a transformation of the data type into another one without validation checks.- Specified by:
mapin interfaceRetNullable<T>- Type Parameters:
R- type of the returned value.- Parameters:
func- functional object that takes the current value as argument, and returns a transformed value.- Returns:
- the problem of the current value, if it is a problem, or the object returned by the function.
-
map
@Nonnull public <R> RetVal<R> map(@Nonnull NonnullFunction<T,R> func)
Description copied from interface:RetValReturn a non-nullRetValvalue, using a function that returns a non-null value, taking the current non-null value as an argument. The function is called only if this object has no problem. If it has a problem, then the current list of problems is returned as the new type.This is similar to
RetVal.then(NonnullFunction), but logically different. This method implies the functional argument performs a transformation of the data type into another one without validation checks.- Specified by:
mapin interfaceRetVal<T>- Type Parameters:
R- type of the returned value.- Parameters:
func- functional object that takes the current value as argument, and returns a transformed value.- Returns:
- the problem of the current value, if it is an problem, or the object returned by the function.
-
thenNullable
@Nonnull public <R> RetNullable<R> thenNullable(@Nonnull NonnullReturnFunction<T,RetNullable<R>> func)
Description copied from interface:RetNullableReturn a non-nullRetNullablevalue using a function that itself returns aRetNullable, taking the current non-null value as an argument. The function is called only if this object has no problem.This is similar to
RetNullable.mapNullable(Function), but logically different. This method implies the functional argument will use the value and perform new processing to create a different value.- Specified by:
thenNullablein interfaceRetNullable<T>- Type Parameters:
R- type of the returned value.- Parameters:
func- functional object that returns a RetNullable and takes the current value as argument.- Returns:
- the problem of the current value, if it is a problem, or the object returned by the supplier.
-
thenNullable
@Nonnull public <R> RetNullable<R> thenNullable(@Nonnull NonnullFunction<T,RetNullable<R>> func)
Description copied from interface:RetValReturn a non-nullRetNullablevalue using a function that itself returns aRetNullable, taking the current non-null value as an argument. The function is called only if this object has no problem.This is similar to
RetVal.mapNullable(NonnullParamFunction), but logically different. This method implies the functional argument will use the value and perform new processing to create a different value.- Specified by:
thenNullablein interfaceRetVal<T>- Type Parameters:
R- type of the returned value.- Parameters:
func- functional object that returns a RetNullable and takes the current value as argument.- Returns:
- the problem of the current value, if it is a problem, or the object returned by the supplier.
-
thenNullable
@Nonnull public <R> RetNullable<R> thenNullable(@Nonnull NonnullSupplier<RetNullable<R>> supplier)
Description copied from interface:RetVoidIf there is no problem, run the supplier and return its value. Otherwise, return this object's problems.- Specified by:
thenNullablein interfaceRetVoid- Type Parameters:
R- return value type- Parameters:
supplier- supplier of the return value; run only if this object has no problems.- Returns:
- the problems in this object, or the supplier's return value.
-
mapNullable
@Nonnull public <R> RetNullable<R> mapNullable(@Nonnull NonnullParamFunction<T,R> func)
Description copied from interface:RetValIf this instance has no problems, then it runs the parameter with the current value. The returned value, which may be null, is wrapped in a nullable value. If this instance has problems, then the problem list is returned and the parameter is not run.This is similar to
RetVal.thenNullable(NonnullFunction), but logically different. This method implies the functional argument performs a transformation of the data type into another one without validation checks.- Specified by:
mapNullablein interfaceRetVal<T>- Type Parameters:
R- return value type- Parameters:
func- the function to run.- Returns:
- a transformed version of this object.
-
mapNullable
@Nonnull public <R> RetNullable<R> mapNullable(@Nonnull java.util.function.Function<T,R> func)
Description copied from interface:RetNullableIf this instance has no problems, then it runs the parameter with the current value. The returned value, which may be null, is wrapped in a nullable value. If this instance has problems, then the problem list is returned and the parameter is not run.This is similar to
RetNullable.thenNullable(NonnullReturnFunction), but logically different. This method implies the functional argument performs a transformation of the data type into another one without validation checks.- Specified by:
mapNullablein interfaceRetNullable<T>- Type Parameters:
R- return value type- Parameters:
func- the function to run.- Returns:
- a transformed version of this object.
-
mapNullable
@Nonnull public <R> RetNullable<R> mapNullable(@Nonnull java.util.function.Supplier<R> supplier)
Description copied from interface:RetVoidReturn a non-nullRetNullablevalue using a supplier that returns a value. The supplier is called only if this object has no problem.Formally, this doesn't "map" one value to another. However, for symmetry with the other Ret classes, it is here called map.
- Specified by:
mapNullablein interfaceRetVoid- Type Parameters:
R- return value type- Parameters:
supplier- functional object that returns a non-null value.- Returns:
- a RetVal, either a problem if this object has an problem, or the value returned by the supplier.
-
thenRun
@Nonnull public MonitoredReturnValue<T> thenRun(@Nonnull java.lang.Runnable runner)
Description copied from interface:RetValRun the parameter, only if this instance has no problems.
-
thenRun
@Nonnull public MonitoredReturnValue<T> thenRun(@Nonnull NonnullConsumer<T> consumer)
Description copied from interface:RetValRun the consumer with the current value, only if this instance has no problems.
-
thenVoid
@Nonnull public RetVoid thenVoid(@Nonnull NonnullSupplier<RetVoid> supplier)
Description copied from interface:RetVoidReturn the supplier if there is no problem.
-
thenVoid
@Nonnull public RetVoid thenVoid(@Nonnull java.util.function.Consumer<T> consumer)
Description copied from interface:RetNullablePass the value of this instance to the consumer, only if there are no problems. Return a void version of this instance.A note about usage: if the argument is a lambda that ignores the argument, then the compiler will fail due to an ambiguous call. There exist some use cases where the argument value is no longer needed and can be safely ignored; for those scenarios, use
RetNullable.consume(Consumer).This call will lose the contained value on return, so it's used to pass on the value to another object.
- Specified by:
thenVoidin interfaceRetNullable<T>- Parameters:
consumer- consumer of this value.- Returns:
- a response that contains the problem state of the current value.
-
thenVoid
@Nonnull public RetVoid thenVoid(@Nonnull NonnullReturnFunction<T,RetVoid> func)
Description copied from interface:RetNullablePass the value of this instance to the consumer, only if there are no problems. Return the function's value.A note about usage: if the argument is a lambda that ignores the argument, then the compiler will fail due to an ambiguous call. There exist some use cases where the argument value is no longer needed and can be safely ignored; for those scenarios, use
RetNullable.produceVoid(NonnullReturnFunction).This call will lose the contained value on return, so it's used to pass on the value to another object.
- Specified by:
thenVoidin interfaceRetNullable<T>- Parameters:
func- consumer of this value.- Returns:
- a response that contains the problem state of the current value.
-
thenVoid
@Nonnull public RetVoid thenVoid(@Nonnull NonnullConsumer<T> consumer)
Description copied from interface:RetValPass the value of this instance to the consumer, only if there are no problems. Return a void version of this instance.A note about usage: if the argument is a lambda that ignores the argument, then the compiler will fail due to an ambiguous call. There exist some use cases where the argument value is no longer needed and can be safely ignored; for those scenarios, use
RetVal.consume(NonnullConsumer).This call will lose the contained value on return, so it's used to pass on the value to another object.
-
thenVoid
@Nonnull public RetVoid thenVoid(@Nonnull NonnullFunction<T,RetVoid> func)
Description copied from interface:RetValPass the value of this instance to the function, only if there are no problems. Return a void version of this instance if there are problems with it, or the return value from the function.A note about usage: if the argument is a lambda that ignores the argument, then the compiler will fail due to an ambiguous call. There exist some use cases where the argument value is no longer needed and can be safely ignored; for those scenarios, use
RetVal.produceVoid(NonnullFunction).This call will lose the contained value on return, so it's used to pass on the value to another object.
-
consume
@Nonnull public RetVoid consume(@Nonnull java.util.function.Consumer<T> consumer)
Description copied from interface:RetNullablePass the value of this instance to the consumer, only if there are no problems. Return a void version of this instance.This call will lose the contained value on return, so it's used to pass on the value to another object.
- Specified by:
consumein interfaceRetNullable<T>- Parameters:
consumer- consumer of this value.- Returns:
- a response that contains the problem state of the current value.
-
consume
@Nonnull public RetVoid consume(@Nonnull NonnullConsumer<T> consumer)
Description copied from interface:RetValPass the value of this instance to the consumer, only if there are no problems. Return a void version of this instance.This call will lose the contained value on return, so it's used to pass on the value to another object.
-
produceVoid
@Nonnull public RetVoid produceVoid(@Nonnull NonnullReturnFunction<T,RetVoid> func)
Description copied from interface:RetNullablePass the value of this instance to the consumer, only if there are no problems. Return the function's value.This call will lose the contained value on return, so it's used to pass on the value to another object.
- Specified by:
produceVoidin interfaceRetNullable<T>- Parameters:
func- consumer of this value.- Returns:
- a response that contains the problem state of the current value.
-
produceVoid
@Nonnull public RetVoid produceVoid(@Nonnull NonnullFunction<T,RetVoid> func)
Description copied from interface:RetValPass the value of this instance to the consumer, only if there are no problems. Return the function's value.This call will lose the contained value on return, so it's used to pass on the value to another object.
- Specified by:
produceVoidin interfaceRetVal<T>- Parameters:
func- consumer of this value.- Returns:
- a response that contains the problem state of the current value.
-
requireNonNull
@Nonnull public RetVal<T> requireNonNull(@Nonnull Problem problem, @Nonnull Problem... problems)
Description copied from interface:RetNullableRequire that this value contains a non-null value, otherwise produce a value with the problem arguments. If this value already has a problem, the arguments are ignored.- Specified by:
requireNonNullin interfaceRetNullable<T>- Parameters:
problem- problem to report if the value is null.problems- optional other problems to report if the value is null.- Returns:
- if non-null, return this value, otherwise the problem arguments.
-
defaultAs
@Nonnull public RetVal<T> defaultAs(@Nonnull T defaultValue)
Description copied from interface:RetNullableReturns this object as aRetValif it is not null, otherwise a value with the returned value. If this value has a problem, that is still returned.- Specified by:
defaultAsin interfaceRetNullable<T>- Parameters:
defaultValue- value to use if this object contains a null value.- Returns:
- the value with a non-null result, using the parameter if this object contains a null value.
-
consumeIfNonnull
@Nonnull public RetVoid consumeIfNonnull(@Nonnull NonnullConsumer<T> consumer)
Description copied from interface:RetNullableIf this value has a problem, then it is returned as aRetVoid. If it contains a null value, then the equivalent ofRetVoid.ok()is returned. Otherwise, the consumer is called with the value, andRetVoid.ok()is returned.- Specified by:
consumeIfNonnullin interfaceRetNullable<T>- Parameters:
consumer- consumer called with the value if there are no problems and the value is non-null.- Returns:
- the problems or a problem-free void value.
-
produceVoidIfNonnull
@Nonnull public RetVoid produceVoidIfNonnull(@Nonnull NonnullFunction<T,RetVoid> func)
Description copied from interface:RetNullableIf this value has a problem, then it is returned as aRetVoid. If it contains a null value, then the equivalent ofRetVoid.ok()is returned. Otherwise, the consumer is called with the value, andRetVoid.ok()is returned.- Specified by:
produceVoidIfNonnullin interfaceRetNullable<T>- Parameters:
func- called with the value if there are no problems and the value is non-null, and the return value is returned by this call.- Returns:
- the problems or a problem-free void value.
-
defaultOrMap
@Nonnull public <R> RetVal<R> defaultOrMap(@Nonnull R defaultValue, @Nonnull NonnullFunction<T,R> func)
Description copied from interface:RetNullableIf this value has a problem, then it is returned. If the stored value is null, then defaultValue is returned. If the stored value is non-null, then it is passed to the function and returned.- Specified by:
defaultOrMapin interfaceRetNullable<T>- Type Parameters:
R- mapped-to value type- Parameters:
defaultValue- value to return if the stored value is null.func- function to process the stored value if it is non-null.- Returns:
- this value's problems, or the mapped-to value, or the default value.
-
nullOrMap
@Nonnull public <R> RetNullable<R> nullOrMap(@Nonnull NonnullParamFunction<T,R> func)
Description copied from interface:RetNullableIf this value has a problem, then it is returned. If the stored value is null, then null is returned. If the stored value is non-null, then it is passed to the function and returned.- Specified by:
nullOrMapin interfaceRetNullable<T>- Type Parameters:
R- mapped-to value type- Parameters:
func- function to process the stored value if it is non-null.- Returns:
- this value's problems, or the mapped-to value, or the default value.
-
nullOrThenNullable
@Nonnull public <R> RetNullable<R> nullOrThenNullable(@Nonnull NonnullFunction<T,RetNullable<R>> func)
Description copied from interface:RetNullableIf this value has a problem, then it is returned. If the stored value is null, then null is returned. If the stored value is non-null, then it is passed to the function and returned.- Specified by:
nullOrThenNullablein interfaceRetNullable<T>- Type Parameters:
R- mapped-to value type- Parameters:
func- function to process the stored value if it is non-null.- Returns:
- this value's problems, or the mapped-to value, or the default value.
-
hasProblems
public boolean hasProblems()
Description copied from interface:ProblemContainerReturns whether this object contains 1 or more problems. Duplicate ofProblemContainer.isProblem()for English readability.- Specified by:
hasProblemsin interfaceProblemContainer- Returns:
- true if there is a problem, false if there is no problem.
-
isProblem
public boolean isProblem()
Description copied from interface:ProblemContainerReturns whether this object contains 1 or more problems.- Specified by:
isProblemin interfaceProblemContainer- Returns:
- true if there is a problem, false if there is no problem.
-
isOk
public boolean isOk()
Description copied from interface:ProblemContainerReturns whether this object contains zero problems.- Specified by:
isOkin interfaceProblemContainer- Returns:
- true if there are no problems, false if there is a problem.
-
anyProblems
@Nonnull public java.util.Collection<Problem> anyProblems()
Description copied from interface:ProblemContainerReturn all the problems in this object, even if the container is "ok".Generally, this combines the problems in this instance with a larger collection, which can itself be used to check if any of the values had problems.
The returned collection is read-only, and contains no null values.
- Specified by:
anyProblemsin interfaceProblemContainer- Returns:
- the problems contained in this container, even if there are none.
-
validProblems
@Nonnull public java.util.Collection<Problem> validProblems()
Description copied from interface:ProblemContainerReturns all contained problems in this object, but only if this object contains 1 or more problems. If it contains 0, then this throws anIllegalStateException.The returned collection is read-only, and contains no null values.
- Specified by:
validProblemsin interfaceProblemContainer- Returns:
- the problems in this container, and the collection will contain at least 1 item.
-
debugProblems
@Nonnull public java.lang.String debugProblems(@Nonnull java.lang.String joinedWith)Description copied from interface:ProblemContainerReturn the problems as a single string, which combines theObject.toString()output of each problem with the given joining string parameter. If this object contains no problems, then an empty string is returned instead.- Specified by:
debugProblemsin interfaceProblemContainer- Parameters:
joinedWith- the text to join multiple problem strings together.- Returns:
- the combined text of the problems, or an empty string if there are no problems.
-
joinProblemsWith
public void joinProblemsWith(@Nonnull java.util.Collection<Problem> problemList)Description copied from interface:ProblemContainerAdd all problems in this container into the argument. This has a very specific usage to indicate that this container, even if it has no problems, is part of a bigger issue. Therefore, this is fine to call even if there are no problems in this container.- Specified by:
joinProblemsWithin interfaceProblemContainer- Parameters:
problemList- a modifiable collection of zero or more problems.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-