Package com.opencsv.validators
Class RowMustHaveSameNumberOfColumnsAsFirstRowValidator
- java.lang.Object
-
- com.opencsv.validators.RowMustHaveSameNumberOfColumnsAsFirstRowValidator
-
- All Implemented Interfaces:
RowValidator
public class RowMustHaveSameNumberOfColumnsAsFirstRowValidator extends java.lang.Object implements RowValidator
This validator is used when the number of columns is not neccessarily known but must be consistent. The first row validated will always be considered valid, unless null or empty, and after that the each subsequent row must have the same number of columns as the first.Arrays that are empty or null are considered to have 0 elements. An empty or null first row is considered invalid.
As with all row validators the assumption is you have control of the data and have skipped any initial empty lines. If you have data that has empty lines or separators lines in your data then you should not use this class. Either extend it or write your own validator.
- Since:
- 5.0
- Author:
- Scott Conway
-
-
Constructor Summary
Constructors Constructor Description RowMustHaveSameNumberOfColumnsAsFirstRowValidator()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isValid(java.lang.String[] row)
Performs the validation check on the string and returns the result.void
validate(java.lang.String[] row)
Performs the validation check on the row (an array ofString
s) and throws an exception if invalid.
-
-
-
Method Detail
-
isValid
public boolean isValid(java.lang.String[] row)
Description copied from interface:RowValidator
Performs the validation check on the string and returns the result. While not called directly in opencsv it is in the interface to provide an easy way to test if the validator is functioning properly.- Specified by:
isValid
in interfaceRowValidator
- Parameters:
row
- Array of strings to be validated- Returns:
true
if the row is valid,false
otherwise
-
validate
public void validate(java.lang.String[] row) throws CsvValidationException
Description copied from interface:RowValidator
Performs the validation check on the row (an array ofString
s) and throws an exception if invalid.- Specified by:
validate
in interfaceRowValidator
- Parameters:
row
- Array ofString
s to be validated.- Throws:
CsvValidationException
- Thrown if invalid. Should contain a message describing the error.
-
-