Package net.groboclown.retval
Interface ProblemContainer
-
- All Known Subinterfaces:
RetNullable<T>,RetVal<T>,RetVoid,ValuedProblemContainer<T>
- All Known Implementing Classes:
MonitoredReturnProblem,MonitoredReturnValue,MonitoredRetVoidOk,ProblemCollector,SimpleReturnProblem,SimpleReturnValue,SimpleRetVoidOk,ValueAccumulator,ValueBuilder,WarningVal
public interface ProblemContainerAn object that contains problems.Some implementations may be immutable, while others aren't.
The API intentionally does not accept a generic problem container in many parts of the code as a way to push problems into other objects. Due to the checking mechanisms, care must be taken that values are not incorrectly lost.
-
-
Method Summary
All Methods Instance Methods Abstract 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.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.java.util.Collection<Problem>validProblems()Returns all contained problems in this object, but only if this object contains 1 or more problems.
-
-
-
Method Detail
-
isProblem
boolean isProblem()
Returns whether this object contains 1 or more problems.- Returns:
- true if there is a problem, false if there is no problem.
-
hasProblems
boolean hasProblems()
Returns whether this object contains 1 or more problems. Duplicate ofisProblem()for English readability.- Returns:
- true if there is a problem, false if there is no problem.
-
isOk
boolean isOk()
Returns whether this object contains zero problems.- Returns:
- true if there are no problems, false if there is a problem.
-
anyProblems
@Nonnull java.util.Collection<Problem> anyProblems()
Return 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.
- Returns:
- the problems contained in this container, even if there are none.
-
validProblems
@Nonnull java.util.Collection<Problem> validProblems()
Returns 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.
- Returns:
- the problems in this container, and the collection will contain at least 1 item.
- Throws:
java.lang.IllegalStateException- if this object has 0 problems.
-
debugProblems
@Nonnull java.lang.String debugProblems(@Nonnull 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. If this object contains no problems, then an empty string is returned instead.- 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
void joinProblemsWith(@Nonnull java.util.Collection<Problem> problemList)Add 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.- Parameters:
problemList- a modifiable collection of zero or more problems.
-
-