Class StringUtils
- java.lang.Object
-
- org.pentaho.reporting.libraries.base.util.StringUtils
-
public final class StringUtils extends Object
String utilities.- Author:
- Thomas Morgner.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanendsWithIgnoreCase(String base, String end)Helper functions to query a strings end portion.static booleanequals(String s1, String s2)Determines if the two Strings are equals (taking nulls into account).static booleanequalsIgnoreCase(String s1, String s2)Determines if the two Strings are equals ingnoring case sensitivity (taking nulls into account).static StringgetLineSeparator()Queries the system properties for the line separator.static booleanisEmpty(String source)Determines if the string is empty ornull.static booleanisEmpty(String source, boolean trim)Determines if the string is empty ornull.static booleanisSpace(char c)Determines whether or not a character is considered a space.static StringmakeUniqueName(String[] knownNames, String pattern)Computes a unique name using the given known-names array as filter.static String[]merge(String[] first, String[] second)Merges the contents of the first and second array returning a array that contains only unique strings.static booleanonlySpaces(String str)Checks whether or not a String consists only of spaces.static String[]split(String string)Splits a given string on any whitespace character.static String[]split(String string, String separator)Splits a given string at the given separator string.static String[]split(String string, String separator, String quate)Splits a given string at the given separator string.static String[]splitCSV(String string, String separator)Splits a given string at the given separator string.static String[]splitCSV(String string, String separator, String quate)Splits a given string at the given separator string.static booleanstartsWithIgnoreCase(String base, String start)Helper functions to query a strings start portion.static booleantoBoolean(String source)Returnstrueif the source string evaulates (case insensative and trimmed) totrue,yes, oron.static booleantoBoolean(String source, boolean nullDefault)Returnstrueif the source string evaulates (case insensative and trimmed) totrue,yes, oron.static Stringtrim(String str)Trims a string: removes the leading and trailing spaces of a String.
-
-
-
Method Detail
-
startsWithIgnoreCase
public static boolean startsWithIgnoreCase(String base, 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(String base, 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 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 String[] split(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 String[] split(String string, 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 String[] split(String string, String separator, 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 String[] splitCSV(String string, 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 String[] splitCSV(String string, String separator, 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 String makeUniqueName(String[] knownNames, 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 String[] merge(String[] first, 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(String source)
Returnstrueif the source string evaulates (case insensative and trimmed) totrue,yes, oron. It will returnfalseotherwise (includingnull).- Parameters:
source- the string to check- Returns:
trueif the source string evaulates totrueor similar value,falseotherwise.
-
toBoolean
public static boolean toBoolean(String source, boolean nullDefault)
Returnstrueif the source string evaulates (case insensative and trimmed) totrue,yes, oron. It will returnfalse otherwise. If the source string isnull, it will return the value of the default.- Parameters:
source- the string to checknullDefault- to value to return if the source string isnull- Returns:
trueif the source string evaulates totrueor similar value,falseotherwise.
-
isEmpty
public static boolean isEmpty(String source)
Determines if the string is empty ornull.- Parameters:
source- the string to check- Returns:
trueif the source string isnullor an emptry string,falseotherwise.
-
isEmpty
public static boolean isEmpty(String source, boolean trim)
Determines if the string is empty ornull. If the trim istrue, the string will be trimmed before checking for an empty string.- Parameters:
source- the string to checktrim- indicates if the string should be trimmed before checking for an empty string.- Returns:
trueif the source string isnullor an emptry string,falseotherwise.
-
equals
public static boolean equals(String s1, 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:
trueif both string are null or the contain the same value,falseotherwise
-
equalsIgnoreCase
public static boolean equalsIgnoreCase(String s1, 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:
trueif both string are null or the contain the same case-insensitive value,falseotherwise
-
onlySpaces
public static final boolean onlySpaces(String str)
Checks whether or not a String consists only of spaces.- Parameters:
str- The string to check- Returns:
- true if the string has nothing but spaces.
-
isSpace
public static final boolean isSpace(char c)
Determines whether or not a character is considered a space. A character is considered a space in Kettle if it is a space, a tab, a newline or a cariage return.- Parameters:
c- The character to verify if it is a space.- Returns:
- true if the character is a space. false otherwise.
-
-