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.
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 Summary
Modifier and TypeMethodDescriptionstatic HeaderValidatorcontainsAtLeast(String... requiredFields) Builds a validator that throws aCsvParseExceptionif the header does not contain all of the given fields, in any order.static HeaderValidatorcontainsAtLeast(List<String> requiredFields) Builds a validator that throws aCsvParseExceptionif the header does not contain all of the given fields, in any order.static HeaderValidatorcontainsExactly(String... expectedHeader) Builds a validator that throws aCsvParseExceptionif the header does not consist of exactly the given fields, in the given order.static HeaderValidatorcontainsExactly(List<String> expectedHeader) Builds a validator that throws aCsvParseExceptionif the header does not consist of exactly the given fields, in the given order.voidGets 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.
-
Method Details
-
containsExactly
Builds a validator that throws aCsvParseExceptionif the header does not consist of exactly the given fields, in the given order.- Parameters:
expectedHeader- the expected header fields, must not benull- Returns:
- the validator
- Throws:
NullPointerException- ifnullis passed or the fields containnullelements- See Also:
-
containsExactly
Builds a validator that throws aCsvParseExceptionif the header does not consist of exactly the given fields, in the given order.- Parameters:
expectedHeader- the expected header fields, must not benull- Returns:
- the validator
- Throws:
NullPointerException- ifnullis passed or the fields containnullelements- See Also:
-
containsAtLeast
Builds a validator that throws aCsvParseExceptionif 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 benull- Returns:
- the validator
- Throws:
NullPointerException- ifnullis passed or the fields containnullelements- See Also:
-
containsAtLeast
Builds a validator that throws aCsvParseExceptionif 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 benull- Returns:
- the validator
- Throws:
NullPointerException- ifnullis passed or the fields containnullelements- See Also:
-
validate
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, nevernull- Throws:
RuntimeException- if the header is not acceptable
-