lv.gotika.engine.util
Class StringBuilderExt

java.lang.Object
  extended by lv.gotika.engine.util.StringBuilderExt

public final class StringBuilderExt
extends Object

Class contains frequently used string operations that are not provided by Java standard library.


Constructor Summary
StringBuilderExt()
           
 
Method Summary
static int count(String s, String target)
          For the given string counts the frequency of a specific substring.
static StringBuilder replace(StringBuilder sb, String target, String replacement)
          Replaces each substring of the given string buffer that matches the given substring with the given replacement.
static StringBuilder replaceEnd(StringBuilder sb, String target, String replacement)
          If the given string buffer ends with a certain substring then it is substituted with the given replacement.
static StringBuilder replaceStart(StringBuilder sb, String target, String replacement)
          If the given string buffer begins with a certain substring then it is substituted with the given replacement.
static String trimEnd(String s)
          Cuts off all the whitespaces (if any) that the given string ends with.
static StringBuilder trimEnd(StringBuilder s)
          Cuts off all the whitespaces (if any) that the given string buffer ends with.
static String trimStart(String s)
          Cuts off all the whitespaces (if any) that the given string starts with.
static StringBuilder trimStart(StringBuilder s)
          Cuts off all the whitespaces (if any) that the given string buffer starts with.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringBuilderExt

public StringBuilderExt()
Method Detail

replace

public static StringBuilder replace(StringBuilder sb,
                                    String target,
                                    String replacement)
Replaces each substring of the given string buffer that matches the given substring with the given replacement.

Example: replace(new StringBuilder("aaa"), "a", "ba") returns bababa.

Parameters:
sb - a string buffer.
target - a substring of interest.
replacement - a replacement string.
Returns:
the resulting string buffer.

replaceStart

public static StringBuilder replaceStart(StringBuilder sb,
                                         String target,
                                         String replacement)
If the given string buffer begins with a certain substring then it is substituted with the given replacement.

Parameters:
sb - a string buffer.
target - a substring of interest.
replacement - a replacement string.
Returns:
the resulting string buffer.

replaceEnd

public static StringBuilder replaceEnd(StringBuilder sb,
                                       String target,
                                       String replacement)
If the given string buffer ends with a certain substring then it is substituted with the given replacement.

Parameters:
sb - a string buffer.
target - a substring of interest.
replacement - a replacement string.
Returns:
the resulting string buffer.

count

public static int count(String s,
                        String target)
For the given string counts the frequency of a specific substring. Overlapping substrings are not taken into account.

Example: count("aabaaa", "aa") returns 2.

Parameters:
s - a string.
target - a substring of interest.
Returns:
the frequency of the substring in the string.

trimStart

public static StringBuilder trimStart(StringBuilder s)
Cuts off all the whitespaces (if any) that the given string buffer starts with.

Parameters:
s - a string buffer.
Returns:
the resulting string buffer (the same object).

trimStart

public static String trimStart(String s)
Cuts off all the whitespaces (if any) that the given string starts with.

Parameters:
s - a string.
Returns:
the resulting string (a new object).

trimEnd

public static StringBuilder trimEnd(StringBuilder s)
Cuts off all the whitespaces (if any) that the given string buffer ends with.

Parameters:
s - a string buffer.
Returns:
the resulting string buffer (the same object).

trimEnd

public static String trimEnd(String s)
Cuts off all the whitespaces (if any) that the given string ends with.

Parameters:
s - a string.
Returns:
the resulting string (a new object).