com.ls.util.text
Class StringTools

java.lang.Object
  |
  +--com.ls.util.text.StringTools

public class StringTools
extends Object

This class contains several implementations to manipulate Strings.

Usage example:

 Map replacements = new HashMap();
 replacements.put("a1", "value for 'a'");
 replacements.put("a2", "value for 'a2'");
 replacements.put("b1", "unused value for 'b'");
 StringTools.replace(sourcString, replacements);
 
 System.out.println(replacementMap.replace("This String contains text like a1 and a2"));

 
The output of this example would be
 this String contains the variables value for 'a' and value for 'a2' and
 

Version:
$Revision: 1.3 $
Author:
Last modified by $Author: PMandal $

Constructor Summary
StringTools()
           
 
Method Summary
static String removePattern(String encodedString, String removement)
          Remove a patterns from the sourceString
static String removePatterns(String encodedString, List replacementList)
          Remove all patterns in the replacementList from the sourceString and return it
static String removePatterns(String encodedString, String[] replacementList)
          Remove all patterns in the replacementList from the sourceString and return it
static String replacePattern(String encodedString, String pattern, char replacement)
          Decodes the pattern with the replacement in the source string and returns the decoded string.
static String replacePattern(String encodedString, String pattern, String replacement)
          Decodes the pattern with the replacement in the source string and returns the decoded string.
static String replacePatterns(String encodedString, Map replacementMap)
          Decodes all variables defined in this ReplacementMap in the given argument. If the encodedString or the replacementMap is null the encodedString will be returned unencoded like it got passed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringTools

public StringTools()
Method Detail

removePatterns

public static String removePatterns(String encodedString,
                                    String[] replacementList)
Remove all patterns in the replacementList from the sourceString and return it
Parameters:
encodedString - string to decode
replacementList - A list of patterns that should be removed from the source String.
Returns:
the decoded string

removePatterns

public static String removePatterns(String encodedString,
                                    List replacementList)
Remove all patterns in the replacementList from the sourceString and return it
Parameters:
encodedString - string to decode
replacementList - A list of patterns that should be removed from the source String.
Returns:
the decoded string

removePattern

public static String removePattern(String encodedString,
                                   String removement)
Remove a patterns from the sourceString
Parameters:
encodedString - string to decode
removement - The String that should be removed from the source String
Returns:
the decoded string

replacePatterns

public static String replacePatterns(String encodedString,
                                     Map replacementMap)
Decodes all variables defined in this ReplacementMap in the given argument.

If the encodedString or the replacementMap is null the encodedString will be returned unencoded like it got passed.

Parameters:
encodedString - string to decode
replacementMap - The map with the source Strings (keys) and the target Strings (values)
Returns:
the decoded string

replacePattern

public static String replacePattern(String encodedString,
                                    String pattern,
                                    String replacement)
Decodes the pattern with the replacement in the source string and returns the decoded string. If one of the parameters will be null the encoded String will be returned unchanged
Parameters:
encodedString - string to decode
pattern - The pattern that should be replaced by the replacement
replacement - The replacement of the search pattern
Returns:
the decoded string

replacePattern

public static String replacePattern(String encodedString,
                                    String pattern,
                                    char replacement)
Decodes the pattern with the replacement in the source string and returns the decoded string. If one of the parameters will be null the encoded String will be returned unchanged
Parameters:
encodedString - string to decode
pattern - The pattern that should be replaced by the replacement
replacement - the replace ment charecter
Returns:
the decoded string