Package com.opencsv.validators
Class RowValidatorAggregator
- java.lang.Object
-
- com.opencsv.validators.RowValidatorAggregator
-
public class RowValidatorAggregator extends java.lang.Object
The aggregator's purpose is to collect multipleRowValidator
s 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 int
CAPACITY
private static int
MULTIPLIER
private 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 void
addValidator(RowValidator validator)
Add a validator to the aggregator.boolean
isValid(java.lang.String[] row)
Runs allRowValidator
s'RowValidator.isValid(String[])
method against the line.(package private) void
setValidators(java.util.List<RowValidator> validators)
Setter created for unit test.void
validate(java.lang.String[] row)
Runs allRowValidator
s'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 allRowValidator
s'RowValidator.isValid(String[])
method against the line. This is a short circuit: as soon as one validator returnsfalse
thenfalse
is returned.- Parameters:
row
- Array of strings to be validated.- Returns:
true
if all validators'RowValidator.isValid(String[])
methods returntrue
,false
otherwise.
-
validate
public void validate(java.lang.String[] row) throws CsvValidationException
Runs allRowValidator
s'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.
-
-