no.inspera.services.pedal.utils
Class StringUtils

java.lang.Object
  extended by no.inspera.services.pedal.utils.StringUtils

public class StringUtils
extends java.lang.Object

Utility class for working with String class.

Since:
20.12.2007
Version:
$Id: StringUtils.java 44171 2008-04-02 21:39:14Z naimdjon $
Author:
Naimdjon Takhirov

Field Summary
static java.lang.String ENCODING
           
 
Constructor Summary
StringUtils()
           
 
Method Summary
static boolean anyEquals(java.lang.String firstString, java.lang.String... strings)
          Compares firstString to the other specified strings.
static boolean anyEqualsIgnoreCase(java.lang.String firstString, java.lang.String... strings)
           
static boolean anyStartsWithIgnoreCase(java.lang.String firstString, java.lang.String... strings)
           
static void appendIfNotNull(java.lang.String tagName, java.lang.Object value, java.lang.StringBuffer s)
          Appends the following value as tag specified by tagName if value is not null
static java.lang.String capitalize(java.lang.String s)
           
static java.lang.String checkNull(java.lang.Object s)
           
static java.lang.String checkNull(java.lang.String s)
          Checks if the string is null.
static java.lang.String decode(java.lang.String str)
          Decodes the string with default system encoding.
static boolean empty(java.lang.Object s)
          Checks if the specified string is null or not.
static java.lang.String encode(java.lang.String str)
          Encodes the given string with the default system encoding.
static boolean endsWith(java.lang.String original, java.lang.String... suffixes)
          Tests if this string ends with the specified suffix.
static boolean equals(java.lang.String s1, java.lang.String s2)
          Compares this string to the specified object.
static boolean hasLength(java.lang.String s)
          Checks if the specified string is null or not.
static boolean isNumber(java.lang.String str)
          Checks if the specified string represents a number.
static boolean isParseableNumber(java.lang.Object obj)
          Checks if the type of the Object is string and checks if it can be parsed as a Number.
static boolean isTrue(java.lang.String str)
          Checks if the specified string is true.
static java.lang.String stackTraceToString(java.lang.Throwable t)
          Prints and returns a string that contains the stack trace of this exception
static boolean startsWith(java.lang.String s, java.lang.String prefix)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODING

public static final java.lang.String ENCODING
Constructor Detail

StringUtils

public StringUtils()
Method Detail

equals

public static boolean equals(java.lang.String s1,
                             java.lang.String s2)
Compares this string to the specified object. The result is true if and only if both arguments are null or s1 is a String object that represents the same sequence of characters as s2 object.

Parameters:
s1 - first String
s2 - second String
Returns:
true if both arguments are null or String.equals(Object) returns true

anyEquals

public static boolean anyEquals(java.lang.String firstString,
                                java.lang.String... strings)
Compares firstString to the other specified strings. The method permits null firstString argument and any of strings can be null as well.

Parameters:
firstString - the first string to be compared
strings - an array of strings to be compared with firstString
Returns:
true if any of strings equals to firstString.

anyEqualsIgnoreCase

public static boolean anyEqualsIgnoreCase(java.lang.String firstString,
                                          java.lang.String... strings)

anyStartsWithIgnoreCase

public static boolean anyStartsWithIgnoreCase(java.lang.String firstString,
                                              java.lang.String... strings)

stackTraceToString

public static java.lang.String stackTraceToString(java.lang.Throwable t)
Prints and returns a string that contains the stack trace of this exception

Parameters:
t - throwable that needs to be printed
Returns:
a string containing stack trace.

checkNull

public static java.lang.String checkNull(java.lang.String s)
Checks if the string is null. Returns an empty string if this string is null or the string itself otherwise.

This method is usefull when we would like to avoid null strings.

Parameters:
s - string to be checked.
Returns:
an empty string if this string is null or the string itself otherwise.

checkNull

public static java.lang.String checkNull(java.lang.Object s)

appendIfNotNull

public static void appendIfNotNull(java.lang.String tagName,
                                   java.lang.Object value,
                                   java.lang.StringBuffer s)
Appends the following value as tag specified by tagName if value is not null

Parameters:
tagName - the tag name of xml element
value - the value to be appended.
s - stringbuffer to be appended to.

encode

public static java.lang.String encode(java.lang.String str)
Encodes the given string with the default system encoding.

Parameters:
str - string to be encoded.
Returns:
encoded string.

decode

public static java.lang.String decode(java.lang.String str)
Decodes the string with default system encoding.

Parameters:
str - string to be decoded
Returns:
decoded string.

isNumber

public static boolean isNumber(java.lang.String str)
Checks if the specified string represents a number. Usefull for parsing strings that are numbers.

Parameters:
str - string representing number
Returns:
true if the str is a number, false otherwise

isParseableNumber

public static boolean isParseableNumber(java.lang.Object obj)
Checks if the type of the Object is string and checks if it can be parsed as a Number.

Parameters:
obj - Object to be checked.
Returns:
true if it can be parsed as a Number.

isTrue

public static boolean isTrue(java.lang.String str)
Checks if the specified string is true. The check is not case-censitive. The values to be checked true|false are(1|0, true|false, on|off).

Parameters:
str - string to be checked
Returns:
true if the str is true, false otherwise.

empty

public static boolean empty(java.lang.Object s)
Checks if the specified string is null or not. NOTE: This method trims the string before checking whether or not it is empty, thus sending an empty string will result in false.

Parameters:
s - string to be checked
Returns:
true if the string is empty and false otherwise.

startsWith

public static boolean startsWith(java.lang.String s,
                                 java.lang.String prefix)

hasLength

public static boolean hasLength(java.lang.String s)
Checks if the specified string is null or not. NOTE: This method trims the string before checking whether or not it is empty, thus sending an empty string will result in false.

Parameters:
s - string to be checked
Returns:
true if the string is not empty and false otherwise.

endsWith

public static boolean endsWith(java.lang.String original,
                               java.lang.String... suffixes)
Tests if this string ends with the specified suffix.

Parameters:
original -
suffixes - the suffixes.
Returns:
true if the character sequence represented by the suffixes argument is a suffix of the character sequence represented by this object; false otherwise. Note that the result will be true if the argument is the empty string or is equal to this String object as determined by the Object.equals(Object) method.

capitalize

public static java.lang.String capitalize(java.lang.String s)


Copyright © 2008 Naimdjon Takhirov (naimdjon@gmail.com). All Rights Reserved.