public class StringUtils extends Object
Modifier and Type | Field and Description |
---|---|
private static HashMap<String,DecimalFormat> |
decimalFormats |
private static String |
DEFAULT_ARRAY_SEPARATOR |
private static String |
DEFAULT_ELIPSIS |
static String |
REGEX_SPACE_OR_TAB |
static String[][] |
STRING_URLENCODE_REPLACEMENTS |
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
appendExtension(String fileName,
String extension) |
static String |
appendOrReplaceExtension(String fileName,
String oldExtension,
String newExtension) |
static String |
beautify(String source) |
static String |
beautifyForHTML(String source) |
static String[] |
concat(String[] array1,
String[] array2) |
static boolean |
containsAny(String s,
String... options) |
static String |
defaultIfBlank(String s,
String defaultValue)
Works analogous to
StringUtils.defaultIfEmpty(String, String) , but using
StringUtils.isBlank(String) instead of
StringUtils.isEmpty(String) |
static boolean |
endsWithAny(String s,
String... options) |
static String |
ensureExtension(String fileName,
String extension) |
static boolean |
equals(Object o,
String s) |
static boolean |
equalsAny(Object o,
String... options) |
static boolean |
equalsAny(String s,
Object... options)
Checks whether the given String equals any of the given options when calling
Object.toString() on them |
static boolean |
equalsAny(String s,
String... options)
Checks whether the given String equals any of the given options.
|
static boolean |
equalsAnyIgnoreCase(String s,
String... options)
Checks whether the given String equals any of the given options, ignoring case
|
static String |
escapeClassNameForWeka(String label) |
static String |
escapeForWeka(String label) |
static String |
escapeString(String s) |
static String |
format(double number,
int fractionDigits)
Formats a double value with the given number of fractionDigits.
|
static String |
format(double number,
int fractionDigits,
boolean withZeros)
Formats a double value with the given number of fractionDigits.
|
static String |
format(double number,
int fractionDigits,
boolean withZeros,
int leadingDigits) |
static String |
format(int number,
int digits)
Formats a double value with the given number of digits, potentially including leading zeros.
|
static String |
formatAsPercent(double value,
double maxValue,
int fractionDigits) |
static String |
formatBooleanValue(int type,
boolean value)
formats a boolean value according to the given type returns the needed string representation of a boolean value
that can be printed to the report.
At the moment, only one transtormation is supported: type: 0: true -> yes, false->no (default) |
static String |
formatDouble(double value)
returns the correct format of a double needed for displaying it in the comparison table this means, that if the
value is smaller than 0, the string "-" is returned instead of the value
|
static String |
formatEndMaxLengthEllipsis(String s,
int maxLen) |
static String |
formatEndMaxLengthEllipsis(String s,
int maxLen,
String ellipsis) |
static String |
formatMaxLengthEllipsis(String s,
int maxLen) |
static String |
formatMaxLengthEllipsis(String s,
int maxLen,
String ellipsis) |
static String |
formatString(String value)
returns the correct format of the given String needed for displaying it in the comparison table this means, that
if the String is null or empty, "-" is returned instead of the String
|
static String |
getCommonPrefix(Collection<String> c) |
static String |
getCommonPrefix(String[] a) |
static String |
getCommonPrefix(String s1,
String s2)
Returns the common starting portion of the two Strings, or an empty String if there is no common part.
|
static String |
getCommonSuffix(Collection<String> c) |
static String |
getCommonSuffix(String[] a) |
static String |
getCommonSuffix(String s1,
String s2)
Returns the common starting portion of the two Strings, or an empty String if there is no common part.
|
private static DecimalFormat |
getDecimalFormat(int digits) |
static DecimalFormat |
getDecimalFormat(int fractionDigits,
boolean withZeros,
int leadingDigits)
Returns a
DecimalFormat with the given number of fractionDigits, with or without trailing zeros. |
static String[] |
getDifferences(String[] a) |
static DecimalFormat |
getIntegerFormat(int digits)
Returns a
DecimalFormat intended to formatting integers with the given number of digits, potentially with
leading zeros |
static String |
getLatexRGBString(int[] rgb)
creates an representation of a color that can be used in html or css takes an int - array of size 3 and
transforms it to a hex String of structure #rrggbb The array must have at least length 3 and must not contain
null values.
|
static int |
getLongestStringLength(Iterable<String> c) |
static int |
getLongestStringLength(String[] c) |
static String |
getRGBString(int[] rgb)
creates an representation of a color that can be used in html or css takes an int - array of size 3 and
transforms it to a hex String of structure #rrggbb The array must have at least length 3 and must not contain
null values.
|
static String |
getSpaces(int num) |
static String |
getStackTrace(Exception exception)
Gets the stack trace of the exception, as it would be printed through
Throwable.printStackTrace() , as a
String |
static int |
indexOfStartsWithAny(String s,
String... options)
Checks whether the given String starts with any of the given options.
|
static int |
indexOfStartsWithAny(String s,
String suffix,
String... options)
Checks whether the given String starts with any of the given options concatenated by the suffix.
|
static String |
interleave(double[] d,
String string) |
static String |
interleave(String[] s,
String string) |
static int |
levenshteinDistance(String s,
String t)
Calculate the Levenshtein Distance between the two given Strings (String1 and String2).
|
static void |
main(String[] args) |
static String |
makeStringEndWithCorrectFileSeparator(String path)
Makes sure that the given String ends with the OS-correct File.separator ('/' on Unix, '\\' on Windows)
|
static boolean |
matchesAny(String[] regExps,
String s) |
static int |
notEmpty(Object o) |
static String |
pad(double value,
int len) |
static String |
pad(String s,
int len) |
static double[] |
parseDoubles(String s)
parses double values from a comma-separated string
|
private static double[] |
parseDoubles(String[] parts)
parses double values from a string array, after trimming of the strings is performed
|
static double[] |
parseDoublesAndRanges(String s) |
static String |
printMap(Map m) |
static String |
readableBytes(long byteSize)
Formats byte size in nice format
|
static String |
repeatString(int num,
String s) |
static String |
replaceURLEncode(String s) |
static boolean |
startsWithAny(String s,
String... options)
Checks whether the given String starts with any of the given options.
|
static boolean |
startsWithAnyIgnoreCase(String s,
String... options)
Checks whether the given String starts with any of the given options, ignoring the case
|
static String |
stripQuotes(String s) |
static String |
stripSuffix(String sMitSuffix)
Returns the string until (excluding) the first dot (.)
|
static String |
substringMore(String s,
int maxlen) |
static String |
toString(Collection<?> collection) |
static String |
toString(Collection<?> collection,
String start,
String end) |
static String |
toString(Collection<?> collection,
String start,
String end,
String separator) |
static String |
toString(double[][] data) |
static String |
toString(double[][][] data) |
static String |
toString(double[] a,
int maxElements)
Returns a string representation of the contents of the specified array in the same fashion as
Arrays.toString(double[]) , but limiting the output to the given maxIndices parameter. |
static String |
toString(double[] array,
String start,
String end) |
static String |
toString(int[] array,
String start,
String end) |
static String |
toString(Object[] array,
int maxElements) |
static String |
toString(Object[] array,
String start,
String end) |
static String |
toString(Object[] array,
String start,
String end,
String separator) |
static String |
toString(Object[] array,
String start,
String end,
String separator,
int maxElements) |
static String |
toString(Object[] array,
String start,
String end,
String separator,
String encasing) |
static String |
toString(Point2D[] a) |
static String |
toString(Point2D[][] a) |
static String |
toStringWithPrecision(double[] a,
int digits)
Prints a double[] with the given number of decimal digits.
|
static String[] |
trim(String[] split) |
static String |
URLencode(String url)
This extra method had to be written because URLEncoder.encode 1) performs an encoding of a slash (/), 2) encodes
a space as a +, but should encode it as %20.
|
static String |
wrap(String string,
int lineWidth) |
static String |
wrap(String string,
int lineWidth,
int indent) |
static String |
wrap(String string,
int lineWidth,
int indent,
boolean wordBoundaries) |
static String |
wrap(String string,
int lineWidth,
String indentString) |
static String |
wrap(String string,
int lineWidth,
String indentString,
boolean wordBoundaries) |
public static final String REGEX_SPACE_OR_TAB
private static final String DEFAULT_ARRAY_SEPARATOR
private static final String DEFAULT_ELIPSIS
private static HashMap<String,DecimalFormat> decimalFormats
public static final String[][] STRING_URLENCODE_REPLACEMENTS
public static DecimalFormat getDecimalFormat(int fractionDigits, boolean withZeros, int leadingDigits)
DecimalFormat
with the given number of fractionDigits, with or without trailing zeros.public static DecimalFormat getIntegerFormat(int digits)
DecimalFormat
intended to formatting integers with the given number of digits, potentially with
leading zerospublic static String format(double number, int fractionDigits)
format(double, int, boolean)
with
no trailing zeros.public static String formatAsPercent(double value, double maxValue, int fractionDigits)
public static String format(double number, int fractionDigits, boolean withZeros)
withZeros
- indicates whether there should be trailing zeros to fill up all fraction digitspublic static String format(double number, int fractionDigits, boolean withZeros, int leadingDigits)
public static String format(int number, int digits)
public static String stripSuffix(String sMitSuffix)
public static String makeStringEndWithCorrectFileSeparator(String path)
public static String readableBytes(long byteSize)
byteSize
- the size in bytes to formatpublic static String toString(Collection<?> collection)
public static String toString(Collection<?> collection, String start, String end)
public static String toString(Collection<?> collection, String start, String end, String separator)
public static String toString(Object[] array, String start, String end, String separator, String encasing)
public static String toString(Object[] array, String start, String end, String separator, int maxElements)
public static boolean equalsAny(String s, String... options)
public static boolean equalsAny(String s, Object... options)
Object.toString()
on thempublic static boolean equalsAnyIgnoreCase(String s, String... options)
public static boolean startsWithAny(String s, String... options)
public static int indexOfStartsWithAny(String s, String... options)
public static int indexOfStartsWithAny(String s, String suffix, String... options)
public static boolean startsWithAnyIgnoreCase(String s, String... options)
public static String toStringWithPrecision(double[] a, int digits)
public static String toString(double[] a, int maxElements)
Arrays.toString(double[])
, but limiting the output to the given maxIndices parameter.public static String toString(double[][] data)
public static String toString(double[][][] data)
private static DecimalFormat getDecimalFormat(int digits)
public static String getSpaces(int num)
public static int getLongestStringLength(String[] c)
public static String formatMaxLengthEllipsis(String s, int maxLen, String ellipsis)
public static String formatEndMaxLengthEllipsis(String s, int maxLen, String ellipsis)
public static String getCommonPrefix(String s1, String s2)
public static String getCommonPrefix(Collection<String> c)
public static String getCommonSuffix(String s1, String s2)
public static String getCommonSuffix(Collection<String> c)
public static int levenshteinDistance(String s, String t)
s
- String1t
- String2public static void main(String[] args)
public static String formatBooleanValue(int type, boolean value)
type
- the type of conversion/strings wished (see above)value
- the boolean valuepublic static String getRGBString(int[] rgb)
rgb
- an array specifying the red, green and blue parts of the colorpublic static String getLatexRGBString(int[] rgb)
rgb
- an array specifying the red, green and blue parts of the colorpublic static String formatString(String value)
value
- the string that shall be formattedpublic static String formatDouble(double value)
value
- a double value for which a String representation is neededpublic static String URLencode(String url)
url
- a non-encoded URLpublic static String appendOrReplaceExtension(String fileName, String oldExtension, String newExtension)
public static String pad(double value, int len)
public static String wrap(String string, int lineWidth)
string
- The String
to wraplineWidth
- the width string
is wrapped tostring
wrapped to the width of lineWidth
public static String wrap(String string, int lineWidth, int indent)
string
- The String
to wraplineWidth
- the width string
is wrapped toindent
- prefix each newly added line with indent
spacesstring
wrapped to the width of lineWidth
public static String wrap(String string, int lineWidth, int indent, boolean wordBoundaries)
string
- The String
to wraplineWidth
- the width string
is wrapped toindent
- prefix each newly added line with indent
spaceswordBoundaries
- only wrap at word boudaries (aka Spaces).string
wrapped to the width of lineWidth
public static String wrap(String string, int lineWidth, String indentString)
string
- The String
to wraplineWidth
- the width string
is wrapped toindentString
- each newly added line will be prefixed with this stringstring
wrapped to the width of lineWidth
public static String wrap(String string, int lineWidth, String indentString, boolean wordBoundaries)
string
- The String
to wraplineWidth
- the width string
is wrapped toindentString
- each newly added line will be prefixed with this stringwordBoundaries
- only wrap at word boudaries (aka Spaces).string
wrapped to the width of lineWidth
public static double[] parseDoubles(String s)
public static double[] parseDoublesAndRanges(String s)
private static double[] parseDoubles(String[] parts)
public static int notEmpty(Object o)
public static String getStackTrace(Exception exception)
Throwable.printStackTrace()
, as a
Stringpublic static String defaultIfBlank(String s, String defaultValue)
StringUtils.defaultIfEmpty(String, String)
, but using
StringUtils.isBlank(String)
instead of
StringUtils.isEmpty(String)