Package com.opencsv.validators
Class RowMustHaveSameNumberOfColumnsAsFirstRowValidator
java.lang.Object
com.opencsv.validators.RowMustHaveSameNumberOfColumnsAsFirstRowValidator
- All Implemented Interfaces:
RowValidator
public class RowMustHaveSameNumberOfColumnsAsFirstRowValidator
extends 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
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
NO_ROWS
private static final int NO_ROWS- See Also:
-
numRows
private int numRows
-
-
Constructor Details
-
RowMustHaveSameNumberOfColumnsAsFirstRowValidator
public RowMustHaveSameNumberOfColumnsAsFirstRowValidator()Default constructor.
-
-
Method Details
-
isValid
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
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.
-
firstRowNotSetYet
private boolean firstRowNotSetYet()
-