public class StringUtils extends Object
Modifier and Type | Field and Description |
---|---|
static char[] |
INVALID_FILESYSTEM_CHARACTERS |
static char[] |
INVALID_JSONIFY_CHARACTERS |
Modifier and Type | Method and Description |
---|---|
static int |
compareVersions(String version1,
String version2)
Compares two version strings.
|
static String |
convertGlobToRegex(String pattern)
Converts a standard POSIX Shell globbing pattern into a regular expression
pattern.
|
static String |
createIconTextHTMLTable(String text,
URL iconURL)
Creates an HTML table with an icon and text.
|
static String |
createIconTextHTMLTableElement(String text,
URL iconURL)
Creates an HTML table with an icon and text.
|
static String |
createRightIconTextHTMLTable(String text,
URL iconURL)
Same as createIconTextHTMLTable but the icon is on the right side
|
static String |
createRightIconTextHTMLTableElement(String text,
URL iconURL)
Same as createIconTextHTMLTableElement but the icon is on the right side
|
static String |
formatDateTime(LocalDateTime dateTime)
A nice human-readable format
|
static String |
formatDuration(long durationMilliseconds)
Formats a duration in milliseconds to something readable
|
static String |
formatPluralS(int count,
String labelSingular) |
static String |
formatSize(long size) |
static String |
generateRandomString(String characters,
int length)
Generates a random string
|
static String |
getCleanedMenuPath(String menuPath)
Cleans a menu path string
|
static boolean |
isFilesystemCompatible(String string)
Returns if the string does not contain invalid characters.
|
static boolean |
isNullOrEmpty(Object string)
Returns true if the string is null or empty
|
static boolean |
isValidDouble(String text) |
static boolean |
isValidInteger(String text) |
static boolean |
isValidVersion(String version) |
static String |
jsonify(String input)
Removes all spaces, and filesystem-unsafe characters from the string and replaces them with dashes
Duplicate dashes are removed
|
static String |
limitWithEllipsis(String str,
int maxWidth,
FontMetrics metrics)
If the string is longer than maxWidth, limit it to fit within maxWidth
with an ellipsis (...).
|
static String |
limitWithoutEllipsis(String str,
int maxWidth,
FontMetrics metrics)
If the string is longer than maxWidth, limit it to fit within maxWidth
with an ellipsis (...).
|
static String |
makeFilesystemCompatible(String input)
Replaces all characters invalid for filesystems with spaces
Assumes that the string is a filename, so path operators are not allowed.
|
static String |
makeUniqueString(String input,
String spaceCharacter,
Collection<String> existing)
Makes an unique string by adding a counting variable to its end if it already exists
|
static String |
makeUniqueString(String input,
String spaceCharacter,
Predicate<String> existing)
Makes an unique string by adding a counting variable to its end if it already exists
|
static String |
nullTerminate(String input)
Applies a \0 termination to a string.
|
static String |
nullToEmpty(Object s)
Returns an empty string if s is null otherwise returns s
|
static double |
objectToDouble(Object o) |
static String |
orElse(Object string,
String ifNullOrEmpty)
Returns the string if its not null or empty or the alternative
|
static double |
parseDouble(String str) |
static float |
parseFloat(String str) |
static int |
parseInt(String str) |
static String |
removeDuplicateDelimiters(String string,
String delimiter) |
static String |
removeHTMLRoot(String html)
Removes the HTML root from HTML
|
static String |
safeJsonify(String input)
Removes all spaces, and filesystem-unsafe characters from the string and replaces them with dashes
Duplicate dashes are removed
|
static String[] |
splitNonRegex(String s,
String delimiter) |
static double |
tryParseDouble(String str,
double defaultValue) |
static Object |
tryParseDoubleOrReturnString(String str)
Attempts to parse a string as double.
|
static String |
wordWrappedHTML(String text,
int wrapColumn)
Create word wrapping in HTML.
|
static String |
wordWrappedHTMLElement(String text,
int wrapColumn)
Create word wrapping in HTML.
|
static String |
wrapHtml(String text) |
public static final char[] INVALID_FILESYSTEM_CHARACTERS
public static final char[] INVALID_JSONIFY_CHARACTERS
public static boolean isValidDouble(String text)
public static boolean isValidInteger(String text)
public static String limitWithEllipsis(String str, int maxWidth, FontMetrics metrics)
public static String limitWithoutEllipsis(String str, int maxWidth, FontMetrics metrics)
public static String removeDuplicateDelimiters(String string, String delimiter)
public static String formatDuration(long durationMilliseconds)
durationMilliseconds
- the durationpublic static String formatDateTime(LocalDateTime dateTime)
dateTime
- the time pointpublic static String createIconTextHTMLTable(String text, URL iconURL)
text
- the text. Is automatically escapediconURL
- the iconpublic static String createIconTextHTMLTableElement(String text, URL iconURL)
text
- the text. Is automatically escapediconURL
- the iconpublic static String createRightIconTextHTMLTable(String text, URL iconURL)
text
- the text. Is automatically escapediconURL
- the iconpublic static String createRightIconTextHTMLTableElement(String text, URL iconURL)
text
- the text. Is automatically escapediconURL
- the iconpublic static String nullTerminate(String input)
input
- the input stringpublic static String removeHTMLRoot(String html)
html
- the HTMLpublic static String wordWrappedHTML(String text, int wrapColumn)
text
- the wrapped text. It is automatically escapedwrapColumn
- after how many columns to break wordspublic static String generateRandomString(String characters, int length)
characters
- the available characterslength
- the lengthpublic static String wordWrappedHTMLElement(String text, int wrapColumn)
text
- the wrapped text. It is automatically escapedwrapColumn
- after how many columns to break wordspublic static boolean isNullOrEmpty(Object string)
string
- the stringpublic static String orElse(Object string, String ifNullOrEmpty)
string
- the stringifNullOrEmpty
- returned if string is null or emptypublic static String safeJsonify(String input)
input
- the input stringpublic static String jsonify(String input)
input
- the input stringpublic static String makeFilesystemCompatible(String input)
input
- filenamepublic static String makeUniqueString(String input, String spaceCharacter, Collection<String> existing)
input
- initial stringspaceCharacter
- character to add between the string and counting variableexisting
- collection of existing stringspublic static String makeUniqueString(String input, String spaceCharacter, Predicate<String> existing)
input
- initial stringspaceCharacter
- character to add between the string and counting variableexisting
- function that returns true if the string already existspublic static String getCleanedMenuPath(String menuPath)
menuPath
- a menu pathpublic static boolean isFilesystemCompatible(String string)
string
- the filenamepublic static String nullToEmpty(Object s)
s
- the stringpublic static String convertGlobToRegex(String pattern)
java.util.regex
API to
recognize strings which match the glob pattern.
See also, the POSIX Shell language: ...
See ...
pattern
- A glob pattern.public static int compareVersions(String version1, String version2)
version1
- the first versionversion2
- the second versionpublic static Object tryParseDoubleOrReturnString(String str)
str
- the stringpublic static double tryParseDouble(String str, double defaultValue)
public static int parseInt(String str)
public static double parseDouble(String str)
public static float parseFloat(String str)
public static double objectToDouble(Object o)
public static boolean isValidVersion(String version)
public static String formatSize(long size)
Copyright © 2020–2025 Leibniz Institute for Natural Product Research and Infection Biology - Hans Knöll Institute (HKI). All rights reserved.