Class 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
    • 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 of Strings) and throws an exception if invalid.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RowMustHaveSameNumberOfColumnsAsFirstRowValidator

        public RowMustHaveSameNumberOfColumnsAsFirstRowValidator()
        Default constructor.
    • 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 interface RowValidator
        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 of Strings) and throws an exception if invalid.
        Specified by:
        validate in interface RowValidator
        Parameters:
        row - Array of Strings to be validated.
        Throws:
        CsvValidationException - Thrown if invalid. Should contain a message describing the error.