com.acsinet_solutions.util.validator
Class ValidationIssueBuilder

java.lang.Object
  extended by com.acsinet_solutions.util.validator.ValidationIssueBuilder

public class ValidationIssueBuilder
extends java.lang.Object

Bean that represents a validation issue register. Issues are added to this instance using the addIssue() methods. Several convenience checkXXX() methods are added to provide common check situations. When validation conditions are checked, the check() method may be called; if any issue was detected, a ValidationException that gathers all validation issues is thrown.

WARNING! This class is not thread-safe; it is intended for single-thread use only

Author:
Santiago Arriaga

Field Summary
 java.util.List<ValidationIssue> _issues
          The issues being built
 
Constructor Summary
ValidationIssueBuilder()
          Public default constructor
 
Method Summary
 void addIssue(java.lang.String key, java.lang.Object... args)
          Add a new validation issue
 void addIssue(ValidationIssue issue)
          Add a new validation issue
 void addIssues(java.util.List<ValidationIssue> list)
          Add all the issues in the given list
 void check()
          Check if there are issues and throw a ValidationException if there are
 boolean checkIncluded(java.lang.Object value, java.util.Set validValues, java.lang.String key, java.lang.Object... args)
          Check that the given value is included in the validValues Set
 boolean checkMatch(java.lang.String re, java.lang.String field, java.lang.String key, java.lang.Object... args)
          Check that a field matches a re, and generate a validation issue if not.
 boolean checkNotEmpty(java.util.Collection collection, java.lang.String key, java.lang.Object... args)
          Check that the given Collection is not null or empty.
 boolean checkNotEmpty(java.util.Map map, java.lang.String key, java.lang.Object... args)
          Check that the given Map is not null or empty.
 boolean checkNotEmpty(java.lang.String field, java.lang.String key, java.lang.Object... args)
          Check that the given field is not null or empty.
 boolean checkNotNull(java.lang.Object obj, java.lang.String key, java.lang.Object... args)
          Check that the given reference is not null.
 boolean checkTrue(boolean condition, java.lang.String key, java.lang.Object... args)
          Check that the given condition evaluates to a true value.
 int getSize()
          Check the issues size
 boolean hasIssues()
          Return whether the current class has raised issues or not
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_issues

public final java.util.List<ValidationIssue> _issues
The issues being built

Constructor Detail

ValidationIssueBuilder

public ValidationIssueBuilder()
Public default constructor

Method Detail

addIssue

public final void addIssue(ValidationIssue issue)
Add a new validation issue


addIssue

public final void addIssue(java.lang.String key,
                           java.lang.Object... args)
Add a new validation issue

Parameters:
description - A not-null not-empty issue key

addIssues

public void addIssues(java.util.List<ValidationIssue> list)
Add all the issues in the given list

Parameters:
list - A not-null maybe-empty list of not-null ValidationIssue instances.

hasIssues

public final boolean hasIssues()
Return whether the current class has raised issues or not


getSize

public final int getSize()
Check the issues size


check

public final void check()
                 throws ValidationException
Check if there are issues and throw a ValidationException if there are

Throws:
ValidationException

checkTrue

public final boolean checkTrue(boolean condition,
                               java.lang.String key,
                               java.lang.Object... args)
Check that the given condition evaluates to a true value.

Parameters:
condition - The condition that must be true in order to pass the check
key - The not-null not-empty String instance that will identify the issue to be raised if the field is null or empty.
args - Extra, maybe-null arguments for the issue message.
Returns:
the value of the condition field; useful for chaining

checkNotEmpty

public final boolean checkNotEmpty(java.lang.String field,
                                   java.lang.String key,
                                   java.lang.Object... args)
Check that the given field is not null or empty. A space-filled field is considered to be empty

Parameters:
field - The maybe-null field to be checked
key - The not-null not-empty String instance that will identify the issue to be raised if the field is null or empty.
args - Extra, maybe-null arguments for the issue message.
Returns:
true if the field is not null or empty; false otherwise.

checkNotEmpty

public final boolean checkNotEmpty(java.util.Map map,
                                   java.lang.String key,
                                   java.lang.Object... args)
Check that the given Map is not null or empty.

Parameters:
map - The maybe-null Map to be checked
key - The not-null not-empty String instance that will identify the issue to be raised if the Map is null or empty.
args - Extra, maybe-null arguments for the issue message.
Returns:
true if the Map is not null or empty; false otherwise.

checkNotEmpty

public final boolean checkNotEmpty(java.util.Collection collection,
                                   java.lang.String key,
                                   java.lang.Object... args)
Check that the given Collection is not null or empty.

Parameters:
collection - The maybe-null Collection to be checked
key - The not-null not-empty String instance that will identify the issue to be raised if the Collection is null or empty.
args - Extra, maybe-null arguments for the issue message.
Returns:
true if the Collection is not null or empty; false otherwise.

checkNotNull

public final boolean checkNotNull(java.lang.Object obj,
                                  java.lang.String key,
                                  java.lang.Object... args)
Check that the given reference is not null.

Parameters:
obj - The object reference.
key - The not-null not-empty String instance that will identify the issue to be raised if the Collection is null or empty.
args - Extra, maybe-null arguments for the issue message.
Returns:
true if the object is not null; false otherwise

checkIncluded

public final boolean checkIncluded(java.lang.Object value,
                                   java.util.Set validValues,
                                   java.lang.String key,
                                   java.lang.Object... args)
Check that the given value is included in the validValues Set

Parameters:
value - a maybe-null value instance
validValues - a not-null Set of not-null values that will be compared against the arg value
key - The not-null not-empty String instance that will identify the issue to be raised if the Collection is null or empty.
args - Extra, maybe-null arguments for the issue message.
Returns:
true if the value is contained in the validValues collection

checkMatch

public final boolean checkMatch(java.lang.String re,
                                java.lang.String field,
                                java.lang.String key,
                                java.lang.Object... args)
Check that a field matches a re, and generate a validation issue if not.

Parameters:
re - The not-null valid re pattern to be matched upon
field - The not-null field to be checked
key - The not-null not-empty String instance that will identify the issue to be raised if the matching doesn't occur.
args - Extra, maybe-null arguments for the issue message.
Returns:
true if the field matches the re pattern; false otherwise.