com.plumtree.openfoundation.util
Class XPStringUtility

java.lang.Object
  extended bycom.plumtree.openfoundation.util.XPStringUtility

public class XPStringUtility
extends java.lang.Object

XPStringUtility contains the utility methods that operate on strings.


Field Summary
static java.lang.String DEFAULT_ENCODING
          Default byte encoding for characters and strings.
 
Constructor Summary
XPStringUtility()
           
 
Method Summary
static char CharAt(java.lang.String source, int index)
          Return the value of the character at the specified index in the source string, for a non-null source and an index in bounds.
static int Compare(java.lang.String stringA, java.lang.String stringB)
          Compares two strings and returns an integer value that represents if the given strings are equal or stringA is greater that stringB or stringA is less than stringB.
static int CompareIgnoreCase(java.lang.String stringA, java.lang.String stringB)
          Compares two strings and returns an integer value that represents if the given strings are equal or stringA is greater that stringB or stringA is less than stringB.
static boolean EndsWith(java.lang.String source, java.lang.String token)
          Tests if this string ends with the specified suffix.
static boolean EqualsIgnoreCase(java.lang.String stringA, java.lang.String stringB)
          Compares two strings, ignoring case considerations.
static java.lang.String ForceEndsWith(java.lang.String strIn, java.lang.String strEndsWith)
          This method forces strIn to end with strEndsWith.
static byte[] GetBytes(java.lang.String str)
          Encodes this string into a sequence of bytes using the platform's default charset, storing the result into a new byte array.
static char[] GetChars(java.lang.String str)
          Encodes this string into a sequence of chars, storing the result into a new char array.
static int IndexOf(java.lang.String source, char ch)
          Wraps String source.indexOf(ch), returning -1 if the character is not found.
static int IndexOf(java.lang.String source, char ch, int fromIndex)
          Wraps String source.indexOf(ch, fromIndex), returning -1 if the character is not found.
static int IndexOf(java.lang.String source, java.lang.String token)
          Wraps String source.indexOf(token), returning -1 if the token is not found.
static int IndexOf(java.lang.String source, java.lang.String token, int fromIndex)
          Wraps String source.indexOf(token, fromIndex), returning -1 if the token is not found.
static int LastIndexOf(java.lang.String source, char ch)
          Wraps String source.lastIndexOf(ch), returning -1 if the character is not found.
static int LastIndexOf(java.lang.String source, char ch, int fromIndex)
          Wraps String source.lastIndexOf(ch, fromIndex), returning -1 if the character is not found.
static int LastIndexOf(java.lang.String source, java.lang.String token)
          Wraps String source.lastIndexOf(token), returning -1 if the token is not found.
static int LastIndexOf(java.lang.String source, java.lang.String token, int fromIndex)
          Wraps String source.lastIndexOf(token, fromIndex), returning -1 if the token is not found.
static boolean StartsWith(java.lang.String source, java.lang.String token)
          Tests if this string starts with the specified prefix.
static java.lang.String Substring(java.lang.String source, int startIndex)
          Returns a new string that is a substring of this string.
static java.lang.String Substring(java.lang.String source, int startIndex, int endIndex)
          Returns a new string that is a substring of this string.
static java.lang.String ToLowerCase(java.lang.String source)
          Converts the supplied String instance to lower case.
static java.lang.String ToLowerCase(java.lang.String source, XPLocale locale)
          Converts the supplied String instance to lower case with regard to the supplied locale.
static java.lang.String ToUpperCase(java.lang.String source)
          Converts the supplied String instance to upper case.
static java.lang.String ToUpperCase(java.lang.String source, XPLocale locale)
          Converts the supplied String instance to upper case with regard to the supplied locale.
static java.lang.String Trim(java.lang.String str)
          Returns a new string instance based on the source, trimmed of leading and trailing whitespace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ENCODING

public static final java.lang.String DEFAULT_ENCODING
Default byte encoding for characters and strings.

See Also:
Constant Field Values
Constructor Detail

XPStringUtility

public XPStringUtility()
Method Detail

CharAt

public static char CharAt(java.lang.String source,
                          int index)
Return the value of the character at the specified index in the source string, for a non-null source and an index in bounds.

Parameters:
source - a non-null source string.
index - value in bounds.
Returns:
the value of the character at the specified index in the source string.

Compare

public static int Compare(java.lang.String stringA,
                          java.lang.String stringB)
