com.abstractics.utils
Class StringUtils

java.lang.Object
  extended bycom.abstractics.utils.StringUtils

public final class StringUtils
extends java.lang.Object

Various static methods to perform simple String manipulations

Version:
$Id: StringUtils.java,v 1.2 2006/03/15 05:37:33 andyman99 Exp $
Author:
Andrew Lawrence, Copyright 2006 Abstractics, L.L.C., Licensed under the Apache License, Version 2.0

Method Summary
static java.lang.String classNameOnly(java.lang.Class clazz)
           
static java.lang.String ensureString(java.lang.String string)
          Given a String object, will return the String object itself, or if it is null, then and empty String is returned.
static java.lang.String ensureString(java.lang.String string, java.lang.String defaultValue)
          Given a String object, will return the String object itself, or if it is null, then the specified defaultValue is returned.
static java.lang.String fill(char ch, int size)
          Given a character and the number of those characters to use, returns a String composed of that many of the character.
i.e.
static boolean isEmpty(java.lang.String str)
           
static java.lang.String maxLength(java.lang.String str, int length)
          Returns the string making sure that it does not exceed the given max length, and if it does, it is truncated to that length.
static java.lang.String padLeft(java.lang.String str, int totalLength)
          Given a string and a total length that it should be, this method appends spaces repeatedly onto the left of the string to make the string the correct length, or truncates the string
static java.lang.String padLeft(java.lang.String str, int totalLength, char padChar)
          Given a string and a total length that it should be, this method appends the given character repeatedly onto the left of the string to make the string the correct length, or truncates the string
static java.lang.String padRight(java.lang.String str, int totalLength)
          Given a string and a total length that it should be, this method appends spaces repeatedly onto the right of the string to make the string the correct length, or truncates the string
static java.lang.String padRight(java.lang.String str, int totalLength, char padChar)
          Given a string and a total length that it should be, this method appends the given character repeatedly onto the right of the string to make the string the correct length, or truncates the string
static java.lang.String stripChars(java.lang.String s, char[] stripChars)
           
static java.lang.String stripNewlines(java.lang.String str)
          Given a String, any newlines will be removed and replaced with a space
static java.lang.String toUpperCase(java.lang.String str)
           
static java.lang.String trimString(java.lang.String string)
          Returns a trimmed string, and if the trimming results in a zero length String, returns null;
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

classNameOnly

public static java.lang.String classNameOnly(java.lang.Class clazz)
Parameters:
clazz - Class to get class name for
Returns:
The class name only, without the package

padRight

public static java.lang.String padRight(java.lang.String str,
                                        int totalLength)
Given a string and a total length that it should be, this method appends spaces repeatedly onto the right of the string to make the string the correct length, or truncates the string

Parameters:
str - Original String
totalLength - Final length that the String should be
Returns:
String that is the length given

padRight

public static java.lang.String padRight(java.lang.String str,
                                        int totalLength,
                                        char padChar)
Given a string and a total length that it should be, this method appends the given character repeatedly onto the right of the string to make the string the correct length, or truncates the string

Parameters:
str - Original String
totalLength - Final length that the String should be
padChar - The character to use for padding
Returns:
String that is the length given

padLeft

public static java.lang.String padLeft(java.lang.String str,
                                       int totalLength)
Given a string and a total length that it should be, this method appends spaces repeatedly onto the left of the string to make the string the correct length, or truncates the string

Parameters:
str - Original String
totalLength - Final length that the String should be
Returns:
String that is the length given

padLeft

public static java.lang.String padLeft(java.lang.String str,
                                       int totalLength,
                                       char padChar)
Given a string and a total length that it should be, this method appends the given character repeatedly onto the left of the string to make the string the correct length, or truncates the string

Parameters:
str - Original String
totalLength - Final length that the String should be
padChar - The character to use for padding
Returns:
String that is the length given

isEmpty

public static boolean isEmpty(java.lang.String str)
Parameters:
str -
Returns:
Returns true if the string is null or its trimmed length is 0, otherwise returns false

toUpperCase

public static java.lang.String toUpperCase(java.lang.String str)
Parameters:
str -
Returns:
If str is null, returns null, otherwise returns str.toUpperCase()

fill

public static java.lang.String fill(char ch,
                                    int size)
Given a character and the number of those characters to use, returns a String composed of that many of the character.
i.e. fill('b', 5) --> "bbbbb"

Parameters:
ch -
size -
Returns:

trimString

public static java.lang.String trimString(java.lang.String string)
Returns a trimmed string, and if the trimming results in a zero length String, returns null;

Parameters:
string -
Returns:

ensureString

public static java.lang.String ensureString(java.lang.String string)
Given a String object, will return the String object itself, or if it is null, then and empty String is returned.

Parameters:
string - String to check
Returns:
String -- will not be null

ensureString

public static java.lang.String ensureString(java.lang.String string,
                                            java.lang.String defaultValue)
Given a String object, will return the String object itself, or if it is null, then the specified defaultValue is returned.

Parameters:
string - String to check
defaultValue - The default String to return if string is null
Returns:
String -- will not be null

stripChars

public static java.lang.String stripChars(java.lang.String s,
                                          char[] stripChars)

maxLength

public static java.lang.String maxLength(java.lang.String str,
                                         int length)
Returns the string making sure that it does not exceed the given max length, and if it does, it is truncated to that length.

Parameters:
str - String to check
Returns:
String ensured to be no longer than length

stripNewlines

public static java.lang.String stripNewlines(java.lang.String str)
Given a String, any newlines will be removed and replaced with a space

Parameters:
str -
Returns: