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
-
-
Constructor Summary
Constructors Constructor Description RowMustHaveSameNumberOfColumnsAsFirstRowValidator()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanfirstRowNotSetYet()booleanisValid(java.lang.String[] row)Performs the validation check on the string and returns the result.voidvalidate(java.lang.String[] row)Performs the validation check on the row (an array ofStrings) and throws an exception if invalid.
-
-
-
Field Detail
-
NO_ROWS
private static final int NO_ROWS
- See Also:
- Constant Field Values
-
numRows
private int numRows
-
-
Method Detail
-
isValid
public boolean isValid(java.lang.String[] row)
Description copied from interface:RowValidatorPerforms 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:
isValidin interfaceRowValidator- Parameters:
row- Array of strings to be validated- Returns:
trueif the row is valid,falseotherwise
-
validate
public void validate(java.lang.String[] row) throws CsvValidationExceptionDescription copied from interface:RowValidatorPerforms the validation check on the row (an array ofStrings) and throws an exception if invalid.- Specified by:
validatein interfaceRowValidator- Parameters:
row- Array ofStrings to be validated.- Throws:
CsvValidationException- Thrown if invalid. Should contain a message describing the error.
-
firstRowNotSetYet
private boolean firstRowNotSetYet()
-
-