|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.jgoodies.validation.ValidationResult
public final class ValidationResult
Describes a validation result as a list of ValidationMessages. You can add single validation messages, single text messages, lists of messages, and all messages from another ValidationResult.
ValidationMessage,
Validator,
Serialized Form| Field Summary | |
|---|---|
static ValidationResult |
EMPTY
A constant for an empty and unmodifiable validation result. |
| Constructor Summary | |
|---|---|
ValidationResult()
Constructs an empty modifiable ValidationResult. |
|
| Method Summary | |
|---|---|
void |
add(ValidationMessage validationMessage)
Adds a new ValidationMessage to the list of messages. |
void |
addAll(List<ValidationMessage> messages)
Adds all messages from the given list to this validation result. |
void |
addAllFrom(ValidationResult validationResult)
Adds all messages from the given ValidationResult to the list of messages that this validation result holds. |
void |
addError(String text)
Creates and adds an error message to the list of validation messages using the given text. |
void |
addError(String text,
String key)
Creates and adds an error message to the list of validation messages using the given text and validation message key. |
void |
addWarning(String text)
Creates and adds a warning message to the list of validation messages using the given text. |
void |
addWarning(String text,
String key)
Creates and adds a warning message to the list of validation messages using the given text. |
boolean |
contains(ValidationMessage message)
Checks and answers whether this result contains the specified message. |
boolean |
equals(Object o)
Compares the specified object with this validation result for equality. |
ValidationMessage |
get(int index)
Returns the message at the specified position in this result. |
List<ValidationMessage> |
getErrors()
Returns an unmodifiable List of the validation messages that indicate errors. |
List<ValidationMessage> |
getMessages()
Returns an unmodifiable List of all validation messages. |
String |
getMessagesText()
Returns a string representation of the message list. |
Severity |
getSeverity()
Returns the highest severity of this result's messages, Severity.OK if there are no messages. |
List<ValidationMessage> |
getWarnings()
Returns an unmodifiable List of the validation messages that indicate warnings. |
boolean |
hasErrors()
Checks and answers whether this validation result contains a message of type ERROR. |
int |
hashCode()
Returns the hash code value for this validation result. |
boolean |
hasMessages()
Checks and answers whether this validation result has messages or not. |
boolean |
hasWarnings()
Checks and answers whether this validation result contains a message of type WARNING. |
boolean |
isEmpty()
Checks and answers whether this validation result contains no messages. |
boolean |
isModifiable()
Returns if this validation result is modifiable or not. |
Iterator<ValidationMessage> |
iterator()
Returns an iterator over the validation messages in this result in proper sequence. |
Map<Object,ValidationResult> |
keyMap()
Creates and returns an unmodifiable Map that maps the message keys of this validation result to unmodifiable sub results that share the key. |
int |
size()
Returns the number of messages in this result. |
ValidationResult |
subResult(int fromIndex,
int toIndex)
Returns an unmodifiable view of the portion of this result between the specified fromIndex, inclusive, and toIndex,
exclusive. |
ValidationResult |
subResult(Object messageKey)
Returns an unmodifiable sub result of this result that consists of all messages that share the specified message key. |
ValidationResult |
subResult(Object[] messageKeys)
Returns an unmodifiable sub result of this result that consists of all messages that share the specified message keys. |
String |
toString()
Returns a string representation intended for debugging purposes. |
static ValidationResult |
unmodifiableResult(ValidationResult validationResult)
Returns an unmodifiable view of the given ValidationResult. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final ValidationResult EMPTY
| Constructor Detail |
|---|
public ValidationResult()
| Method Detail |
|---|
public static ValidationResult unmodifiableResult(ValidationResult validationResult)
UnsupportedOperationException.
validationResult - the result for which an unmodifiable view is to be returned
public void add(ValidationMessage validationMessage)
validationMessage - the message to add
NullPointerException - if the message is null
UnsupportedOperationException - if the result is unmodifiable
IllegalArgumentException - if the severity is OKaddError(String),
addWarning(String)public void addError(String text)
text - the error text to add
NullPointerException - if the message text null
UnsupportedOperationException - if the result is unmodifiableadd(ValidationMessage),
addWarning(String)
public void addError(String text,
String key)
text - the error text to addkey - the optional messages key
NullPointerException - if the message text null
UnsupportedOperationException - if the result is unmodifiableadd(ValidationMessage),
addWarning(String)public void addWarning(String text)
text - the warning text to add
NullPointerException - if the message text null
UnsupportedOperationException - if the result is unmodifiableadd(ValidationMessage),
addError(String)
public void addWarning(String text,
String key)
text - the warning text to addkey - the optional message key
NullPointerException - if the message text null
UnsupportedOperationException - if the result is unmodifiableadd(ValidationMessage),
addError(String)public void addAll(List<ValidationMessage> messages)
messages - the messages to be added
NullPointerException - if the messages list is null
UnsupportedOperationException - if the result is unmodifiable
IllegalArgumentException - if the messages list contains
a message with severity OKaddAllFrom(ValidationResult)public void addAllFrom(ValidationResult validationResult)
validationResult - the validation result to add messages from
NullPointerException - if the validation result is null
UnsupportedOperationException - if the result is unmodifiableaddAll(List)public boolean isEmpty()
hasErrors(),
hasWarnings()public int size()
public boolean contains(ValidationMessage message)
true if and only if this result
contains at least one message m such that
(message.equals(m)).
message - message whose presence in this result is to be tested
true if this result contains the specified message
NullPointerException - if the specified message is
nullpublic ValidationMessage get(int index)
index - index of the message to return.
IndexOutOfBoundsException - if the index is out of range (index
< 0 || index >= size()).public Iterator<ValidationMessage> iterator()
iterator in interface Iterable<ValidationMessage>
public ValidationResult subResult(int fromIndex,
int toIndex)
fromIndex, inclusive, and toIndex,
exclusive.
(If fromIndex and toIndex are equal,
the returned result is empty.) The returned result is a copy,
so changes in the returned result won't affect this result,
and vice-versa.
fromIndex - low end point (inclusive) of the subResulttoIndex - high end point (exclusive) of the subResult
IndexOutOfBoundsException - for an illegal end point index value
(fromIndex < 0 || toIndex > size || fromIndex > toIndex).subResult(Object)public ValidationResult subResult(Object messageKey)
null, this method returns an empty result.
The returned result is a copy, so changes in this result won't affect it.
messageKey - the key to look for, can be null
nullsubResult(int, int)public ValidationResult subResult(Object[] messageKeys)
null, this method returns an empty result.
The returned result is a copy, so changes in this result won't affect it.
messageKeys - the keys to look for, can be null
nullsubResult(int, int)public Map<Object,ValidationResult> keyMap()
More formally:
for each key key in the created map map,
map.get(key) returns a ValidationResult
result, such that for each ValidationMessage
message in result we have:
message.key().equals(key).
ValidationMessage.key()public Severity getSeverity()
Severity.OK if there are no messages.
Severity.OK if there are no messageshasMessages(),
hasErrors(),
hasWarnings()public boolean hasMessages()
getSeverity(),
hasErrors(),
hasWarnings()public boolean hasErrors()
ERROR.
getSeverity(),
hasMessages(),
hasWarnings()public boolean hasWarnings()
WARNING.
Note that this method checks for warning messages only.
It'll return false, if there are errors but no warnings.
If you want to test whether this result contains
warning and/or errors, use #hasMessages instead.
getSeverity(),
hasMessages(),
hasErrors()public List<ValidationMessage> getMessages()
List of all validation messagesgetErrors(),
getWarnings()public List<ValidationMessage> getErrors()
getMessages(),
getWarnings()public List<ValidationMessage> getWarnings()
getMessages(),
getErrors()public boolean isModifiable()
public String getMessagesText()
public String toString()
toString in class ObjectObject.toString()public boolean equals(Object o)
true if and only if the specified object is also
a validation result, both results have the same size, and all
corresponding pairs of validation messages in the two validation results
are equal. (Two validation messages m1 and
m2 are equal if (m1==null ? m2==null :
m1.equals(m2)).) In other words, two validation results
are defined to be equal if and only if they contain the same
validation messages in the same order.
This implementation first checks if the specified object is this
validation result. If so, it returns true;
if not, it checks if the specified object is a validation result.
If not, it returns false; if so, it checks and returns
if the lists of messages in both results are equal.
equals in class Objecto - the object to be compared for equality with this validation result.
true if the specified object is equal
to this validation result.List.equals(java.lang.Object),
Object.equals(java.lang.Object)public int hashCode()
hashCode in class ObjectList.hashCode(),
Object.hashCode()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||