org.javagen.agile.core.util
Class RegexRenamer

java.lang.Object
  extended by org.javagen.agile.core.util.RegexRenamer

public class RegexRenamer
extends Object

Itererates through a list of regular expressions and applies a replacement string when a match is found.

Currently only applies the first match found, ingnoring any remaining regex's in the list.

Regex and replacePatterns can be set as a single property string or added individually by calling addReplacementPattern.

For example to add a regex to remove 'Fk' & 'Pk' suffixes from a name such as 'PersonPk', you can call either:

addReplacementPattern("^([a-zA-Z]+)(Fk|Pk)$", "$1")
or
setRegexReplacePairs("^([a-zA-Z]+)(Fk|Pk)$>$1")

As a single string property the general form of the list is: regex1>replace1,regex2>replace2,...

The replacePattern can be any text interspersed with regex group replacement holders of the form $n, for example: text$1text$3text

Author:
Richard Easterling

Constructor Summary
RegexRenamer()
           
 
Method Summary
 void addReplacementPattern(String regex, String replacementPattern)
           
 List<org.javagen.agile.core.util.RegexRenamer.PatternHolder> getPatternHolders()
           
 boolean isEmpty()
           
 String rename(String name)
           
 void setRegexReplacePairs(String replacePatterns)
          Property file friendly means of adding regex-replacePattern pairs as comma-delineated list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegexRenamer

public RegexRenamer()
Method Detail

rename

public String rename(String name)

setRegexReplacePairs

public void setRegexReplacePairs(String replacePatterns)
Property file friendly means of adding regex-replacePattern pairs as comma-delineated list.

general form of the list: regex1>replace1,regex2>replace2,...

regex can be any regular expression excluding the > symbol.

The replacePattern can be any text interspersed with regex group replacement holders of the form $n, for example: text$1text$3text

For example to remove 'Fk' & 'Pk' suffixes use: ^([a-zA-Z]+)(Fk|Pk)$>$1


addReplacementPattern

public void addReplacementPattern(String regex,
                                  String replacementPattern)

getPatternHolders

public List<org.javagen.agile.core.util.RegexRenamer.PatternHolder> getPatternHolders()

isEmpty

public boolean isEmpty()


Copyright 2006-2006-2007 Outsource Cafe Inc.. All Rights Reserved.