Package com.opencsv.validators
Class RowValidatorAggregator
- java.lang.Object
-
- com.opencsv.validators.RowValidatorAggregator
-
public class RowValidatorAggregator extends java.lang.ObjectThe aggregator's purpose is to collect multipleRowValidators and run them against a single array of strings. This way complex validations can be performed.- Since:
- 5.0
-
-
Field Summary
Fields Modifier and Type Field Description private static intCAPACITYprivate static intMULTIPLIERprivate java.util.List<RowValidator>validators
-
Constructor Summary
Constructors Constructor Description RowValidatorAggregator()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddValidator(RowValidator validator)Add a validator to the aggregator.booleanisValid(java.lang.String[] row)Runs allRowValidators'RowValidator.isValid(String[])method against the line.(package private) voidsetValidators(java.util.List<RowValidator> validators)Setter created for unit test.voidvalidate(java.lang.String[] row)Runs allRowValidators'RowValidator.validate(String[])methods and if the string array is invalid, then it combines all the validation error messages in a single CsvValidationException.
-
-
-
Field Detail
-
CAPACITY
private static final int CAPACITY
- See Also:
- Constant Field Values
-
MULTIPLIER
private static final int MULTIPLIER
- See Also:
- Constant Field Values
-
validators
private java.util.List<RowValidator> validators
-
-
Method Detail
-
addValidator
public void addValidator(RowValidator validator)
Add a validator to the aggregator.- Parameters:
validator- Validator to be added.
-
isValid
public boolean isValid(java.lang.String[] row)
Runs allRowValidators'RowValidator.isValid(String[])method against the line. This is a short circuit: as soon as one validator returnsfalsethenfalseis returned.- Parameters:
row- Array of strings to be validated.- Returns:
trueif all validators'RowValidator.isValid(String[])methods returntrue,falseotherwise.
-
validate
public void validate(java.lang.String[] row) throws CsvValidationExceptionRuns allRowValidators'RowValidator.validate(String[])methods and if the string array is invalid, then it combines all the validation error messages in a single CsvValidationException.- Parameters:
row- Array of Strings to be validation.- Throws:
CsvValidationException- Thrown if the string is invalid.
-
setValidators
void setValidators(java.util.List<RowValidator> validators)
Setter created for unit test.- Parameters:
validators- - list of validators to use.
-
-