Class StrRegEx

java.lang.Object
org.supercsv.cellprocessor.CellProcessorAdaptor
org.supercsv.cellprocessor.constraint.StrRegEx
All Implemented Interfaces:
CellProcessor, StringCellProcessor

public class StrRegEx extends CellProcessorAdaptor implements StringCellProcessor
This constraint ensures that the input data matches the given regular expression.
Since:
1.50
  • Field Details

    • regex

      private final String regex
    • regexPattern

      private final Pattern regexPattern
    • REGEX_MSGS

      private static final Map<String,String> REGEX_MSGS
  • Constructor Details

    • StrRegEx

      public StrRegEx(String regex)
      Constructs a new StrRegEx processor, which ensures that the input data matches the given regular expression.
      Parameters:
      regex - the regular expression to match
      Throws:
      NullPointerException - if regex is null
      IllegalArgumentException - if regex is empty
      PatternSyntaxException - if regex is not a valid regular expression
    • StrRegEx

      public StrRegEx(String regex, StringCellProcessor next)
      Constructs a new StrRegEx processor, which ensures that the input data matches the given regular expression, then calls the next processor in the chain.
      Parameters:
      regex - the regular expression to match
      next - the next processor in the chain
      Throws:
      NullPointerException - if regex is null
      IllegalArgumentException - if regex is empty
      PatternSyntaxException - if regex is not a valid regular expression
  • Method Details

    • checkPreconditions

      private static void checkPreconditions(String regex)
      Checks the preconditions for creating a new StrRegEx processor.
      Parameters:
      regex - the regular expression to match
      Throws:
      NullPointerException - if regex is null
      IllegalArgumentException - if regex is empty
    • execute

      public Object execute(Object value, CsvContext context)
      This method is invoked by the framework when the processor needs to process data or check constraints.
      Specified by:
      execute in interface CellProcessor
      Parameters:
      value - the value to be processed
      context - the CSV context
      Returns:
      the result of cell processor execution
      Throws:
      SuperCsvCellProcessorException - if value is null
      SuperCsvConstraintViolationException - if value doesn't match the regular expression
    • registerMessage

      public static void registerMessage(String regex, String message)
      Register a message detailing in plain language the constraint representing a regular expression. For example, the regular expression \d{0,6}(\.\d{0,3})? could be associated with the message "up to 6 digits whole digits, followed by up to 3 fractional digits".
      Parameters:
      regex - the regular expression
      message - the message to associate with the regex