Class Problem
- Direct Known Subclasses:
Unchecked
Class used for describing errors and other issues with user defined input. Problems are hierarchical, which
is used to 'target' where issues are found, e.g. a problem with your function that is in your model that is in your
project might have three levels, e.g. There was a problem in your project... -> There was a problem with your
model... -> The function 'hazard-calculator' does not exist
This code is going through a 'transition' phase as it moves away from free form messages to something more structured and linked to the i18n system. Over time, we should: * purge all the code related to default messages * use annotations to apply structure to the various args, e.g. an 'expected' and 'actual' argument
See Problems for tips on constructing Problems.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.use the ProblemCode-based constructor insteadProblem(List<Problem> children, ProblemCode code, Object... args) Problem(Problem.Severity severity, String message) Deprecated.use the ProblemCode-based constructor insteadProblem(Problem.Severity severity, String message, Object[] args, Throwable t) Deprecated.use the ProblemCode-based constructor insteadProblem(Problem.Severity severity, String defaultMessageFormat, Object[] arguments, Throwable exception, ProblemCode code, nz.org.riskscape.problem.Problem.AffectedMetadata affected, Problems children) Creates a newProbleminstance.Problem(Problem.Severity severity, ProblemCode code, Object... args) Same aserror(ProblemCode, Object...), but where you need to use a different severity, e.g. -
Method Summary
Modifier and TypeMethodDescriptionCopy this Problem but add details of the specific thing that the problem affects.booleanprotected booleanstatic ProblemDeprecated.use the ProblemCode-based constructor insteadstatic ProblemDeprecated.use the ProblemCode-based constructor insteadstatic StringdebugString(List<Problem> problems) Variation ofdebugString(Problem)that dumps out a list of problemsstatic StringdebugString(Problem origin) booleanstatic ProblemDeprecated.use the ProblemCode-based constructor insteadstatic ProblemDeprecated.use the ProblemCode-based constructor insteadstatic Problemerror(ProblemCode code, Object... args) Create an problem withProblem.Severity.ERRORwith a particularProblemCodeand message arguments.static ProblemDeprecated.use the ProblemCode-based constructor insteadfilterAffected(Collection<? extends Problem> problems, Class<?> contextClass) Filters the list of Problems (and their children) based on the affected class, e.g.Finds any exception info related to this problem, including exceptions that may have been caught by child/nested Problems<T> Optional<T>getAffected(Class<T> classOfThing) With Problems, there is usually something this is most affected by the Problem, e.g.Class<?>Object[]getCode()booleanstatic booleanhasErrors(Collection<? extends Problem> problems) inthashCode()static ProblemDeprecated.use the ProblemCode-based constructor insteadbooleanisEmpty()booleanisError()booleanisFatal()booleaniterator()static Problem.Severitymax(Collection<? extends Problem> children) setChildren(List<Problem> newChildren) Copy this Problem but replace the children.stream()static <T extends Throwable>
voidtoList()Convert this Problems in to a (possibly empty) list of ProblemsConvert this Problems in to a single problem, or empty if this is Problems.NONEtoString()static ProblemDeprecated.use the ProblemCode-based constructor insteadstatic ProblemDeprecated.use the ProblemCode-based constructor insteadwithChildren(List<? extends Problem> moreChildren) Copy this Problem but add in more children.withChildren(Problems... moreChildren) Copy this Problem but with a new exceptionCopy this Problem but with a new severitystatic nz.org.riskscape.problem.Problem.AffectedMetadatawrapAffectedObject(Object thing) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
severity
-
-
Constructor Details
-
Problem
Deprecated.use the ProblemCode-based constructor instead -
Problem
Deprecated.use the ProblemCode-based constructor instead -
Problem
@Deprecated public Problem(List<Problem> children, Problem.Severity severity, String message, Object[] args) Deprecated.use the ProblemCode-based constructor instead -
Problem
Same as
error(ProblemCode, Object...), but where you need to use a different severity, e.g. INFO, WARNING, etc. -
Problem
-
Problem
public Problem(Problem.Severity severity, String defaultMessageFormat, Object[] arguments, Throwable exception, ProblemCode code, nz.org.riskscape.problem.Problem.AffectedMetadata affected, Problems children) Creates a new
Probleminstance.- Parameters:
severity-defaultMessageFormat- Stores the unformatted message string that will be used as the default message (i.e. if the i18n lookup fails to find a better message). Note that this is in String format (rather than MessageFormat format).arguments-exception-code-affected- Basic metadata about what this specific problem affects, e.g. is it a problem with a Bookmark, or Parameter, or Expression, etc.children-
-
-
Method Details
-
wrapAffectedObject
-
info
Deprecated.use the ProblemCode-based constructor instead -
warning
Deprecated.use the ProblemCode-based constructor instead -
warning
Deprecated.use the ProblemCode-based constructor instead -
error
Deprecated.use the ProblemCode-based constructor instead -
error
Deprecated.use the ProblemCode-based constructor instead -
fatal
Deprecated.use the ProblemCode-based constructor instead -
composite
Deprecated.use the ProblemCode-based constructor insteadBuilds a
Problemthat contains the childProblems.The level of the the returned
Problemis the most severe from those of the children.- Parameters:
children- the problems the new Problem should wrap
-
composite
@Deprecated public static Problem composite(Problem.Severity severity, List<Problem> children, String message, Object... args) Deprecated.use the ProblemCode-based constructor insteadBuilds a
Problemthat contains the childProblems, forcing a particular severity for the created parent.- Parameters:
children- the problems the new Problem should wrap
-
error
Create an problem with
Problem.Severity.ERRORwith a particularProblemCodeand message arguments. -
max
-
hasErrors
-
throwIfErrors
public static <T extends Throwable> void throwIfErrors(List<Problem> problems, Function<List<Problem>, T> supplier) throws T- Throws:
T extends Throwable
-
withChildren
-
withChildren
Copy this Problem but add in more children.
-
setChildren
Copy this Problem but replace the children.
-
withSeverity
Copy this Problem but with a new severity
-
withException
Copy this Problem but with a new exception
-
affecting
Copy this Problem but add details of the specific thing that the problem affects. E.g. the specific Parameter or pipeline Step affected, etc. Note that there are several variants as in some cases we may know the class and name but not have an object, whereas other cases may have an object but no name.
-
affecting
-
isError
public boolean isError() -
isFatal
public boolean isFatal() -
hasChildren
public boolean hasChildren() -
getMessage
-
getDefaultMessage
-
getAffectedName
- Returns:
- the name of the thing affected by this Problem (or an empty String if there is no such context associated with it)
-
getAffectedObject
- Returns:
- the thing affected by this Problem, e.g. the Parameter object. Returns Optional.empty() if there is no specific object affected.
-
getAffectedClass
- Returns:
- the class of thing affected by this Problem, e.g. Parameter.class. Returns Object.class if this is unknown.
-
affects
- Returns:
- true if the Problem affects the given class or superclass
-
getAffected
With Problems, there is usually something this is most affected by the Problem, e.g. a Parameter or a File or a Bookmark. This checks if this Problem affects the class given, and if so, returns that thing. E.g. 'I know this Problem affects a File, gimme the File'.
-
filterAffected
public static List<Problem> filterAffected(Collection<? extends Problem> problems, Class<?> contextClass) Filters the list of Problems (and their children) based on the affected class, e.g. find any/all problems that affect a Parameter, Step, etc. A flattened list is returned, i.e. it may be a mix of parents and children, regardless of where they occur in the problem hierarchy.
- Returns:
- a list of Problems that affect the given class. Or an empty list, if no Problems affect the given class.
-
debugString
- Returns:
- a string that gives some idea of the structure of this problem and its children, but without requiring any i18n resources to give actual user-facing error messages
-
debugString
Variation of
debugString(Problem)that dumps out a list of problems -
getChildren
-
toString
-
findAnyException
Finds any exception info related to this problem, including exceptions that may have been caught by child/nested Problems
-
iterator
-
toProblem
Description copied from interface:ProblemsConvert this Problems in to a single problem, or empty if this is Problems.NONE
-
stream
-
toList
Description copied from interface:ProblemsConvert this Problems in to a (possibly empty) list of Problems
-
isEmpty
public boolean isEmpty() -
isPresent
public boolean isPresent() -
equals
-
canEqual
-
hashCode
public int hashCode() -
getSeverity
- Specified by:
getSeverityin interfaceProblems- Returns:
- the maximum severity of any
Problems, or INFO if empty.
-
getArguments
-
getException
-
getCode
-