Package org.supercsv.cellprocessor
Class StrReplace
java.lang.Object
org.supercsv.cellprocessor.CellProcessorAdaptor
org.supercsv.cellprocessor.StrReplace
- All Implemented Interfaces:
BoolCellProcessor
,CellProcessor
,DateCellProcessor
,DoubleCellProcessor
,LongCellProcessor
,StringCellProcessor
public class StrReplace
extends CellProcessorAdaptor
implements BoolCellProcessor, DateCellProcessor, DoubleCellProcessor, LongCellProcessor, StringCellProcessor
Replaces each substring of the input string that matches the given regular expression with the given replacement. The
regular expression pattern is compiled once then reused for efficiency.
-
Field Summary
FieldsFields inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor
next
-
Constructor Summary
ConstructorsConstructorDescriptionStrReplace
(String regex, String replacement) Constructs a new StrReplace processor, which replaces each substring of the input that matches the regex with the supplied replacement.StrReplace
(String regex, String replacement, StringCellProcessor next) Constructs a new StrReplace processor, which replaces each substring of the input that matches the regex with the supplied replacement, then calls the next processor in the chain. -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
checkPreconditions
(String regex, String replacement) Checks the preconditions for creating a new StrRegExReplace processor.execute
(Object value, CsvContext context) This method is invoked by the framework when the processor needs to process data or check constraints.Methods inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor
toString, validateInputNotNull
-
Field Details
-
regexPattern
-
replacement
-
-
Constructor Details
-
StrReplace
Constructs a new StrReplace processor, which replaces each substring of the input that matches the regex with the supplied replacement.- Parameters:
regex
- the regular expression to matchreplacement
- the string to be substituted for each match- Throws:
IllegalArgumentException
- if regex is emptyNullPointerException
- if regex or replacement is nullPatternSyntaxException
- if regex is not a valid regular expression
-
StrReplace
Constructs a new StrReplace processor, which replaces each substring of the input that matches the regex with the supplied replacement, then calls the next processor in the chain.- Parameters:
regex
- the regular expression to matchreplacement
- the string to be substituted for each matchnext
- the next processor in the chain- Throws:
IllegalArgumentException
- if regex is emptyNullPointerException
- if regex or replacement is nullPatternSyntaxException
- if regex is not a valid regular expression
-
-
Method Details
-
checkPreconditions
Checks the preconditions for creating a new StrRegExReplace processor.- Parameters:
regex
- the supplied regular expressionreplacement
- the supplied replacement text- Throws:
IllegalArgumentException
- if regex is emptyNullPointerException
- if regex or replacement is null
-
execute
This method is invoked by the framework when the processor needs to process data or check constraints.- Specified by:
execute
in interfaceCellProcessor
- Parameters:
value
- the value to be processedcontext
- the CSV context- Returns:
- the result of cell processor execution
- Throws:
SuperCsvCellProcessorException
- if value is null
-