org.pentaho.reporting.libraries.base.util
Class StringUtils

java.lang.Object
  extended by org.pentaho.reporting.libraries.base.util.StringUtils

public class StringUtils
extends java.lang.Object

String utilities.

Author:
Thomas Morgner.

Method Summary
static boolean endsWithIgnoreCase(java.lang.String base, java.lang.String end)
          Helper functions to query a strings end portion.
static boolean equals(java.lang.String s1, java.lang.String s2)
          Determines if the two Strings are equals (taking nulls into account).
static boolean equalsIgnoreCase(java.lang.String s1, java.lang.String s2)
          Determines if the two Strings are equals ingnoring case sensitivity (taking nulls into account).
static java.lang.String getLineSeparator()
          Queries the system properties for the line separator.
static boolean isEmpty(java.lang.String source)
          Determines if the string is empty or null.
static boolean isEmpty(java.lang.String source, boolean trim)
          Determines if the string is empty or null.
static java.lang.String makeUniqueName(java.lang.String[] knownNames, java.lang.String pattern)
          Computes a unique name using the given known-names array as filter.
static java.lang.String[] merge(java.lang.String[] first, java.lang.String[] second)
          Merges the contents of the first and second array returning a array that contains only unique strings.
static java.lang.String[] split(java.lang.String string)
          Splits a given string on any whitespace character.
static java.lang.String[] split(java.lang.String string, java.lang.String separator)
          Splits a given string at the given separator string.
static java.lang.String[] split(java.lang.String string, java.lang.String separator, java.lang.String quate)
          Splits a given string at the given separator string.
static java.lang.String[] splitCSV(java.lang.String string, java.lang.String separator)
          Splits a given string at the given separator string.
static java.lang.String[] splitCSV(java.lang.String string, java.lang.String separator, java.lang.String quate)
          Splits a given string at the given separator string.
static boolean startsWithIgnoreCase(java.lang.String base, java.lang.String start)
          Helper functions to query a strings start portion.
static boolean toBoolean(java.lang.String source)
          Returns true if the source string evaulates (case insensative and trimmed) to true, yes, or on.
static boolean toBoolean(java.lang.String source, boolean nullDefault)
          Returns true if the source string evaulates (case insensative and trimmed) to true, yes, or on.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

startsWithIgnoreCase

public static boolean startsWithIgnoreCase(java.lang.String base,
                                           java.lang.String start)
Helper functions to query a strings start portion. The comparison is case insensitive.

Parameters:
base - the base string.
start - the starting text.
Returns:
true, if the string starts with the given starting text.

endsWithIgnoreCase

public static boolean endsWithIgnoreCase(java.lang.String base,
                                         java.lang.String end)
Helper functions to query a strings end portion. The comparison is case insensitive.

Parameters:
base - the base string.
end - the ending text.
Returns:
true, if the string ends with the given ending text.

getLineSeparator

public static java.lang.String getLineSeparator()
Queries the system properties for the line separator. If access to the System properties is forbidden, the UNIX default is returned.

Returns:
the line separator.

split

public static java.lang.String[] split(java.lang.String string)
Splits a given string on any whitespace character. Duplicate separators will be merged into a single separator occurance. This implementation provides the same functionality as the REGEXP-based String.split(..) operation but does not use Regular expressions and therefore it is faster and less memory consuming.

Parameters:
string - the text to be split.
Returns:
the text elements as array.

split

public static java.lang.String[] split(java.lang.String string,
                                       java.lang.String separator)
Splits a given string at the given separator string. Duplicate separators will be merged into a single separator occurance.

Parameters:
string - the text to be split.
separator - the separator chacters used for the split.
Returns:
the splitted array.

split

public static java.lang.String[] split(java.lang.String string,
                                       java.lang.String separator,
                                       java.lang.String quate)
Splits a given string at the given separator string. Duplicate separators will be merged into a single separator occurance.

Parameters:
string - the text to be split.
separator - the separator chacters used for the split.
quate - the quoting character.
Returns:
the splitted array.

splitCSV

public static java.lang.String[] splitCSV(java.lang.String string,
                                          java.lang.String separator)
Splits a given string at the given separator string. Duplicate separators will result in empty strings thus preserving the number of fields specified in the original string.

Parameters:
string - the text to be split.
separator - the separator chacters used for the split.
Returns:
the splitted array.

splitCSV

public static java.lang.String[] splitCSV(java.lang.String string,
                                          java.lang.String separator,
                                          java.lang.String quate)
Splits a given string at the given separator string. Duplicate separators will result in empty strings thus preserving the number of fields specified in the original string.

Parameters:
string - the text to be split.
separator - the separator chacters used for the split.
quate - the quoting character.
Returns:
the splitted array.

makeUniqueName

public static java.lang.String makeUniqueName(java.lang.String[] knownNames,
                                              java.lang.String pattern)
Computes a unique name using the given known-names array as filter. This method is not intended for large datasets.

Parameters:
knownNames - the list of known names.
pattern - the name pattern, which should have one integer slot to create derived names.
Returns:
the unique name or null, if no unqiue name could be created.

merge

public static java.lang.String[] merge(java.lang.String[] first,
                                       java.lang.String[] second)
Merges the contents of the first and second array returning a array that contains only unique strings. The order of the returned array is undefined.

Parameters:
first - the first array to be merged.
second - the second array to be merged.
Returns:
the merged araray.

toBoolean

public static boolean toBoolean(java.lang.String source)
Returns true if the source string evaulates (case insensative and trimmed) to true, yes, or on. It will return false otherwise (including null).

Parameters:
source - the string to check
Returns:
true if the source string evaulates to true or similar value, false otherwise.

toBoolean

public static boolean toBoolean(java.lang.String source,
                                boolean nullDefault)
Returns true if the source string evaulates (case insensative and trimmed) to true, yes, or on. It will return false otherwise. If the source string is null, it will return the value of the default.

Parameters:
source - the string to check
nullDefault - to value to return if the source string is null
Returns:
true if the source string evaulates to true or similar value, false otherwise.

isEmpty

public static boolean isEmpty(java.lang.String source)
Determines if the string is empty or null.

Parameters:
source - the string to check
Returns:
true if the source string is null or an emptry string, false otherwise.

isEmpty

public static boolean isEmpty(java.lang.String source,
                              boolean trim)
Determines if the string is empty or null. If the trim is true, the string will be trimmed before checking for an empty string.

Parameters:
source - the string to check
trim - indicates if the string should be trimmed before checking for an empty string.
Returns:
true if the source string is null or an emptry string, false otherwise.

equals

public static boolean equals(java.lang.String s1,
                             java.lang.String s2)
Determines if the two Strings are equals (taking nulls into account).

Parameters:
s1 - the first string to compare.
s2 - the second string to compare.
Returns:
true if both string are null or the contain the same value, falseotherwise

equalsIgnoreCase

public static boolean equalsIgnoreCase(java.lang.String s1,
                                       java.lang.String s2)
Determines if the two Strings are equals ingnoring case sensitivity (taking nulls into account).

Parameters:
s1 - the first string to compare.
s2 - the second string to compare.
Returns:
true if both string are null or the contain the same case-insensitive value, falseotherwise