Package nl.siegmann.epublib.util
Class StringUtil
- java.lang.Object
-
- nl.siegmann.epublib.util.StringUtil
-
public class StringUtil extends java.lang.ObjectVarious String utility functions. Most of the functions herein are re-implementations of the ones in apache commons StringUtils. The reason for re-implementing this is that the functions are fairly simple and using my own implementation saves the inclusion of a 200Kb jar file.
-
-
Constructor Summary
Constructors Constructor Description StringUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringcollapsePathDots(java.lang.String path)Changes a path containing '..', '.' and empty dirs into a path that doesn't.static java.lang.StringdefaultIfNull(java.lang.String text)If the given text is null return "", the original text otherwise.static java.lang.StringdefaultIfNull(java.lang.String text, java.lang.String defaultValue)If the given text is null return "", the given defaultValue otherwise.static booleanendsWithIgnoreCase(java.lang.String source, java.lang.String suffix)Whether the given source string ends with the given suffix, ignoring case.static booleanequals(java.lang.String text1, java.lang.String text2)Null-safe string comparatorstatic inthashCode(java.lang.String... values)static booleanisBlank(java.lang.String text)Whether the String is null, zero-length and does contain only whitespace.static booleanisEmpty(java.lang.String text)Whether the given string is null or zero-length.static booleanisNotBlank(java.lang.String text)Whether the String is not null, not zero-length and does not contain of only whitespace.static java.lang.StringsubstringAfter(java.lang.String text, char c)Gives the substring of the given text after the given separator.static java.lang.StringsubstringAfterLast(java.lang.String text, char separator)Gives the substring of the given text after the last occurrence of the given separator.static java.lang.StringsubstringBefore(java.lang.String text, char separator)Gives the substring of the given text before the given separator.static java.lang.StringsubstringBeforeLast(java.lang.String text, char separator)Gives the substring of the given text before the last occurrence of the given separator.static java.lang.StringtoString(java.lang.Object... keyValues)Pretty toString printer.
-
-
-
Method Detail
-
collapsePathDots
public static java.lang.String collapsePathDots(java.lang.String path)
Changes a path containing '..', '.' and empty dirs into a path that doesn't. X/foo/../Y is changed into 'X/Y', etc. Does not handle invalid paths like "../".- Parameters:
path-- Returns:
- the normalized path
-
isNotBlank
public static boolean isNotBlank(java.lang.String text)
Whether the String is not null, not zero-length and does not contain of only whitespace.- Parameters:
text-- Returns:
- Whether the String is not null, not zero-length and does not contain of
-
isBlank
public static boolean isBlank(java.lang.String text)
Whether the String is null, zero-length and does contain only whitespace.- Returns:
- Whether the String is null, zero-length and does contain only whitespace.
-
isEmpty
public static boolean isEmpty(java.lang.String text)
Whether the given string is null or zero-length.- Parameters:
text- the input for this method- Returns:
- Whether the given string is null or zero-length.
-
endsWithIgnoreCase
public static boolean endsWithIgnoreCase(java.lang.String source, java.lang.String suffix)Whether the given source string ends with the given suffix, ignoring case.- Parameters:
source-suffix-- Returns:
- Whether the given source string ends with the given suffix, ignoring case.
-
defaultIfNull
public static java.lang.String defaultIfNull(java.lang.String text)
If the given text is null return "", the original text otherwise.- Parameters:
text-- Returns:
- If the given text is null "", the original text otherwise.
-
defaultIfNull
public static java.lang.String defaultIfNull(java.lang.String text, java.lang.String defaultValue)If the given text is null return "", the given defaultValue otherwise.- Parameters:
text-defaultValue-- Returns:
- If the given text is null "", the given defaultValue otherwise.
-
equals
public static boolean equals(java.lang.String text1, java.lang.String text2)Null-safe string comparator- Parameters:
text1-text2-- Returns:
- whether the two strings are equal
-
toString
public static java.lang.String toString(java.lang.Object... keyValues)
Pretty toString printer.- Parameters:
keyValues-- Returns:
- a string representation of the input values
-
hashCode
public static int hashCode(java.lang.String... values)
-
substringBefore
public static java.lang.String substringBefore(java.lang.String text, char separator)Gives the substring of the given text before the given separator. If the text does not contain the given separator then the given text is returned.- Parameters:
text-separator-- Returns:
- the substring of the given text before the given separator.
-
substringBeforeLast
public static java.lang.String substringBeforeLast(java.lang.String text, char separator)Gives the substring of the given text before the last occurrence of the given separator. If the text does not contain the given separator then the given text is returned.- Parameters:
text-separator-- Returns:
- the substring of the given text before the last occurrence of the given separator.
-
substringAfterLast
public static java.lang.String substringAfterLast(java.lang.String text, char separator)Gives the substring of the given text after the last occurrence of the given separator. If the text does not contain the given separator then "" is returned.- Parameters:
text-separator-- Returns:
- the substring of the given text after the last occurrence of the given separator.
-
substringAfter
public static java.lang.String substringAfter(java.lang.String text, char c)Gives the substring of the given text after the given separator. If the text does not contain the given separator then "" is returned.- Parameters:
text- the input textc- the separator char- Returns:
- the substring of the given text after the given separator.
-
-