Class MonitoredRetVoidOk
- java.lang.Object
-
- net.groboclown.retval.impl.MonitoredRetVoidOk
-
- All Implemented Interfaces:
ProblemContainer,RetVoid
public class MonitoredRetVoidOk extends java.lang.Object implements RetVoid
Monitored version of RetVal with an ok state (no problems).
-
-
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".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.<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.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(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.<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.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.RetVoid
fromProblem, fromProblem, fromProblems, fromProblems, ok
-
-
-
-
Method Detail
-
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.
-
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.
-
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.
-
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.
-
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 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.
-
thenVoid
@Nonnull public RetVoid thenVoid(@Nonnull NonnullSupplier<RetVoid> supplier)
Description copied from interface:RetVoidReturn the supplier if there is no problem.
-
thenRun
@Nonnull public RetVoid thenRun(@Nonnull java.lang.Runnable runnable)
Description copied from interface:RetVoidRun the runnable if there is no problem.
-
forwardProblems
@Nonnull public <V> RetVal<V> forwardProblems()
Description copied from interface:RetVoidForward 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.
- 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:RetVoidForward 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.
- 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:RetVoidForward 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 interfaceRetVoid- Returns:
- the value, only if this instance has problems.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-