Interface HeaderValidator

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface HeaderValidator

Implementations of this class are used within NamedCsvRecordHandler to validate the header of a CSV file once it is determined.

Example:

NamedCsvRecordHandler handler = NamedCsvRecordHandler.builder()
    .headerValidator(HeaderValidator.containsExactly("col1", "col2"))
    .build();
  • Method Details

    • containsExactly

      static HeaderValidator containsExactly(String... expectedHeader)
      Builds a validator that throws a CsvParseException if the header does not consist of exactly the given fields, in the given order.
      Parameters:
      expectedHeader - the expected header fields, must not be null
      Returns:
      the validator
      Throws:
      NullPointerException - if null is passed or the fields contain null elements
      See Also:
    • containsExactly

      static HeaderValidator containsExactly(List<String> expectedHeader)
      Builds a validator that throws a CsvParseException if the header does not consist of exactly the given fields, in the given order.
      Parameters:
      expectedHeader - the expected header fields, must not be null
      Returns:
      the validator
      Throws:
      NullPointerException - if null is passed or the fields contain null elements
      See Also:
    • containsAtLeast

      static HeaderValidator containsAtLeast(String... requiredFields)
      Builds a validator that throws a CsvParseException if the header does not contain all of the given fields, in any order. Additional fields are allowed.
      Parameters:
      requiredFields - the required header fields, must not be null
      Returns:
      the validator
      Throws:
      NullPointerException - if null is passed or the fields contain null elements
      See Also:
    • containsAtLeast

      static HeaderValidator containsAtLeast(List<String> requiredFields)
      Builds a validator that throws a CsvParseException if the header does not contain all of the given fields, in any order. Additional fields are allowed.
      Parameters:
      requiredFields - the required header fields, must not be null
      Returns:
      the validator
      Throws:
      NullPointerException - if null is passed or the fields contain null elements
      See Also:
    • validate

      void validate(List<String> header)
      Gets called once the header is determined – either from the first record (that is not a comment or an empty line) or from a predefined header.
      Parameters:
      header - the header fields, never null
      Throws:
      RuntimeException - if the header is not acceptable