Interface RetVoid
-
- All Superinterfaces:
ProblemContainer
- All Known Implementing Classes:
MonitoredReturnProblem,MonitoredReturnValue,MonitoredRetVoidOk,SimpleReturnProblem,SimpleRetVoidOk
@Immutable public interface RetVoid extends ProblemContainer
A simple returnable that can have problems, but no value.Because these instances have no value, they allow for more flexibility in their functionality than the other classes.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description <V> RetNullable<V>forwardNullableProblems()Forward this instance as a nullable with a value type, but only if it has problems.<V> RetVal<V>forwardProblems()Forward this object to a typed RetVal instance.RetVoidforwardVoidProblems()Forward this instance as a value-less object, but only if it has problems.static RetVoidfromProblem(java.util.Collection<Problem> problemSet, java.util.Collection<Problem>... problemSets)Constructs aRetVoidinstance with the collections of problems.static RetVoidfromProblem(Problem problem, Problem... problems)Create a RetVoid containing the passed-in problems.static RetVoidfromProblems(java.util.Collection<ProblemContainer> retSet, java.util.Collection<ProblemContainer>... retSets)Create a RetVoid containing the passed-in problems.static RetVoidfromProblems(ProblemContainer ret, ProblemContainer... rets)Create a RetVoid containing the passed-in problems.<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.Supplier<R> supplier)Return a non-nullRetNullablevalue using a supplier that returns a value.static RetVoidok()Return a void object with no problems.<R> RetVal<R>then(NonnullSupplier<RetVal<R>> supplier)<R> RetNullable<R>thenNullable(NonnullSupplier<RetNullable<R>> supplier)If there is no problem, run the supplier and return its value.RetVoidthenRun(java.lang.Runnable runnable)Run the runnable if there is no problem.RetVoidthenVoid(NonnullSupplier<RetVoid> supplier)Return the supplier if there is no problem.-
Methods inherited from interface net.groboclown.retval.ProblemContainer
anyProblems, debugProblems, hasProblems, isOk, isProblem, joinProblemsWith, validProblems
-
-
-
-
Method Detail
-
ok
@Nonnull static RetVoid ok()
Return a void object with no problems.- Returns:
- a no-problem void object.
-
fromProblem
@SafeVarargs @Nonnull static RetVoid fromProblem(@Nonnull java.util.Collection<Problem> problemSet, @Nonnull java.util.Collection<Problem>... problemSets)
Constructs aRetVoidinstance with the collections of problems. This is optimized to reduce the memory load where easy. If the collection of problems has no values, then an OK value is returned instead.- Parameters:
problemSet- first collection of problemsproblemSets- vararg optional problems that should be included in this object.- Returns:
- a RetVoid with all the given problems.
-
fromProblem
@Nonnull static RetVoid fromProblem(@Nullable Problem problem, Problem... problems)
Create a RetVoid containing the passed-in problems. If there was no problem in any of the arguments, then this will return a no-problem value.- Parameters:
problem- initial problemproblems- vararg optional list of problems.- Returns:
- a new void instance, possibly without problems.
-
fromProblems
@SafeVarargs @Nonnull static RetVoid fromProblems(@Nonnull java.util.Collection<ProblemContainer> retSet, @Nonnull java.util.Collection<ProblemContainer>... retSets)
Create a RetVoid containing the passed-in problems. If there was no problem in any of the arguments, then this will return a no-problem value.- Parameters:
retSet- primary collection of problem containers.retSets- vararg optional problem container collections.- Returns:
- a new void instance, possibly without problems.
-
fromProblems
@Nonnull static RetVoid fromProblems(@Nullable ProblemContainer ret, @Nonnull ProblemContainer... rets)
Create a RetVoid containing the passed-in problems. If there was no problem in any of the arguments, then this will return a no-problem value.- Parameters:
ret- a problem containerrets- an optional list of problem containers.- Returns:
- a new void instance, possibly without problems.
-
then
@Nonnull <R> RetVal<R> then(@Nonnull NonnullSupplier<RetVal<R>> supplier)
Return a non-nullRetValvalue using a supplier that itself returns aRetVal. The supplier is called only if this object has no problem.- Type Parameters:
R- type of the returned value.- Parameters:
supplier- functional object that returns a RetVal.- Returns:
- the problem of the current value, if it is a problem, or the object returned by the supplier.
-
map
@Nonnull <R> RetVal<R> map(@Nonnull NonnullSupplier<R> supplier)
Return 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.
- 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 a problem, or the value returned by the supplier.
-
thenNullable
@Nonnull <R> RetNullable<R> thenNullable(@Nonnull NonnullSupplier<RetNullable<R>> supplier)
If there is no problem, run the supplier and return its value. Otherwise, return this object's problems.- 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 <R> RetNullable<R> mapNullable(@Nonnull java.util.function.Supplier<R> supplier)
Return 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.
- 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.
-
thenVoid
@Nonnull RetVoid thenVoid(@Nonnull NonnullSupplier<RetVoid> supplier)
Return the supplier if there is no problem.- Parameters:
supplier- function to run- Returns:
- this object if there are problems in this object, otherwise the supplier's return value.
-
thenRun
@Nonnull RetVoid thenRun(@Nonnull java.lang.Runnable runnable)
Run the runnable if there is no problem.- Parameters:
runnable- function to run- Returns:
- this object.
-
forwardProblems
@Nonnull <V> RetVal<V> forwardProblems()
Forward this object to a 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.
- Type Parameters:
V- altered type.- Returns:
- the type-altered version
- Throws:
java.lang.IllegalStateException- if this instance does not have problems.
-
forwardNullableProblems
@Nonnull <V> RetNullable<V> forwardNullableProblems()
Forward this instance as a nullable with a 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.
- Type Parameters:
V- destination type- Returns:
- the value, only if this instance has problems.
-
forwardVoidProblems
@Nonnull RetVoid forwardVoidProblems()
Forward 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.
- Returns:
- the value, only if this instance has problems.
-
-