Mp3dings 
20100427

net.sourceforge.mp3dings.filter
Class StringReplacer

java.lang.Object
  extended by net.sourceforge.mp3dings.utils.Bean
      extended by net.sourceforge.mp3dings.filter.FilterBean
          extended by net.sourceforge.mp3dings.filter.AbstractStringFilter
              extended by net.sourceforge.mp3dings.filter.StringReplacer
All Implemented Interfaces:
Serializable, Filter

public class StringReplacer
extends AbstractStringFilter

A filter that performs one or more string/regular expression substitution.

Version:
$Revision: 117 $ ($Date: 2007-11-09 12:09:50 +0100 (Fr, 09 Nov 2007) $)
Author:
Moritz Ringler
See Also:
Serialized Form

Field Summary
static String PROPERTY_RULES
           
 
Fields inherited from class net.sourceforge.mp3dings.utils.Bean
L_NO_ID, NO_ID, PROPERTY_ID, PROPERTY_NAME
 
Constructor Summary
StringReplacer()
          Constructs a new empty case-sensitive ruleset.
 
Method Summary
 void addRule(String pattern, String replacement)
          Adds a new rule to this ruleset.
protected  Pattern compile(String pattern)
           
 String[] deleteRule(int i)
          Deletes the rule with index i from this ruleset.
 boolean equals(Object o)
           
 String filterString(String val)
          Applies all rules in this ruleset to the specified string and returns the result.
 String[] getRule(int i)
          Returns the rule with index i as a string pair.
protected  Vector getRuleList()
           
 String[][] getRulesAsStrings()
          Returns the ruleset as an array of string pairs.
 int getSize()
          Returns the number of rules currently in this ruleset.
 int hashCode()
           
 void insertRule(String pattern, String replacement, int i)
          Adds a new rule to this ruleset.
 boolean isCaseSensitive()
           
 boolean isRegExp()
           
 boolean isWordMatch()
           
static Bean load(Preferences pref, String key)
          returns a StringReplacer or null
protected  void replaceRule(String pattern, String replacement, int i)
           
protected  String[] ruleToStrings(Object[] rule, String[] result)
           
 void setCaseSensitive(boolean b)
           
 void setFlags()
           
 void setRegExp(boolean b)
           
 void setRulesAsStrings(String[][] rs)
          This method is public as an implementation side effect.
 void setWordMatch(boolean b)
           
 String toString()
          Returns a String representation of this Object.
 
Methods inherited from class net.sourceforge.mp3dings.filter.AbstractStringFilter
filter
 
Methods inherited from class net.sourceforge.mp3dings.utils.Bean
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getConstraints, getId, getName, getPropertyChangeListeners, getPropertyChangeListeners, isSavable, load, removePropertyChangeListener, removePropertyChangeListener, save, save, setId, setName
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PROPERTY_RULES

public static final String PROPERTY_RULES
See Also:
Constant Field Values
Constructor Detail

StringReplacer

public StringReplacer()
Constructs a new empty case-sensitive ruleset.

Method Detail

load

public static Bean load(Preferences pref,
                        String key)
returns a StringReplacer or null


getRuleList

protected Vector getRuleList()

isRegExp

public boolean isRegExp()

setRegExp

public void setRegExp(boolean b)

isCaseSensitive

public boolean isCaseSensitive()

setCaseSensitive

public void setCaseSensitive(boolean b)

isWordMatch

public boolean isWordMatch()

setWordMatch

public void setWordMatch(boolean b)

toString

public String toString()
Returns a String representation of this Object.

Overrides:
toString in class Object
Returns:
a String of rules

addRule

public void addRule(String pattern,
                    String replacement)
Adds a new rule to this ruleset.

Parameters:
pattern - a string or regular expression pattern matching the parts of the input that you want replaced
replacement - the replacement string

insertRule

public void insertRule(String pattern,
                       String replacement,
                       int i)
Adds a new rule to this ruleset.

Parameters:
pattern - the matching pattern (string or regular expression)
replacement - the replacement string
i - the index of the rule in the ruleset. For two rules the one with smaller index will have higher precedence.

compile

protected Pattern compile(String pattern)

replaceRule

protected void replaceRule(String pattern,
                           String replacement,
                           int i)

setFlags

public void setFlags()

filterString

public String filterString(String val)
Applies all rules in this ruleset to the specified string and returns the result.

Specified by:
filterString in class AbstractStringFilter
Parameters:
val - the String to process (remains unchanged)
Returns:
a new String resulting from applying all replacement rules to the input.

getSize

public int getSize()
Returns the number of rules currently in this ruleset.

Returns:
the number of rules in the ruleset

getRule

public String[] getRule(int i)
Returns the rule with index i as a string pair. Equivalent to but more efficient than getRulesAsStrings()[i].

Parameters:
i - the index of the rule returned
Returns:
the specified rule as a string array with length 2

ruleToStrings

protected String[] ruleToStrings(Object[] rule,
                                 String[] result)

getRulesAsStrings

public String[][] getRulesAsStrings()
Returns the ruleset as an array of string pairs. The first element (index 0) in each pair is the matching pattern and the second element (index 1) is the replacement.

Returns:
an array of rules as string pairs
See Also:
getRule(int)

setRulesAsStrings

public void setRulesAsStrings(String[][] rs)
This method is public as an implementation side effect. It must never be invoked by a client.


deleteRule

public String[] deleteRule(int i)
Deletes the rule with index i from this ruleset.

Parameters:
i - the index of the rule to delete

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

Mp3dings 
20100427