net.sf.mmm.util.transformer.base
Class RegexStringTransformer

java.lang.Object
  extended by net.sf.mmm.util.transformer.base.RegexStringTransformer
All Implemented Interfaces:
Transformer<String>
Direct Known Subclasses:
RegexStringTransformerRule

public class RegexStringTransformer
extends Object
implements Transformer<String>

This class converts a string by matching a given regular expression Pattern and if it partially matches replacing the match(es) with a given replacement.

Since:
1.0.2
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
private  Pattern pattern
           
private  boolean replaceAll
           
private  String replacement
           
 
Constructor Summary
RegexStringTransformer()
          The non-arg constructor.
RegexStringTransformer(Pattern pattern, String replacement, boolean replaceAll)
          The constructor.
 
Method Summary
 Pattern getPattern()
           
 String getReplacement()
           
 boolean isReplaceAll()
           
 String transform(String original)
          This method transforms a given original value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pattern

private Pattern pattern
See Also:
getPattern()

replacement

private String replacement
See Also:
getReplacement()

replaceAll

private boolean replaceAll
See Also:
isReplaceAll()
Constructor Detail

RegexStringTransformer

public RegexStringTransformer()
The non-arg constructor.
NOTE:
This constructor should not be called directly! It is only intended for reflective access (e.g. for JAXB).


RegexStringTransformer

public RegexStringTransformer(Pattern pattern,
                              String replacement,
                              boolean replaceAll)
The constructor.

Parameters:
pattern - is the pattern used for conversion.
replacement - is the replacement to fill in the string to convert.
replaceAll - - if true Matcher.replaceAll(String) will be used, else if false Matcher.replaceFirst(String).
Method Detail

getPattern

public Pattern getPattern()
Returns:
the pattern

isReplaceAll

public boolean isReplaceAll()
Returns:
the replaceAll

getReplacement

public String getReplacement()
Returns:
the replacement

transform

public String transform(String original)
This method transforms a given original value. This value must NOT be modified by this method. To change the original value a new value has to be created and returned instead. If the value should NOT be changed, the original value (the exact same instance) should be returned.

Specified by:
transform in interface Transformer<String>
Parameters:
original - is the original value.
Returns:
the transformed value. May only be null if explicitly documented by the implementation. The receiver of a Transformer should also document if null is a legal result.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.