public class

StringUtils

extends Object
java.lang.Object
   ↳ com.microstrategy.utils.StringUtils

Class Overview

This class provides static utility methods for doing string processing.

Summary

Fields
public static final String NEWLINE
Public Constructors
StringUtils()
Public Methods
static int compareFullServerVersion(String version1, String version2)
Compares IServer versions.
static int compareFullServerVersionInOrder(String version1, String version2)
Compares IServer versions.
static int compareServerVersion(String version1, String version2)
Compares IServer versions.
static String escape(String str, String toEscape, char escape)

Applies escape processing to the string parameter 'str'.

static void escape(String str, String toEscape, char escape, StringBuilder escaped)

Applies escape processing to a string, and appends the results to a StringBuilder.

static String getMessageIDFromSessionID(String sessionID)
Strips and returns the messageID from the session ID passed in.
static String getResultCodeFromSessionID(String sessionID)
Strips and returns the result code from the session ID passed in.
static String getServerNameFromSessionID(String sessionID)
Strips and returns the Intelligence Server name from the session ID passed in.
static String getSessionInfoFromSessionID(String sessionID)
Strips and returns the session info without message id and result code from the session ID passed in.
static boolean hasAsciiChars(String s)

Test if a string contains any non-ascii characters

static String intArrayToString(int[] intArray)
Returns a string representation of an integer array.
static boolean isEmpty(Object value)
static boolean isEmpty(String value)

A String is considered empty if its null, or when trimmed has zero length.

static boolean isEqual(String str1, String str2)
Checks whether two strings are equal.
static boolean isEqual(Object obj1, Object obj2)
static boolean isEqualIgnoreCase(String str1, String str2)
static boolean isEqualWithEmpty(String str1, String str2)
Checks whether two strings are equal.
static boolean isNotEmpty(String value)
Checks whether the specified string is null or an empty string after trimming.
static boolean isNotEqual(String str1, String str2)
Checks whether two string are not equal
static String mergeTokens(StringTokenizer strTok, String separator)
Concatenate all tokens in the StringTokenizer and delimit them by the specified separator.
static String parseFirstName(String fullName)
static String parseLastName(String fullName)
static CharSequence replace(String str, char[] chars, String[] replaces)
Replaces the characters specified by the char[] with the String specified in the String[].
static void replace(StringBuilder sb, char[] chars, String[] replaces)
Replaces the characters specified by the char[] with the String specified in the String[].
static String replaceCharsWithStrings(String str, char[] chars, String[] replaces)
static String replaceString(String str, String pattern, String replace)
Replaces every ocurrence of XX with YY in the passed string.
static String[] split(String str, String delimiter)
Split the String into a string array, according to the delimiter
static ArrayList stringToIntArrayList(String str)
Splits the specified string into tokens based on the delimiter comma and then stores them into an array list.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

public static final String NEWLINE

Public Constructors

public StringUtils ()

Public Methods

public static int compareFullServerVersion (String version1, String version2)

Compares IServer versions. Takes into account intermediate builds. Version structure: major.minor.release1.release2. Precendence is as follows: major, minor, release 2, release 1. Note that release 2 takes precedence over release 1. Returns 1 if version1 is higher than version2, -1 if version2 is higher, and 0 if they are equals.

Parameters
version1 MicroStrategy Intelligence Server version string.
version2 MicroStrategy Intelligence Server version string.
Returns
  • whether two server versions have the same release number

public static int compareFullServerVersionInOrder (String version1, String version2)

Compares IServer versions. Takes into account intermediate builds. Version structure: major.minor.release1.release2. Precendence is as follows: major, minor, release 1, release 2. Returns 1 if version1 is higher than version2, -1 if version2 is higher, and 0 if they are equals.

Parameters
version1 MicroStrategy Intelligence Server version string.
version2 MicroStrategy Intelligence Server version string.
Returns
  • whether two server versions have the same release number

public static int compareServerVersion (String version1, String version2)

Compares IServer versions. This method assumes that you are comparing 2 release versions and not intermediate builds. Therefore it only bases its comparison on the major release, minor release and revision 2 numbers. It does not care about revision 1. returns 1 if version1 > version 2 returns -1 if version2 > version 1 returns 0 if they are identical

Parameters
version1 MicroStrategy Intelligence Server version string.
version2 MicroStrategy Intelligence Server version string.
Returns
  • whether two server versions have the same release number

public static String escape (String str, String toEscape, char escape)

Applies escape processing to the string parameter 'str'. If any characters in 'str' contains any of the escapable characters defined in parameter 'toEscape', they are prefixed by the escape character specified. By default, the escape character does not escape itself - if this is desired, please ensure it's in the 'toEscape' string.

Parameters
str the original string
toEscape characters to escape
escape the escape character
Returns
  • the escaped string

