View Javadoc
1   package com.opencsv.validators;
2   
3   import com.opencsv.exceptions.CsvValidationException;
4   
5   /**
6    * This is the interface for validators for a {@link String} read by the
7    * {@link java.io.Reader} in the {@link com.opencsv.CSVReader} before it is
8    * processed.
9    * <p>This should only be used if you have a very good understanding and full
10   * control of the data being processed.</p>
11   * <p>Since this is working on an individual line it may not be a full record
12   * if an element has a newline character in it.</p>
13   *
14   * @author Scott Conway
15   * @since 5.0
16   */
17  public interface LineValidator {
18      /**
19       * Performs the validation check on the string and returns the result.
20       *
21       * While not called directly in opencsv it is in the interface to provide
22       * an easy way to test if the validator is function properly.
23       *
24       * @param line {@link String} to be validated
25       * @return {@code true} if the line is valid, {@code false} otherwise
26       */
27      boolean isValid(String line);
28  
29      /**
30       * Performs the validation check on the string and throws an exception if
31       * invalid.
32       *
33       * @param line {@link String} to be validated
34       * @throws CsvValidationException Thrown if invalid. Should contain a
35       * message describing the error.
36       */
37      void validate(String line) throws CsvValidationException;
38  }