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
Fields Modifier and Type Field Description private java.util.regex.Pattern
regexPattern
private java.lang.String
replacement
-
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 Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
checkPreconditions(java.lang.String regex, java.lang.String replacement)
Checks the preconditions for creating a new StrRegExReplace processor.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
-
checkPreconditions
private static void checkPreconditions(java.lang.String regex, java.lang.String replacement)
Checks the preconditions for creating a new StrRegExReplace processor.- Parameters:
regex
- the supplied regular expressionreplacement
- the supplied replacement text- Throws:
java.lang.IllegalArgumentException
- if regex is emptyjava.lang.NullPointerException
- if regex or replacement is null
-
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
-
-