public static void escape (String str, String toEscape, char escape, StringBuilder escaped)

Applies escape processing to a string, and appends the results to a StringBuilder.

Parameters
escaped Escaped string of 'str'

public static String getMessageIDFromSessionID (String sessionID)

Strips and returns the messageID from the session ID passed in.

Parameters
sessionID an Intelligence Server session ID.
Returns
  • the message ID.

public static String getResultCodeFromSessionID (String sessionID)

Strips and returns the result code from the session ID passed in.

Parameters
sessionID an Intelligence Server session ID.
Returns
  • the result code.

public static String getServerNameFromSessionID (String sessionID)

Strips and returns the Intelligence Server name from the session ID passed in.

Parameters
sessionID an Intelligence Server session ID.
Returns
  • the Intelligence Server name.
Throws
IllegalArgumentException thrown if the session ID is invalid.

public static String getSessionInfoFromSessionID (String sessionID)

Strips and returns the session info without message id and result code from the session ID passed in.

Parameters
sessionID an Intelligence Server session ID.
Returns
  • the session info without message id and result code.

public static boolean hasAsciiChars (String s)

Test if a string contains any non-ascii characters

Parameters
s A non-empty string
Returns
  • whether it contains non-ascii characters

public static String intArrayToString (int[] intArray)

Returns a string representation of an integer array. All integer array elements are concatenated into a string and are delimited by a comma.

Parameters
intArray an integer array.
Returns
  • the string representation of an integer array.

public static boolean isEmpty (Object value)

Returns
  • whether value object is null, or if it's a string then resolve as isEmpty(String)

public static boolean isEmpty (String value)

A String is considered empty if its null, or when trimmed has zero length.

Parameters
value String to test
Returns
  • whether String is empty

public static boolean isEqual (String str1, String str2)

Checks whether two strings are equal. Note that a null string and one with only white space are considered NOT the same.

Parameters
str1 the first string to check equality
str2 the second string to check equality
Returns
  • true if the two strings are the same (null and white space strings are considered different).

public static boolean isEqual (Object obj1, Object obj2)

public static boolean isEqualIgnoreCase (String str1, String str2)

public static boolean isEqualWithEmpty (String str1, String str2)

Checks whether two strings are equal. Also checks for isEmpty(String) equivalence, i.e. a null string and one with only white space are considered also equal.

Parameters
str1 the first string to check equality
str2 the second string to check equality
Returns
  • true if the two strings are the same (null and white space strings are considered the same).

public static boolean isNotEmpty (String value)

Checks whether the specified string is null or an empty string after trimming.

Parameters
value the string to check.
Returns
  • true if the specified string is not null and not empty after trimming white space.

public static boolean isNotEqual (String str1, String str2)

Checks whether two string are not equal

Parameters
str1 the first string to check equality
str2 the second string to check equality
Returns
  • true if the two strings are not equal.

public static String mergeTokens (StringTokenizer strTok, String separator)

Concatenate all tokens in the StringTokenizer and delimit them by the specified separator.

Parameters
strTok a StringTokenizer containing string tokens
separator the delimiter to separate strings
Returns
  • a string containing all the tokens from the StringTokenizer but delimited by the specified separator.

public static String parseFirstName (String fullName)

public static String parseLastName (String fullName)

public static CharSequence replace (String str, char[] chars, String[] replaces)

Replaces the characters specified by the char[] with the String specified in the String[].

Parameters
str - Input String.
chars - Array of Characters that need to be replaced.
replaces - Array of Strings that are replacements.
Returns
  • the original String or a StringBuilder if we replaced any characters.

public static void replace (StringBuilder sb, char[] chars, String[] replaces)

Replaces the characters specified by the char[] with the String specified in the String[].

Parameters
sb - Input StringBuilder.
chars - Array of Characters that need to be replaced.
replaces - Array of Strings that are replacements.

public static String replaceCharsWithStrings (String str, char[] chars, String[] replaces)

public static String replaceString (String str, String pattern, String replace)

Replaces every ocurrence of XX with YY in the passed string. The various replace functions in String are recommended over this legacy function (which preceded the String functions). This method will be deprecated at some point.

Parameters
str the string on which to perform the replacement
pattern the substring to replace(XX) - note that this is NOT a regular expression
replace the replacement substring(YY)
Returns
  • the modified string

public static String[] split (String str, String delimiter)

Split the String into a string array, according to the delimiter

Parameters
str the string on which to perform the spliting.
delimiter the delimiter string.
Returns
  • an array of string.

public static ArrayList stringToIntArrayList (String str)

Splits the specified string into tokens based on the delimiter comma and then stores them into an array list.

Parameters
str a string delimited by comma.
Returns
  • an array list over the string tokens delimited by comma.