Package net.groboclown.retval
Class WarningVal<T>
- java.lang.Object
-
- net.groboclown.retval.WarningVal<T>
-
- Type Parameters:
T- type of the underlying value.
- All Implemented Interfaces:
ProblemContainer,ValuedProblemContainer<T>
@Immutable public class WarningVal<T> extends java.lang.Object implements ValuedProblemContainer<T>
A container for a non-null value and associated problems. Reflects an object that, while valid, may have messages that the user should be made aware of.
-
-
Method Summary
All Methods Static 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.static <T> WarningVal<T>from(T value)Create the warning from a value with no problems.static <T> WarningVal<T>from(T value, ProblemContainer problems)Create a warning value with a collection (possibly empty) of problems.TgetValue()Get the underlying value object.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
-
from
@Nonnull public static <T> WarningVal<T> from(@Nonnull T value)
Create the warning from a value with no problems.- Type Parameters:
T- value type- Parameters:
value- value to store in the warning instance.- Returns:
- the warning
-
from
@Nonnull public static <T> WarningVal<T> from(@Nonnull T value, @Nonnull ProblemContainer problems)
Create a warning value with a collection (possibly empty) of problems.- Type Parameters:
T- value type- Parameters:
value- value to store in the warning instance.problems- collection of problems associated with the warning object.- Returns:
- the warning
-
getValue
@Nonnull public T getValue()
Get the underlying value object.- Specified by:
getValuein interfaceValuedProblemContainer<T>- Returns:
- the value
-
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.
-
-