scriptella.util
Class StringUtils

java.lang.Object
  extended by scriptella.util.StringUtils

public final class StringUtils
extends java.lang.Object

Miscellaneous String/CharSequence utility methods.

Version:
1.0
Author:
Fyodor Kupolov

Method Summary
static java.lang.String consoleFormat(java.lang.String string)
          Formats specified string for console suitable representation.
static java.lang.String consoleFormat(java.lang.String string, int maxLength)
          Formats specified string for console suitable representation.
static boolean isAsciiWhitespacesOnly(java.lang.CharSequence cs)
          Checks if specified characters sequence is empty or contains only ascii whitespace characters.
static boolean isDecimalInt(java.lang.CharSequence cs)
          Checks if specified characters sequence represents a non negative decimal number.
static boolean isEmpty(java.lang.CharSequence cs)
          Returns true if characters sequence is empty (length=0) or null.
static java.lang.String nullsafeToString(java.lang.Object o)
          Returns Null safe string representation of specified object.
static java.lang.String nullsafeTrim(java.lang.CharSequence cs)
          Returns a trimmed value for specified charsequence
static java.lang.String removePrefix(java.lang.String string, java.lang.String prefix)
          Removes a prefix from a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isEmpty

public static boolean isEmpty(java.lang.CharSequence cs)
Returns true if characters sequence is empty (length=0) or null.

Parameters:
cs - characters sequence to test.
Returns:
true if characters sequence is empty (length=0) or null.

nullsafeTrim

public static java.lang.String nullsafeTrim(java.lang.CharSequence cs)
Returns a trimmed value for specified charsequence

Parameters:
cs - charsequence to trim.
Returns:
trimmed value for specified charsequence or empty string if cs=null

nullsafeToString

public static java.lang.String nullsafeToString(java.lang.Object o)
Returns Null safe string representation of specified object.

Parameters:
o - object to convert to String.
Returns:
o.toString() or "" if o==null.

isAsciiWhitespacesOnly

public static boolean isAsciiWhitespacesOnly(java.lang.CharSequence cs)
Checks if specified characters sequence is empty or contains only ascii whitespace characters.

Parameters:
cs - characters sequence to check.
Returns:
true if characters sequence is empty or contains only ascii whitespace characters.

isDecimalInt

public static boolean isDecimalInt(java.lang.CharSequence cs)
Checks if specified characters sequence represents a non negative decimal number.

Parameters:
cs - characters sequence to check.
Returns:
true if specified characters sequence represents a non negative decimal number.

consoleFormat

public static java.lang.String consoleFormat(java.lang.String string)
Formats specified string for console suitable representation.

All EOL char sequences are replaced with a single system line.separator, and all other whitespace sequences are replaced with a single space.

String larger than 10KB are trimmed.

Parameters:
string - string to format. Nulls are allowed.
Returns:
formatted string.

consoleFormat

public static java.lang.String consoleFormat(java.lang.String string,
                                             int maxLength)
Formats specified string for console suitable representation.

All EOL char sequences are replaced with a single system line.separator, and all other whitespace sequences are replaced with a single space.

Parameters:
string - string to format. Nulls are allowed.
maxLength - maximum number of characters to show or negative if the string cannot be trimmed.
Returns:
formatted string.

removePrefix

public static java.lang.String removePrefix(java.lang.String string,
                                            java.lang.String prefix)
Removes a prefix from a string.

Parameters:
string - original string. May be null.
prefix - prefix to to check and remove. May be null.
Returns:
string without a prefix, or unchanged string.


Copyright © Copyright 2006-2009 The Scriptella Project Team.