Class StringUtils
java.lang.Object
ml.karmaconfigs.api.common.utils.string.StringUtils
Karma string utilities
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareNullOrEmpty(Object... checks)Get if the objects are null or emptystatic <T> Set<T>arrayToSet(T[] array)Parse an array to a setstatic VersionComparatorcompareTo(ComparatorBuilder builder)Get the version difference between two versionsstatic booleancontainsLetters(CharSequence sequence)Get if the text contains letterstatic booleancontainsNumbers(CharSequence sequence)Get if the text contains numbersstatic StringescapeString(String text)Escape textstatic StringformatString(CharSequence text, Object... replaces)Format the specified textstatic StringformatString(CharSequence text, Map<String,Object> replaces)Deprecated.static StringformatString(KarmaSource owner, CharSequence text, Level level)Format the specified textstatic StringformatString(KarmaSource owner, CharSequence text, Level level, Object... replaces)Format the specified textstatic RandomStringGenerate a new random textstatic RandomStringgenerateString(OptionsBuilder options)Generate a new random textGet a set of colors present in the textstatic StringgetLastColor(String text)Get the last color present on a textstatic StringgetLastColor(List<String> texts, int index)Get the last color from a list of textsstatic StringinsertInEachSpace(String text, String insert, int period, boolean replaceSpace)Insert a text each amount of characters as soon as the character is a space/emptystatic StringinsetInEach(String text, String insert, int period)Insert a text each amount of charactersstatic booleanisNullOrEmpty(Object check)Get if the object is null or emptystatic StringlistToString(List<String> lines, boolean spaces)Transform a list of texts into a single text linestatic @Nullable ObjectLoad the instance as an unknown objectstatic <T> TloadUnsafe(String instance)Load unsafely the instance as a known objectstatic StringparseLetters(CharSequence original, Character... keep)Parse only the letters from the textstatic StringparseNumbers(CharSequence original, Character... keep)Parse only the numbers from the textstatic StringGenerate a random colorstatic StringRead the file completelystatic StringremoveLetters(CharSequence original)Remove the letters from textstatic StringremoveNumbers(CharSequence original)Remove the numbers from textstatic StringreplaceLast(String text, String regex, String replace)Replace the last regex in the textstatic <T> Stringserialize(T instance)Serialize an object into a textstatic String[]splitInEach(String text, int period)Split a text by each charactersstatic String[]splitInEachSpace(String text, int period, boolean replaceSpace)Split a text by each characters if it's a spacestatic StringstripColor(String text)Remove the color on the textstripColor(List<String> texts)Remove the colors from a textsstatic StringtimeToString(long milliseconds)Convert the time in milliseconds into a readable time string formatstatic StringtimeToString(long milliseconds, TimeName name)Convert the time in milliseconds into a readable time string formatstatic StringTransform the text colors to a valid colorsTransform the list of text to a colored list of textstatic StringtoConsoleColor(CharSequence text)Transform the text colors to a valid colorsstatic StringunEscapeString(String text)Un scape text
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
replaceLast
Replace the last regex in the text- Parameters:
text- the text to search inregex- the text to findreplace- the text to replace with- Returns:
- the replaced text
-
insetInEach
Insert a text each amount of characters- Parameters:
text- the original textinsert- the text to insertperiod- the amount of characters- Returns:
- the formatted text
-
insertInEachSpace
public static String insertInEachSpace(String text, String insert, int period, boolean replaceSpace)Insert a text each amount of characters as soon as the character is a space/empty- Parameters:
text- the original textinsert- the text to insertperiod- the amount of charactersreplaceSpace- replace the empty character with the insert- Returns:
- the formatted text
-
splitInEach
Split a text by each characters- Parameters:
text- the original textperiod- the amount of characters- Returns:
- the splitted text
-
splitInEachSpace
Split a text by each characters if it's a space- Parameters:
text- the original textperiod- the amount of charactersreplaceSpace- replace the empty character with the insert- Returns:
- the splitted text
-
toColor
Transform the text colors to a valid colors- Parameters:
text- the text to translate- Returns:
- the translated text
-
toConsoleColor
Transform the text colors to a valid colors- Parameters:
text- the text to translate- Returns:
- the translated text
-
toColor
Transform the list of text to a colored list of text- Parameters:
texts- the texts to translate- Returns:
- the colored texts
-
getColors
Get a set of colors present in the text- Parameters:
text- the text to read from- Returns:
- the text colors
-
getLastColor
Get the last color present on a text- Parameters:
text- the text to read from- Returns:
- the text colors
-
getLastColor
Get the last color from a list of texts- Parameters:
texts- the list of textsindex- the text index- Returns:
- the texts last color
-
stripColor
Remove the color on the text- Parameters:
text- the text to read- Returns:
- the text without colors
-
stripColor
Remove the colors from a texts- Parameters:
texts- the texts- Returns:
- the uncolored texts
-
generateString
Generate a new random text- Returns:
- a random text creator
-
generateString
Generate a new random text- Parameters:
options- the random text options- Returns:
- a random text creator
-
randomColor
Generate a random color- Returns:
- a random color
-
formatString
Format the specified text- Parameters:
text- the text to formatreplaces- the text replaces- Returns:
- the formatted text
-
formatString
Deprecated.It's better to usenow. By default, KarmaAPI usesGlobalPlaceholderEnginewith a implementation ofPlaceholderasSimplePlaceholder. For now, this method registers the map key to a placeholder which contains the map value and uses global placeholder engine to return the formatted stringFormat the specified text- Parameters:
text- the text to formatreplaces- the text replaces- Returns:
- the formatted text
-
formatString
Format the specified text- Parameters:
owner- the text ownertext- the text to formatlevel- the text level- Returns:
- the formatted text
-
formatString
public static String formatString(KarmaSource owner, CharSequence text, Level level, Object... replaces)Format the specified text- Parameters:
owner- the text ownertext- the text to formatlevel- the text levelreplaces- the text replaces- Returns:
- the formatted text
-
readFrom
Read the file completely- Parameters:
file- the file to read- Returns:
- the file content as text
-
listToString
Transform a list of texts into a single text line- Parameters:
lines- the linesspaces- replace new lines with spaces, otherwise, new lines will be replaced with nothing and '\n' will be added at the end of the line- Returns:
- the list of texts as single line text
-
unEscapeString
Un scape text- Parameters:
text- the text to un scape- Returns:
- the unescaped text
-
escapeString
Escape text- Parameters:
text- the text to scape- Returns:
- the escaped text
-
serialize
Serialize an object into a text- Type Parameters:
T- the objet type- Parameters:
instance- the object instance- Returns:
- the serialized object
-
load
Load the instance as an unknown object- Parameters:
instance- the serialized instance- Returns:
- the instance object
-
loadUnsafe
Load unsafely the instance as a known object- Type Parameters:
T- the type- Parameters:
instance- the instance- Returns:
- the instance type
-
containsLetters
Get if the text contains letter- Parameters:
sequence- the text- Returns:
- if the text contains letter
-
containsNumbers
Get if the text contains numbers- Parameters:
sequence- the text- Returns:
- if the text contains letter
-
isNullOrEmpty
Get if the object is null or empty- Parameters:
check- the object to check- Returns:
- if the object is null or empty
-
areNullOrEmpty
Get if the objects are null or empty- Parameters:
checks- the objects to check- Returns:
- if the objects are null or empty
-
compareTo
Get the version difference between two versions- Parameters:
builder- the version difference builder- Returns:
- a new version comparator
-
removeNumbers
Remove the numbers from text- Parameters:
original- the original text- Returns:
- the text without numbers
-
removeLetters
Remove the letters from text- Parameters:
original- the original text- Returns:
- the text without letters
-
parseNumbers
Parse only the numbers from the text- Parameters:
original- the original textkeep- the characters to allow- Returns:
- the parsed text
-
parseLetters
Parse only the letters from the text- Parameters:
original- the original textkeep- the characters to allow- Returns:
- the parsed text
-
timeToString
Convert the time in milliseconds into a readable time string format- Parameters:
milliseconds- the milliseconds- Returns:
- the time in seconds
-
timeToString
Convert the time in milliseconds into a readable time string format- Parameters:
milliseconds- the millisecondsname- the unit names- Returns:
- the time in seconds
-
arrayToSet
Parse an array to a set
-
now.