Compares two strings and returns an integer value that represents if the given strings are equal or stringA is greater that stringB or stringA is less than stringB. This method performs a case-sensitive comparison.

Parameters:
stringA - The first string
stringB - The second string
Returns:
A signed integer indicating the lexical relationship between the given strings. Less than 0 - stringA is less than stringB Zero - stringA equals stringB Greater than 0 - stringA is greater than stringB

CompareIgnoreCase

public static int CompareIgnoreCase(java.lang.String stringA,
                                    java.lang.String stringB)
Compares two strings and returns an integer value that represents if the given strings are equal or stringA is greater that stringB or stringA is less than stringB. This method performs a case-insensitive comparison.

Parameters:
stringA - The first string
stringB - The second string
Returns:
A signed integer indicating the lexical relationship between the given strings. Less than 0 - stringA is less than stringB Zero - stringA equals stringB Greater than 0 - stringA is greater than stringB

EndsWith

public static boolean EndsWith(java.lang.String source,
                               java.lang.String token)
Tests if this string ends with the specified suffix.

Parameters:
source - A non null string.
token - the suffix.
Returns:
true if the character sequence represented by the 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

EqualsIgnoreCase

public static boolean EqualsIgnoreCase(java.lang.String stringA,
                                       java.lang.String stringB)
Compares two strings, ignoring case considerations. Two strings are considered equal ignoring case if they are of the same length, and corresponding characters in the two strings are equal ignoring case.

Parameters:
stringA - The first string
stringB - The second string
Returns:
true if the argument is not null and the Strings are equal, ignoring case; false otherwise.

ForceEndsWith

public static java.lang.String ForceEndsWith(java.lang.String strIn,
                                             java.lang.String strEndsWith)
This method forces strIn to end with strEndsWith. If strIn already ends with strEndsWith then you just get strIn back. Examples: ForceEndsWith("http://www.yahoo.com", "/") = "http://www.yahoo.com/" ForceEndsWith("http://www.yahoo.com/", "/") = "http://www.yahoo.com/" ForceEndsWith(null, "/") = null

Parameters:
strIn - The string that you want to end with some other string
strEndsWith - The string you want strIn to end with
Returns:
The original string pluse the "endswith" string

GetBytes

public static byte[] GetBytes(java.lang.String str)
Encodes this string into a sequence of bytes using the platform's default charset, storing the result into a new byte array.

Parameters:
str - The input string
Returns:
The resultant byte array.

GetChars

public static char[] GetChars(java.lang.String str)
Encodes this string into a sequence of chars, storing the result into a new char array.

Parameters:
str - The input string
Returns:
The resultant char array.

IndexOf

public static int IndexOf(java.lang.String source,
                          char ch)
Wraps String source.indexOf(ch), returning -1 if the character is not found. Any exceptions are returned wrapped as an appropriate XPException subtype.

Parameters:
source - non-null source string
ch - character to find in source
Returns:
index of the first occurrence of the character, or -1 if not found.
Throws:
XPIllegalArgumentException - if source is null.

IndexOf

public static int IndexOf(java.lang.String source,
                          char ch,
                          int fromIndex)
Wraps String source.indexOf(ch, fromIndex), returning -1 if the character is not found. Any exceptions are returned wrapped as an appropriate XPException subtype.

Parameters:
source - non-null source string
ch - character to find in source
fromIndex - index in source to start looking for token, 0 <= index < source length.
Returns:
index of first occurrence of ch at or after fromIndex, or -1 if not found.
Throws:
XPIllegalArgumentException - if source is null or fromIndex is out of range.

IndexOf

public static int IndexOf(java.lang.String source,
                          java.lang.String token)
Wraps String source.indexOf(token), returning -1 if the token is not found. Any exceptions are returned wrapped as an appropriate XPException subtype.

Parameters:
source - non-null source string
token - substring to find in source
Returns:
index of token in source string, or -1 if not found.
Throws:
XPIllegalArgumentException - if source or token is null, or token is empty.

IndexOf

public static int IndexOf(java.lang.String source,
                          java.lang.String token,
                          int fromIndex)
Wraps String source.indexOf(token, fromIndex), returning -1 if the token is not found. Any exceptions are returned wrapped as an appropriate XPException subtype.

