Class StringUtils
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic List<StringUtils.SplitInfo>advancedSplit(String str, char separatorChar, boolean preserveAllTokens) static booleanareElementsEmpty(Collection<String> strings) static <K,V> StringBuilder associatedArrayMap(Map<K, V> map) static StringbuildArguments(String[] args) static StringbuildArguments(String[] args, int from) static StringbuildArguments(String[] args, String joinStr) static StringbuildArguments(String[] args, String joinStr, int from) Converts all the arguments to a single string from the start index.static Stringcapitalize(String str) Capitalizes the first letter of a string and lowercase the other letters.cleanSplit(String str, char separator) cleanSplitManaged(String str, char separator) static StringconfigOption(Enum<?> enumeral) static StringconfigOption(String str) static StringconfigOptionToEnum(String str) static booleanChecks if String contains a search character, handlingnull.static booleancontainsAny(String str, String... strings) Checks if the given string contains any of the other strings.static booleanstatic booleanChecks if the given string contains a number.static booleancontainsWhitespace(String str) static StringdeleteWhitespace(String str) static booleanstatic StringfindCapitalized(String str) static StringfindSimilar(String name, Collection<String> names) static StringgeneratedToString(Object instance) static StringgetGroupedOption(String option, int... grouped) Translates an enum to a config option with grouped key sections using dots.static DimensiongetImageSize(URL url) static booleanhasSymbol(CharSequence str) static intindexOfAny(String str, String[] searchStrs) Find the first index of any of a set of potential substrings.static booleanisCalledFromClass(Class<?> clazz) static booleanisEnglish(CharSequence str) Checks if every single character in a string is English.static booleanisEnglishDigit(char ch) static booleanisEnglishLetter(char ch) static booleanisEnglishLetterOrDigit(char ch) static booleanstatic booleanChecks if the given string is equal to any of the other strings.static booleanisPureNumber(String str) static CharSequencejoin(char delimiter, CharSequence... elements) static StringJoins the elements of the provided array into a single String containing the provided list of elements.static StringJoins the elements of the provided array into a single String containing the provided list of elements.static Stringjoin(String delimiter, Collection<String> elements, com.google.common.base.Function<String, String> decorator) static Stringjoin(String delimiter, Collection<String> elements, com.google.common.base.Function<String, String> decorator, String empty) static voidlogComponents(net.md_5.bungee.api.chat.BaseComponent... components) static StringlowerCaseReplaceChar(String str, char variable, char replacement) static DoubleparseDouble(org.bukkit.entity.Player player, String str) static Integerstatic voidperformCommands(org.bukkit.OfflinePlayer offlinePlayer, Collection<String> commands) static voidprintConfig(org.bukkit.configuration.ConfigurationSection section) static voidprintConfig(org.bukkit.configuration.ConfigurationSection section, String nestLevel) static voidprintConfig(ConfigSection section) static voidstatic voidprintStackTrace(StackTraceElement[] stackTraceElements, int skip) static Stringstatic Stringstatic StringRemoves all occurrences of a substring from within the source string.static Stringrepeat(char ch, int times) static Stringstatic CharSequencestatic CharSequencestatic StringReplaces all occurrences of a String within another String.static StringReplaces a String with another String inside a larger String, for the firstmaxvalues of the search String.static StringreplaceOnce(String text, char search, String replacement) static StringreplaceOnce(String text, String searchString, String replacement) Replaces a String with another String inside a larger String, once.static Stringstatic Stringspaces(int times) static String[]splitArray(String str, char separatorChar) static String[]splitArray(String str, char separatorChar, boolean preserveAllTokens) splitByLength(List<String> strings, int length) static String[]splitLocation(String str, int size) static Stringstatic StringtoFancyNumber(double number) static StringtoLatinLowerCase(String str) static StringtoLatinUpperCase(String str) static StringtoOrdinalNumeral(int num) static StringupperCaseReplaceChar(String str, char variable, char replacement) static URLvalidateURL(String str)
-
Field Details
-
INDEX_NOT_FOUND
public static final int INDEX_NOT_FOUND- See Also:
-
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
random
-
findCapitalized
-
parseInt
-
parseDouble
-
capitalize
Capitalizes the first letter of a string and lowercase the other letters. Apache's org.apache.commons.lang.StringUtils#capitalize(String) doesn't lowercase the other half.- Parameters:
str- the string to capitalize.- Returns:
- a capitalized word.
- Since:
- 1.0.0
-
contains
Checks if String contains a search character, handling
null. This method usesString.indexOf(int).A
nullor empty ("") String will returnfalse.StringUtils.contains(null, *) = false StringUtils.contains("", *) = false StringUtils.contains("abc", 'a') = true StringUtils.contains("abc", 'z') = false- Parameters:
str- the String to check, may be nullsearchChar- the character to find- Returns:
- true if the String contains the search character,
false if not or
nullstring input - Since:
- 2.0
-
splitByLength
-
configOption
-
configOptionToEnum
-
configOption
-
logComponents
public static void logComponents(net.md_5.bungee.api.chat.BaseComponent... components) -
findSimilar
-
areElementsEmpty
-
repeat
-
repeat
-
containsWhitespace
-
toLatinLowerCase
-
replaceOnce
-
replace
-
replace
-
generatedToString
-
toLatinUpperCase
-
upperCaseReplaceChar
-
join
Joins the elements of the provided array into a single String containing the provided list of elements.
No delimiter is added before or after the list. A
nullseparator is the same as an empty String (""). Null objects or empty strings within the array are represented by empty strings.StringUtils.join(null, *) = null StringUtils.join([], *) = "" StringUtils.join([null], *) = "" StringUtils.join(["a", "b", "c"], "--") = "a--b--c" StringUtils.join(["a", "b", "c"], null) = "abc" StringUtils.join(["a", "b", "c"], "") = "abc" StringUtils.join([null, "", "a"], ',') = ",,a"
- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to use, null treated as ""- Returns:
- the joined String,
nullif null array input
-
join
Joins the elements of the provided array into a single String containing the provided list of elements.
No delimiter is added before or after the list. A
nullseparator is the same as an empty String (""). Null objects or empty strings within the array are represented by empty strings.StringUtils.join(null, *) = null StringUtils.join([], *) = "" StringUtils.join([null], *) = "" StringUtils.join(["a", "b", "c"], "--") = "a--b--c" StringUtils.join(["a", "b", "c"], null) = "abc" StringUtils.join(["a", "b", "c"], "") = "abc" StringUtils.join([null, "", "a"], ',') = ",,a"
- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to use, null treated as ""startIndex- the first index to start joining from. It is an error to pass in an end index past the end of the arrayendIndex- the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array- Returns:
- the joined String,
nullif null array input
-
lowerCaseReplaceChar
-
isEnglish
Checks if every single character in a string is English. English characters consists of whitespaces, alphabets and numbers Characters such as !@#$%^&*()_+| will not be accepted.- Parameters:
str- the string to check.- Returns:
- true if the whole string is in English, otherwise false.
- Since:
- 1.0.0
- See Also:
-
validateURL
-
hasSymbol
-
isEnglishLetter
public static boolean isEnglishLetter(char ch) -
isEnglishDigit
public static boolean isEnglishDigit(char ch) -
cleanSplit
-
cleanSplitManaged
-
deleteWhitespace
-
join
-
join
-
join
-
toOrdinalNumeral
-
split
-
advancedSplit
@Nonnull public static List<StringUtils.SplitInfo> advancedSplit(@Nonnull String str, char separatorChar, boolean preserveAllTokens) -
splitLocation
-
isEnglishLetterOrDigit
public static boolean isEnglishLetterOrDigit(char ch) -
stacktrace
-
printStackTrace
public static void printStackTrace() -
printStackTrace
-
isCalledFromClass
-
fakeBool
-
containsNumber
Checks if the given string contains a number.- Parameters:
str- the string to check the numbers.- Returns:
- true if the string contains any number, otherwise false.
- Since:
- 1.0.0
- See Also:
-
containsAnyLangNumber
-
getImageSize
-
isNumeric
-
associatedArrayMap
-
spaces
-
isPureNumber
-
indexOfAny
Find the first index of any of a set of potential substrings.
A
nullString will return-1. Anullor zero length search array will return-1. Anullsearch array entry will be ignored, but a search array containing "" will return0ifstris not null. This method usesString.indexOf(String).StringUtils.indexOfAny(null, *) = -1 StringUtils.indexOfAny(*, null) = -1 StringUtils.indexOfAny(*, []) = -1 StringUtils.indexOfAny("zzabyycdxx", ["ab","cd"]) = 2 StringUtils.indexOfAny("zzabyycdxx", ["cd","ab"]) = 2 StringUtils.indexOfAny("zzabyycdxx", ["mn","op"]) = -1 StringUtils.indexOfAny("zzabyycdxx", ["zab","aby"]) = 1 StringUtils.indexOfAny("zzabyycdxx", [""]) = 0 StringUtils.indexOfAny("", [""]) = 0 StringUtils.indexOfAny("", ["a"]) = -1- Parameters:
str- the String to check, may be nullsearchStrs- the Strings to search for, may be null- Returns:
- the first index of any of the searchStrs in str, -1 if no match
-
getGroupedOption
Translates an enum to a config option with grouped key sections using dots.Examples
getGroupedOption("HELLO_WORLD"); // Output: hello-world getGroupedOption("WHATS_UP_WORLD", 1); // Output: whats: up-world: getGroupedOption("GOODBYE_CRUEL_WORLD", 1, 2); // Output: goodbye: cruel: world:- Parameters:
grouped- the groups index (will be replaced with "_").- Returns:
- the config option.
- Since:
- 1.0.0
-
splitArray
-
splitArray
-
reverse
-
isOneOf
Checks if the given string is equal to any of the other strings.- Parameters:
str- the original string.strings- the other strings to check.- Returns:
- true if the original string is equal to one of the other strings, otherwise false.
- Since:
- 1.0.0
-
toFancyNumber
-
printConfig
public static void printConfig(org.bukkit.configuration.ConfigurationSection section) -
printConfig
public static void printConfig(org.bukkit.configuration.ConfigurationSection section, String nestLevel) -
printConfig
-
remove
-
remove
Removes all occurrences of a substring from within the source string.
A
nullsource string will returnnull. An empty ("") source string will return the empty string. Anullremove string will return the source string. An empty ("") remove string will return the source string.StringUtils.remove(null, *) = null StringUtils.remove("", *) = "" StringUtils.remove(*, null) = * StringUtils.remove(*, "") = * StringUtils.remove("queued", "ue") = "qd" StringUtils.remove("queued", "zz") = "queued"- Parameters:
str- the source String to search, may be nullremove- the String to search for and remove, may be null- Returns:
- the substring with the string removed if found,
nullif null String input - Since:
- 2.1
-
replaceOnce
Replaces a String with another String inside a larger String, once.
A
nullreference passed to this method is a no-op.StringUtils.replaceOnce(null, *, *) = null StringUtils.replaceOnce("", *, *) = "" StringUtils.replaceOnce("any", null, *) = "any" StringUtils.replaceOnce("any", *, null) = "any" StringUtils.replaceOnce("any", "", *) = "any" StringUtils.replaceOnce("aba", "a", null) = "aba" StringUtils.replaceOnce("aba", "a", "") = "ba" StringUtils.replaceOnce("aba", "a", "z") = "zba"- Parameters:
text- text to search and replace in, may be nullsearchString- the String to search for, may be nullreplacement- the String to replace with, may be null- Returns:
- the text with any replacements processed,
nullif null String input - See Also:
-
replace
Replaces all occurrences of a String within another String.
A
nullreference passed to this method is a no-op.StringUtils.replace(null, *, *) = null StringUtils.replace("", *, *) = "" StringUtils.replace("any", null, *) = "any" StringUtils.replace("any", *, null) = "any" StringUtils.replace("any", "", *) = "any" StringUtils.replace("aba", "a", null) = "aba" StringUtils.replace("aba", "a", "") = "b" StringUtils.replace("aba", "a", "z") = "zbz"- Parameters:
text- text to search and replace in, may be nullsearchString- the String to search for, may be nullreplacement- the String to replace it with, may be null- Returns:
- the text with any replacements processed,
nullif null String input - See Also:
-
replace
Replaces a String with another String inside a larger String, for the first
maxvalues of the search String.A
nullreference passed to this method is a no-op.StringUtils.replace(null, *, *, *) = null StringUtils.replace("", *, *, *) = "" StringUtils.replace("any", null, *, *) = "any" StringUtils.replace("any", *, null, *) = "any" StringUtils.replace("any", "", *, *) = "any" StringUtils.replace("any", *, *, 0) = "any" StringUtils.replace("abaa", "a", null, -1) = "abaa" StringUtils.replace("abaa", "a", "", -1) = "b" StringUtils.replace("abaa", "a", "z", 0) = "abaa" StringUtils.replace("abaa", "a", "z", 1) = "zbaa" StringUtils.replace("abaa", "a", "z", 2) = "zbza" StringUtils.replace("abaa", "a", "z", -1) = "zbzz"- Parameters:
text- text to search and replace in, may be nullsearchString- the String to search for, may be nullreplacement- the String to replace it with, may be nullmax- maximum number of values to replace, or-1if no maximum- Returns:
- the text with any replacements processed,
nullif null String input
-
containsAny
Checks if the given string contains any of the other strings.- Parameters:
str- the original stringstrings- the other strings to check- Returns:
- true if the original string contains one of the other strings, otherwise false.
- Since:
- 1.0.0
-
buildArguments
Converts all the arguments to a single string from the start index.Examples
String args = {"hello", "hi", "goodbye"}; buildArguments(args, ", ", 0); // Output: hello, hi, goodbye buildArguments(args, "", 1); // Output: higoodbye- Parameters:
args- the arguments to convert to string.joinStr- the string to put between each argument when converting to string.from- the index where it should start converting from.- Returns:
- a converted string.
- Since:
- 1.0.0
-
performCommands
public static void performCommands(org.bukkit.OfflinePlayer offlinePlayer, Collection<String> commands) -
buildArguments
-
buildArguments
-
buildArguments
-