Class StrRegEx
java.lang.Object
org.supercsv.cellprocessor.CellProcessorAdaptor
org.supercsv.cellprocessor.constraint.StrRegEx
- All Implemented Interfaces:
CellProcessor, StringCellProcessor
This constraint ensures that the input data matches the given regular expression.
- Since:
- 1.50
-
Field Summary
FieldsFields inherited from class CellProcessorAdaptor
next -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new StrRegEx processor, which ensures that the input data matches the given regular expression.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. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidcheckPreconditions(String regex) Checks the preconditions for creating a new StrRegEx processor.execute(Object value, CsvContext context) This method is invoked by the framework when the processor needs to process data or check constraints.static voidregisterMessage(String regex, String message) Register a message detailing in plain language the constraint representing a regular expression.Methods inherited from class CellProcessorAdaptor
toString, validateInputNotNull
-
Field Details
-
regex
-
regexPattern
-
REGEX_MSGS
-
-
Constructor Details
-
StrRegEx
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 nullIllegalArgumentException- if regex is emptyPatternSyntaxException- if regex is not a valid regular expression
-
StrRegEx
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 matchnext- the next processor in the chain- Throws:
NullPointerException- if regex is nullIllegalArgumentException- if regex is emptyPatternSyntaxException- if regex is not a valid regular expression
-
-
Method Details
-
checkPreconditions
Checks the preconditions for creating a new StrRegEx processor.- Parameters:
regex- the regular expression to match- Throws:
NullPointerException- if regex is nullIllegalArgumentException- if regex is empty
-
execute
This method is invoked by the framework when the processor needs to process data or check constraints.- Specified by:
executein interfaceCellProcessor- Parameters:
value- the value to be processedcontext- the CSV context- Returns:
- the result of cell processor execution
- Throws:
SuperCsvCellProcessorException- if value is nullSuperCsvConstraintViolationException- if value doesn't match the regular expression
-
registerMessage
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 expressionmessage- the message to associate with the regex
-