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.- Author:
- Kasper B. Graversen, Dominique De Vito, James Bassett
-
-
Field Summary
-
Fields inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor
next
-
-
Constructor Summary
Constructors Constructor Description StrReplace(java.lang.String regex, java.lang.String replacement)
Constructs a new StrReplace processor, which replaces each substring of the input that matches the regex with the supplied replacement.StrReplace(java.lang.String regex, java.lang.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
execute(java.lang.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
-
-
-
-
Constructor Detail
-
StrReplace
public StrReplace(java.lang.String regex, java.lang.String replacement)
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:
java.lang.IllegalArgumentException
- if regex is emptyjava.lang.NullPointerException
- if regex or replacement is nulljava.util.regex.PatternSyntaxException
- if regex is not a valid regular expression
-
StrReplace
public StrReplace(java.lang.String regex, java.lang.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.- Parameters:
regex
- the regular expression to matchreplacement
- the string to be substituted for each matchnext
- the next processor in the chain- Throws:
java.lang.IllegalArgumentException
- if regex is emptyjava.lang.NullPointerException
- if regex or replacement is nulljava.util.regex.PatternSyntaxException
- if regex is not a valid regular expression
-
-
Method Detail
-
execute
public java.lang.Object execute(java.lang.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 interfaceCellProcessor
- Parameters:
value
- the value to be processedcontext
- the CSV context- Returns:
- the result of cell processor execution
- Throws:
SuperCsvCellProcessorException
- if value is null
-
-