com.calitha.util
Class StringUtil

java.lang.Object
  extended by com.calitha.util.StringUtil

public final class StringUtil
extends Object

The StringUtil class provides several static convenience methods for manipulating strings or producing string results.

Author:
Robert van Loenhout

Nested Class Summary
static class StringUtil.TextAlignment
           
 
Method Summary
static void fill(StringBuffer buffer, char filler, int size, StringUtil.TextAlignment align)
          Fills a buffer to a certain size with a filler character.
static String fill(String str, char filler, int size, StringUtil.TextAlignment align)
          Fills a string to a certain size with a filler character.
static String stackTraceToString(StackTraceElement[] stackTrace)
          Creates a string representation of a stack trace.
static String stripTags(String text)
          Strips all tags from text.
static String stripTags(String text, List<String> ignoreList)
          Strips the tags from text that are not in the ignoreList.
static String trimLeadingChar(String str, char ch)
          Trims leading characters from a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

fill

public static void fill(StringBuffer buffer,
                        char filler,
                        int size,
                        StringUtil.TextAlignment align)
Fills a buffer to a certain size with a filler character.

The alignment determines where to add the filler characters to keep the text in the buffer in that position. For example LEFT alignment means that the filler characters will be added to the right.

Possible choices are LEFT, RIGHT or CENTER. Default is LEFT.

The buffer is filled in the left or right side.

Parameters:
buffer - buffer to be filled
filler - character that is used to fill the buffer
size - size to which the buffer will grow
align - alignment of text in the buffer
Throws:
IllegalArgumentException - if the buffer argument is null

fill

public static String fill(String str,
                          char filler,
                          int size,
                          StringUtil.TextAlignment align)
Fills a string to a certain size with a filler character.

The alignment determines where to add the filler characters to keep the text in that position. For example LEFT alignment means that the filler characters will be added to the right. Possible choices are LEFT, RIGHT or CENTER

Parameters:
str - string that will be filled
filler - filler character
size - size to which the buffer will grow
align - alignment of text in the buffer
Returns:
new filled string
Throws:
IllegalArgumentException - if the buffer argument is null
See Also:
fill(StringBuffer, char, int, TextAlignment)

trimLeadingChar

public static String trimLeadingChar(String str,
                                     char ch)
Trims leading characters from a string.

Parameters:
str - string that is trimmed
ch - character being trimmed from the string
Returns:
trimmed string
Throws:
IllegalArgumentException - if an argument is null

stackTraceToString

public static String stackTraceToString(StackTraceElement[] stackTrace)
Creates a string representation of a stack trace.

Parameters:
stackTrace - stack trace
Returns:
string that show the stack trace
Throws:
IllegalArgumentException - if an argument is null

stripTags

public static String stripTags(String text)
Strips all tags from text.

Parameters:
text - text input
Returns:
result without tags
Throws:
IllegalArgumentException - if an argument is null

stripTags

public static String stripTags(String text,
                               List<String> ignoreList)
Strips the tags from text that are not in the ignoreList.

Parameters:
text - text input
ignoreList - list of tags to be kept in the input or null if all tags must be removed
Returns:
result without the tags
Throws:
IllegalArgumentException - if the text argument is null