Class ErrorList
- All Implemented Interfaces:
Serializable
,Iterable<ErrorList.ErrorData>
,Collection<ErrorList.ErrorData>
,List<ErrorList.ErrorData>
,SequencedCollection<ErrorList.ErrorData>
Each error within this class can contain a 'short' and 'long' description, where the short description is normally two-word categorisation of the error and the longer description describes what has happened and how to fix the problem; (e.g. shortText="Missing field", longText="The field 'id' is mandatory. Please enter a value for this field.").
In the UI, the short description is normally rendered in bold before the long description.
An individual error also may contain a severity,
and list of fields that it applies to (defined by a comma-separate string of field names)
An error without a severity supplied is assumed to be SEVERITY_INVALID
,
and an error without any fields supplied is assumed to be associated with the entire form,
rather than a specific set of fields.
Errors are inserted into an ErrorList by using one of the addError methods:
-
addError(String, String)
- add an invalid form error -
addError(String, String, int)
- add an form error with a specific severity -
addError(String, String, String)
- add an invalid field error -
addError(String, String, String, int)
- add an invalid field error with a specific severity
- Author:
- knoxg
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
ErrorInfo inner class - contains information related to a single error -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
invalid system-supplied data; end-user cannot fix situationstatic final int
internal error (e.g.static final int
information message; can be used in addition to SEVERITY_OK for additional textstatic final int
invalid user-supplied data; end-user can fix situationstatic final int
Severity level indicating 'not an error' (e.g.static final int
unrecoverable internal error (can't think of anything here, but the world ending could be onestatic final int
possibly incorrect user-supplied data; operation still succeeds but may return incorrect results -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int index, ErrorList.ErrorData element) boolean
boolean
addAll
(int index, Collection<? extends ErrorList.ErrorData> c) boolean
addAll
(Collection<? extends ErrorList.ErrorData> c) void
Adds an error that isn't associated with any particular field, with a default severity ofSEVERITY_ERROR
.void
Adds an error that isn't associated with any particular fieldvoid
As peraddError(String, String, String, int)
, with a default severity ofSEVERITY_ERROR
.void
Adds an error.boolean
Appends the errors contained within another ErrorData into this one.void
clear()
void
Resets all errors contained within this objectboolean
boolean
containsAll
(Collection<?> c) boolean
void
forEach
(Consumer<? super ErrorList.ErrorData> action) Delegate methodsget
(int index) getFieldAt
(int pos) Returns the field of the pos'th errorgetLongTextAt
(int pos) Returns the longText of the pos'th errorint
getSeverityAt
(int pos) Returns the severity of the pos'th errorgetShortTextAt
(int pos) Returns the shortText string of the pos'th errorint
getSize()
Same assize()
.boolean
hasErrorOn
(String field) Returns true if an error has occured on the field passed as a parameter to this methodboolean
Returns true if there are any errors in this objectboolean
hasErrors
(int severity) Deprecated.int
hashCode()
int
boolean
isEmpty()
iterator()
int
listIterator
(int index) void
Convert the backing store for this ErrorList to a Collections.synchronizedList, suitable for use in multithreaded applications.int
Deprecated.remove
(int index) boolean
boolean
removeAll
(Collection<?> c) void
Removes any duplicate errors in this ErrorListboolean
removeIf
(Predicate<? super ErrorList.ErrorData> filter) void
replaceAll
(UnaryOperator<ErrorList.ErrorData> operator) boolean
retainAll
(Collection<?> c) set
(int index, ErrorList.ErrorData element) int
size()
Returns the number of errors in this objectvoid
sort
(Comparator<? super ErrorList.ErrorData> c) stream()
subList
(int fromIndex, int toIndex) Object[]
toArray()
<T> T[]
toArray
(T[] a) toJSON()
Return the JSON representation of this objecttoString()
Return all the errors within this object in a single string.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
toArray
Methods inherited from interface java.util.List
addFirst, addLast, getFirst, getLast, removeFirst, removeLast, reversed
-
Field Details
-
SEVERITY_OK
Severity level indicating 'not an error' (e.g. informational only). Used to indicate successful operations- See Also:
-
SEVERITY_INVALID
invalid user-supplied data; end-user can fix situation- See Also:
-
SEVERITY_ERROR
invalid system-supplied data; end-user cannot fix situation- See Also:
-
SEVERITY_FATAL
internal error (e.g. EJB/LDAP connection failure)- See Also:
-
SEVERITY_PANIC
unrecoverable internal error (can't think of anything here, but the world ending could be one- See Also:
-
SEVERITY_INFO
information message; can be used in addition to SEVERITY_OK for additional text- See Also:
-
SEVERITY_WARNING
possibly incorrect user-supplied data; operation still succeeds but may return incorrect results- See Also:
-
-
Constructor Details
-
ErrorList
public ErrorList()Create a new, empty ErrorData object.
-
-
Method Details
-
makeThreadsafe
Convert the backing store for this ErrorList to a Collections.synchronizedList, suitable for use in multithreaded applications. Note that iterations on this collection must still be synchronised. -
removeDuplicates
Removes any duplicate errors in this ErrorList -
addError
Adds an error. This is the "real" addError() method; all others delegate to this one.- Parameters:
errorField
- a comma-separated list of field names that caused this errorshortText
- a short string conveying the error type (e.g. 'Missing field')longText
- a longer string describing the nature of the error and how to resolve it (e.g. 'The field 'id' is mandatory. Please enter a value for this field.')severity
- the severity of this error (one of the SEVERITY_* constants of this class).- See Also:
-
addError
As peraddError(String, String, String, int)
, with a default severity ofSEVERITY_ERROR
.- Parameters:
errorField
- a comma-separated list of field names that caused this errorshortText
- a short string conveying the error type (e.g. 'Missing field')longText
- a longer string describing the nature of the error and how to resolve it (e.g. 'The field 'id' is mandatory. Please enter a value for this field.')
-
addError
Adds an error that isn't associated with any particular field- Parameters:
shortText
- a short string conveying the error type (e.g. 'Missing field')longText
- a longer string describing the nature of the error and how to resolve it (e.g. 'The field 'id' is mandatory. Please enter a value for this field.')severity
- the severity of this error (one of the SEVERITY_* constants of this class)
-
addError
Adds an error that isn't associated with any particular field, with a default severity ofSEVERITY_ERROR
.- Parameters:
shortText
- a short string conveying the error type (e.g. 'Missing field')longText
- a longer string describing the nature of the error and how to resolve it (e.g. 'The field 'id' is mandatory. Please enter a value for this field.')
-
clearErrors
Resets all errors contained within this object -
addErrors
Appends the errors contained within another ErrorData into this one.- Parameters:
errorList
-- Returns:
- true if there were any additional errors to embed and at least one of the errors had a severity of SEVERITY_ERROR or higher (worse), false otherwise.
-
hasErrorOn
Returns true if an error has occured on the field passed as a parameter to this method- Returns:
- true if an error occured, false if not.
-
hasErrors
Returns true if there are any errors in this object- Returns:
- True if the number of errors > 0
-
hasErrors
Deprecated.Returns true if there are any errors of the specified severity or higher Note that our severities aren't in increasing severity order any more so this method is now deprecated- Parameters:
severity
- a SEVERITY_* constant- Returns:
- True if the number of errors at the specified severity or higher > 0
-
maxErrorSeverity
Deprecated.Returns the maximum severity of all current errors. Note that our severities aren't in increasing severity order any more so this method is now deprecated- Returns:
- the severity ranking of the most severe error, or -1 if there are no errors contained within this ErrorData object.
-
size
Returns the number of errors in this object- Specified by:
size
in interfaceCollection<ErrorList.ErrorData>
- Specified by:
size
in interfaceList<ErrorList.ErrorData>
- Returns:
- The number of errors in this object
-
getSize
Same assize()
. Only here to allow us to access the object in JSTL- Returns:
- The number of errors in this object
-
getShortTextAt
Returns the shortText string of the pos'th error -
getLongTextAt
Returns the longText of the pos'th error -
getFieldAt
Returns the field of the pos'th error -
getSeverityAt
Returns the severity of the pos'th error -
toString
Return all the errors within this object in a single string. Suitable for inclusion within email alarms, logs etc... -
toJSON
Return the JSON representation of this object- Returns:
- the JSON representation of this object
-
forEach
Delegate methods- Specified by:
forEach
in interfaceIterable<ErrorList.ErrorData>
-
isEmpty
- Specified by:
isEmpty
in interfaceCollection<ErrorList.ErrorData>
- Specified by:
isEmpty
in interfaceList<ErrorList.ErrorData>
-
contains
- Specified by:
contains
in interfaceCollection<ErrorList.ErrorData>
- Specified by:
contains
in interfaceList<ErrorList.ErrorData>
-
iterator
- Specified by:
iterator
in interfaceCollection<ErrorList.ErrorData>
- Specified by:
iterator
in interfaceIterable<ErrorList.ErrorData>
- Specified by:
iterator
in interfaceList<ErrorList.ErrorData>
-
toArray
- Specified by:
toArray
in interfaceCollection<ErrorList.ErrorData>
- Specified by:
toArray
in interfaceList<ErrorList.ErrorData>
-
toArray
- Specified by:
toArray
in interfaceCollection<ErrorList.ErrorData>
- Specified by:
toArray
in interfaceList<ErrorList.ErrorData>
-
add
- Specified by:
add
in interfaceCollection<ErrorList.ErrorData>
- Specified by:
add
in interfaceList<ErrorList.ErrorData>
-
remove
- Specified by:
remove
in interfaceCollection<ErrorList.ErrorData>
- Specified by:
remove
in interfaceList<ErrorList.ErrorData>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<ErrorList.ErrorData>
- Specified by:
containsAll
in interfaceList<ErrorList.ErrorData>
-
addAll
- Specified by:
addAll
in interfaceCollection<ErrorList.ErrorData>
- Specified by:
addAll
in interfaceList<ErrorList.ErrorData>
-
addAll
- Specified by:
addAll
in interfaceList<ErrorList.ErrorData>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<ErrorList.ErrorData>
- Specified by:
removeAll
in interfaceList<ErrorList.ErrorData>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<ErrorList.ErrorData>
- Specified by:
retainAll
in interfaceList<ErrorList.ErrorData>
-
replaceAll
- Specified by:
replaceAll
in interfaceList<ErrorList.ErrorData>
-
removeIf
- Specified by:
removeIf
in interfaceCollection<ErrorList.ErrorData>
-
sort
- Specified by:
sort
in interfaceList<ErrorList.ErrorData>
-
clear
- Specified by:
clear
in interfaceCollection<ErrorList.ErrorData>
- Specified by:
clear
in interfaceList<ErrorList.ErrorData>
-
equals
- Specified by:
equals
in interfaceCollection<ErrorList.ErrorData>
- Specified by:
equals
in interfaceList<ErrorList.ErrorData>
- Overrides:
equals
in classObject
-
hashCode
- Specified by:
hashCode
in interfaceCollection<ErrorList.ErrorData>
- Specified by:
hashCode
in interfaceList<ErrorList.ErrorData>
- Overrides:
hashCode
in classObject
-
get
- Specified by:
get
in interfaceList<ErrorList.ErrorData>
-
set
- Specified by:
set
in interfaceList<ErrorList.ErrorData>
-
add
- Specified by:
add
in interfaceList<ErrorList.ErrorData>
-
stream
- Specified by:
stream
in interfaceCollection<ErrorList.ErrorData>
-
remove
- Specified by:
remove
in interfaceList<ErrorList.ErrorData>
-
parallelStream
- Specified by:
parallelStream
in interfaceCollection<ErrorList.ErrorData>
-
indexOf
- Specified by:
indexOf
in interfaceList<ErrorList.ErrorData>
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList<ErrorList.ErrorData>
-
listIterator
- Specified by:
listIterator
in interfaceList<ErrorList.ErrorData>
-
listIterator
- Specified by:
listIterator
in interfaceList<ErrorList.ErrorData>
-
subList
- Specified by:
subList
in interfaceList<ErrorList.ErrorData>
-
spliterator
- Specified by:
spliterator
in interfaceCollection<ErrorList.ErrorData>
- Specified by:
spliterator
in interfaceIterable<ErrorList.ErrorData>
- Specified by:
spliterator
in interfaceList<ErrorList.ErrorData>
-