com.atlassian.renderer.v2
Class Replacer

java.lang.Object
  extended by com.atlassian.renderer.v2.Replacer

public class Replacer
extends java.lang.Object

Helper class for performing repeated pattern replacement. Why you can't do this with just the JDK regex classes, I don't know.


Constructor Summary
Replacer(java.util.regex.Pattern pattern, java.lang.String replacement)
          Convenience constructor which will not require any constant parts (the replacement is always attempted).
Replacer(java.util.regex.Pattern pattern, java.lang.String replacement, java.lang.String... necessaryConstantParts)
          Replaces a pattern with a replacement, optionally provided with an array of necessary constant parts.
 
Method Summary
 java.lang.String replace(java.lang.String str)
          Deprecated. since 7.1 - use replaceAllSkippingConstantsCheck(String) instead.
 java.lang.String replaceAll(java.lang.String str)
          Checks that str contains all of the required parts, and if so, calls replaceAllSkippingConstantsCheck(String) to perform the actual replacement.
 java.lang.String replaceAllSkippingConstantsCheck(java.lang.String str)
          This method does exactly the same thing as replaceAll(String), except that it bypasses the check for the necessaryConstantParts that were provided in the constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Replacer

public Replacer(java.util.regex.Pattern pattern,
                java.lang.String replacement)
Convenience constructor which will not require any constant parts (the replacement is always attempted).

Parameters:
pattern - as for Replacer(Pattern, String, String...)}
replacement - as for Replacer(Pattern, String, String...)

Replacer

public Replacer(java.util.regex.Pattern pattern,
                java.lang.String replacement,
                java.lang.String... necessaryConstantParts)
Replaces a pattern with a replacement, optionally provided with an array of necessary constant parts. The replaceAll(String) method will not evaluate the regular expression patterns unless the target string contains all of the necessary constant parts. This is a performance enhancement, as substring searches are cheaper than regular expression evaluation.

Parameters:
pattern - the regular expression pattern to match
replacement - the replacement expression
necessaryConstantParts - substrings that are checked by replaceAll(String) before evaluating the regular expressions.
Method Detail

replaceAll

public java.lang.String replaceAll(java.lang.String str)
Checks that str contains all of the required parts, and if so, calls replaceAllSkippingConstantsCheck(String) to perform the actual replacement.

Parameters:
str - the string to perform replacements upon
Returns:
str if the string did not satisfy the necessaryConstantParts or otherwise did not need to be modified; otherwise, the modified string after replacements have been performed
Throws:
java.lang.IndexOutOfBoundsException - as for replaceAllSkippingConstantsCheck(String)
java.lang.IllegalArgumentException - as for replaceAllSkippingConstantsCheck(String)

replace

@Deprecated
public java.lang.String replace(java.lang.String str)
Deprecated. since 7.1 - use replaceAllSkippingConstantsCheck(String) instead.

This method does exactly the same thing as replaceAll(String), except that it bypasses the check for the necessaryConstantParts that were provided in the constructor. The name of this method is unclear and might be mistaken as a replaceFirst operation, so it has been renamed to replaceAllSkippingConstantsCheck(String) for clarity.

Parameters:
str - the string to perform replacement on
Returns:
the string after replacement
Throws:
java.lang.IndexOutOfBoundsException - as for replaceAllSkippingConstantsCheck(String)
java.lang.IllegalArgumentException - as for replaceAllSkippingConstantsCheck(String)

replaceAllSkippingConstantsCheck

public java.lang.String replaceAllSkippingConstantsCheck(java.lang.String str)
This method does exactly the same thing as replaceAll(String), except that it bypasses the check for the necessaryConstantParts that were provided in the constructor.

Parameters:
str - the string to perform replacement on
Returns:
the string after replacement
Throws:
java.lang.IndexOutOfBoundsException - if the replacement string ends with an unescaped backslash (\) or dollar-sign ($), or if a group reference is present that has no matching group, such as $2 when the regular expression pattern only had one capturing group.
java.lang.IllegalArgumentException - if the replacement string includes a an unescaped dollar-sign ($) that is immediately followed by a non-digit, such as ($x).


Copyright © 2012 Atlassian. All Rights Reserved.