Parameters:
source - non-null source string
token - substring to find in source
fromIndex - index in source to start looking for token, 0 <= index < source length.
Returns:
index of first occurrence of token in source at or after fromIndex.
Throws:
XPIllegalArgumentException - if source or token is null or token is empty or fromIndex is out of range.

LastIndexOf

public static int LastIndexOf(java.lang.String source,
                              char ch)
Wraps String source.lastIndexOf(ch), returning -1 if the character is not found. Any exceptions are returned wrapped as an appropriate XPException subtype.

Parameters:
source - non-null source string
ch - character to find in source
Returns:
index of last occurrence of ch in source or -1 if not found.
Throws:
XPIllegalArgumentException - if source is null.

LastIndexOf

public static int LastIndexOf(java.lang.String source,
                              char ch,
                              int fromIndex)
Wraps String source.lastIndexOf(ch, fromIndex), returning -1 if the character is not found. Any exceptions are returned wrapped as an appropriate XPException subtype.

Parameters:
source - non-null source string
ch - character to find
fromIndex - index in source to start looking for ch, 0 <= index < source length.
Returns:
index of last occurrence of ch in source at or after fromIndex or -1 if not found.
Throws:
XPIllegalArgumentException - if source is null or fromIndex is out of bounds.

LastIndexOf

public static int LastIndexOf(java.lang.String source,
                              java.lang.String token)
Wraps String source.lastIndexOf(token), returning -1 if the token is not found.

Parameters:
source - non-null source string
token - substring to find in source
Returns:
index of last occurrence of token in source or -1 if not found.
Throws:
XPIllegalArgumentException - if source is null, token is null, or token is empty string.

LastIndexOf

public static int LastIndexOf(java.lang.String source,
                              java.lang.String token,
                              int fromIndex)
Wraps String source.lastIndexOf(token, fromIndex), returning -1 if the token is not found.

Parameters:
source - non-null source string
token - substring to find in source
fromIndex - index in source to start looking for token, 0 <= index < source length.
Returns:
index of last occurrence of token in source or -1 if not found.
Throws:
XPIllegalArgumentException - if source is null, token is null, token is empty string, or fromIndex is out of range.

StartsWith

public static boolean StartsWith(java.lang.String source,
                                 java.lang.String token)
Tests if this string starts with the specified prefix.

Parameters:
source - String.
token - the prefix.
Returns:
true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise. Note also that true will be returned if the argument is an empty string or is equal to this String object.

Substring

public static java.lang.String Substring(java.lang.String source,
                                         int startIndex)
Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string.

Parameters:
source - String.
startIndex - the beginning index, inclusive.
Returns:
the specified substring.

Substring

public static java.lang.String Substring(java.lang.String source,
                                         int startIndex,
                                         int endIndex)
Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.

Parameters:
source - String.
startIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.
Returns:
the specified substring.

ToLowerCase

public static java.lang.String ToLowerCase(java.lang.String source)
Converts the supplied String instance to lower case.

Parameters:
source - String.
Returns:
the supplied String instance converted to lower case.
Throws:
XPIllegalArgumentException - when source string is null.

ToLowerCase

public static java.lang.String ToLowerCase(java.lang.String source,
                                           XPLocale locale)
Converts the supplied String instance to lower case with regard to the supplied locale.

Parameters:
source - String.
locale - XPLocale that's supplied.
Returns:
the supplied String instance converted to lower case with regard to the supplied locale.
Throws:
XPIllegalArgumentException - when source string is null.

ToUpperCase

public static java.lang.String ToUpperCase(java.lang.String source)
Converts the supplied String instance to upper case.

Parameters:
source - String.
Returns:
the supplied String instance converted to upper case.
Throws:
XPIllegalArgumentException - when source string is null.

ToUpperCase

public static java.lang.String ToUpperCase(java.lang.String source,
                                           XPLocale locale)
Converts the supplied String instance to upper case with regard to the supplied locale.

Parameters:
source - String.
locale - supplied locale.
Returns:
the supplied String instance converted to upper case with regard to the supplied locale.
Throws:
XPIllegalArgumentException - when source string is null.

Trim

public static java.lang.String Trim(java.lang.String str)
Returns a new string instance based on the source, trimmed of leading and trailing whitespace. Wraps String instance.trim().

Parameters:
str - non-null source string
Returns:
a new String instance with leading and trailing whitespace removed.
Throws:
XPIllegalArgumentException - if str is null


Copyright © 2002, 2003, 2004 Plumtree Software Inc. All Rights Reserved.