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 classErrorInfo inner class - contains information related to a single error -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intinvalid system-supplied data; end-user cannot fix situationstatic final intinternal error (e.g.static final intinformation message; can be used in addition to SEVERITY_OK for additional textstatic final intinvalid user-supplied data; end-user can fix situationstatic final intSeverity level indicating 'not an error' (e.g.static final intunrecoverable internal error (can't think of anything here, but the world ending could be onestatic final intpossibly incorrect user-supplied data; operation still succeeds but may return incorrect results -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int index, ErrorList.ErrorData element) booleanbooleanaddAll(int index, Collection<? extends ErrorList.ErrorData> c) booleanaddAll(Collection<? extends ErrorList.ErrorData> c) voidAdds an error that isn't associated with any particular field, with a default severity ofSEVERITY_ERROR.voidAdds an error that isn't associated with any particular fieldvoidAs peraddError(String, String, String, int), with a default severity ofSEVERITY_ERROR.voidAdds an error.booleanAppends the errors contained within another ErrorData into this one.voidclear()voidResets all errors contained within this objectbooleanbooleancontainsAll(Collection<?> c) booleanvoidforEach(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 errorintgetSeverityAt(int pos) Returns the severity of the pos'th errorgetShortTextAt(int pos) Returns the shortText string of the pos'th errorintgetSize()Same assize().booleanhasErrorOn(String field) Returns true if an error has occured on the field passed as a parameter to this methodbooleanReturns true if there are any errors in this objectbooleanhasErrors(int severity) Deprecated.inthashCode()intbooleanisEmpty()iterator()intlistIterator(int index) voidConvert the backing store for this ErrorList to a Collections.synchronizedList, suitable for use in multithreaded applications.intDeprecated.remove(int index) booleanbooleanremoveAll(Collection<?> c) voidRemoves any duplicate errors in this ErrorListbooleanremoveIf(Predicate<? super ErrorList.ErrorData> filter) voidreplaceAll(UnaryOperator<ErrorList.ErrorData> operator) booleanretainAll(Collection<?> c) set(int index, ErrorList.ErrorData element) intsize()Returns the number of errors in this objectvoidsort(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, waitMethods inherited from interface java.util.Collection
toArrayMethods 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:
sizein interfaceCollection<ErrorList.ErrorData>- Specified by:
sizein 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:
forEachin interfaceIterable<ErrorList.ErrorData>
-
isEmpty
- Specified by:
isEmptyin interfaceCollection<ErrorList.ErrorData>- Specified by:
isEmptyin interfaceList<ErrorList.ErrorData>
-
contains
- Specified by:
containsin interfaceCollection<ErrorList.ErrorData>- Specified by:
containsin interfaceList<ErrorList.ErrorData>
-
iterator
- Specified by:
iteratorin interfaceCollection<ErrorList.ErrorData>- Specified by:
iteratorin interfaceIterable<ErrorList.ErrorData>- Specified by:
iteratorin interfaceList<ErrorList.ErrorData>
-
toArray
- Specified by:
toArrayin interfaceCollection<ErrorList.ErrorData>- Specified by:
toArrayin interfaceList<ErrorList.ErrorData>
-
toArray
- Specified by:
toArrayin interfaceCollection<ErrorList.ErrorData>- Specified by:
toArrayin interfaceList<ErrorList.ErrorData>
-
add
- Specified by:
addin interfaceCollection<ErrorList.ErrorData>- Specified by:
addin interfaceList<ErrorList.ErrorData>
-
remove
- Specified by:
removein interfaceCollection<ErrorList.ErrorData>- Specified by:
removein interfaceList<ErrorList.ErrorData>
-
containsAll
- Specified by:
containsAllin interfaceCollection<ErrorList.ErrorData>- Specified by:
containsAllin interfaceList<ErrorList.ErrorData>
-
addAll
- Specified by:
addAllin interfaceCollection<ErrorList.ErrorData>- Specified by:
addAllin interfaceList<ErrorList.ErrorData>
-
addAll
- Specified by:
addAllin interfaceList<ErrorList.ErrorData>
-
removeAll
- Specified by:
removeAllin interfaceCollection<ErrorList.ErrorData>- Specified by:
removeAllin interfaceList<ErrorList.ErrorData>
-
retainAll
- Specified by:
retainAllin interfaceCollection<ErrorList.ErrorData>- Specified by:
retainAllin interfaceList<ErrorList.ErrorData>
-
replaceAll
- Specified by:
replaceAllin interfaceList<ErrorList.ErrorData>
-
removeIf
- Specified by:
removeIfin interfaceCollection<ErrorList.ErrorData>
-
sort
- Specified by:
sortin interfaceList<ErrorList.ErrorData>
-
clear
- Specified by:
clearin interfaceCollection<ErrorList.ErrorData>- Specified by:
clearin interfaceList<ErrorList.ErrorData>
-
equals
- Specified by:
equalsin interfaceCollection<ErrorList.ErrorData>- Specified by:
equalsin interfaceList<ErrorList.ErrorData>- Overrides:
equalsin classObject
-
hashCode
- Specified by:
hashCodein interfaceCollection<ErrorList.ErrorData>- Specified by:
hashCodein interfaceList<ErrorList.ErrorData>- Overrides:
hashCodein classObject
-
get
- Specified by:
getin interfaceList<ErrorList.ErrorData>
-
set
- Specified by:
setin interfaceList<ErrorList.ErrorData>
-
add
- Specified by:
addin interfaceList<ErrorList.ErrorData>
-
stream
- Specified by:
streamin interfaceCollection<ErrorList.ErrorData>
-
remove
- Specified by:
removein interfaceList<ErrorList.ErrorData>
-
parallelStream
- Specified by:
parallelStreamin interfaceCollection<ErrorList.ErrorData>
-
indexOf
- Specified by:
indexOfin interfaceList<ErrorList.ErrorData>
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<ErrorList.ErrorData>
-
listIterator
- Specified by:
listIteratorin interfaceList<ErrorList.ErrorData>
-
listIterator
- Specified by:
listIteratorin interfaceList<ErrorList.ErrorData>
-
subList
- Specified by:
subListin interfaceList<ErrorList.ErrorData>
-
spliterator
- Specified by:
spliteratorin interfaceCollection<ErrorList.ErrorData>- Specified by:
spliteratorin interfaceIterable<ErrorList.ErrorData>- Specified by:
spliteratorin interfaceList<ErrorList.ErrorData>
-