Package net.risingworld.api.utils
Class Utils.StringUtils
java.lang.Object
net.risingworld.api.utils.Utils.StringUtils
- Enclosing class:
Utils
Various String functions, i.e functions to check if certain strings are
numeric, getting checksums of strings, and conversion utils.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
combineStringArray
(String[] array, int start, int end, char delimiter) static String
firstCharToLower
(String string) static String
firstCharToUpper
(String string) static String[]
Splits the string by new line characters, i.e \n or \r etc.static String
Generates an MD5 hash from the provided string.static boolean
Determines whether or not the provided string represents a boolean value (lower case, it will only return true for "true" or "false").static boolean
Determines whether or not the provided string represents a hexadecimal (hex) value using a "0x" prefix (for example, it will return true for values like "0xFF", "0xaabbcc", "0x41AB", "0x0", but false for strings like "56", "#FFAA13", "0xZVKK").static boolean
Determines whether or not the provided string represents an integer/long value (for example, it will return true for values like "0", "1", "-7", "42", but false for strings like "7.62", "Hello", "5+5" etc).static boolean
Determines whether or not the provided string represents a numeric value (integer/long or float/double, for example, it will return true for values like "0", "1.426", "-100", "22.0", but false for strings like "3k", "Bonjour", "7*7" etc).static boolean
parseBoolean
(String string, boolean defaultValue) Tries to parse a boolean from a string.static double
parseDouble
(String string, double defaultValue) Tries to parse a float value from a string.static float
parseFloat
(String string, float defaultValue) Tries to parse a float value from a string.static int
parseInteger
(String string, int defaultValue) Tries to parse an integer value from a string.static long
Tries to parse a long value from a string.static String
static String
removeAllLeadingWhitespaces
(String string) Removes all leading white spaces.static String
removeAllNonWordCharacters
(String string) static String
removeAllTrailingWhitespaces
(String string) static String
removeAllWhitespaces
(String string) static String
vector3fToString
(Vector3f vector3f)
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
parseInteger
Tries to parse an integer value from a string. If the provided string is an integer, the parsed int will be returned. Otherwise the provided default value is returned instead.- Parameters:
string
- the string you want to parse.defaultValue
- the default return value if the string could not be parsed.- Returns:
- the parsed int value, or the provided default value if the string could not be parsed.
-
parseLong
Tries to parse a long value from a string. If the provided string is an integer/long, the parsed long will be returned. Otherwise the provided default value is returned instead.- Parameters:
string
- the string you want to parse.defaultValue
- the default return value if the string could not be parsed.- Returns:
- the parsed long value, or the provided default value if the string could not be parsed.
-
parseFloat
Tries to parse a float value from a string. If the provided string is a floating number, the parsed float will be returned. Otherwise the provided default value is returned instead.- Parameters:
string
- the string you want to parse.defaultValue
- the default return value if the string could not be parsed.- Returns:
- the parsed float value, or the provided default value if the string could not be parsed.
-
parseDouble
Tries to parse a float value from a string. If the provided string is a floating number, the parsed float will be returned. Otherwise the provided default value is returned instead.- Parameters:
string
- the string you want to parse.defaultValue
- the default return value if the string could not be parsed.- Returns:
- the parsed float value, or the provided default value if the string could not be parsed.
-
parseBoolean
Tries to parse a boolean from a string. If the provided string is "true" or "false" (or "1" or "0"), the parsed boolean value will be returned. Otherwise the provided default value is returned instead.- Parameters:
string
- the string you want to parse.defaultValue
- the default return value if the string could not be parsed.- Returns:
- the parsed boolean value, or the provided default value if the string could not be parsed.
-
isInteger
Determines whether or not the provided string represents an integer/long value (for example, it will return true for values like "0", "1", "-7", "42", but false for strings like "7.62", "Hello", "5+5" etc).- Parameters:
string
- the string you want to check.- Returns:
- true if the provided string represents an int value, false if not.
-
isNumeric
Determines whether or not the provided string represents a numeric value (integer/long or float/double, for example, it will return true for values like "0", "1.426", "-100", "22.0", but false for strings like "3k", "Bonjour", "7*7" etc).- Parameters:
string
- the string you want to check.- Returns:
- true if the provided string represents a numeric value, false if not.
-
isHex
Determines whether or not the provided string represents a hexadecimal (hex) value using a "0x" prefix (for example, it will return true for values like "0xFF", "0xaabbcc", "0x41AB", "0x0", but false for strings like "56", "#FFAA13", "0xZVKK").- Parameters:
string
- the string you want to check.- Returns:
- true if the provided string represents a hex value, false if not.
-
isBoolean
Determines whether or not the provided string represents a boolean value (lower case, it will only return true for "true" or "false").- Parameters:
string
- the string you want to check.- Returns:
- true if the provided string equals "true" or "false", false if not.
-
combineStringArray
-
firstCharToUpper
-
firstCharToLower
-
removeAllNonWordCharacters
-
removeAllWhitespaces
-
removeAllLeadingWhitespaces
Removes all leading white spaces. e.g if you provide the string " Test", this function returns "Test". If you provide "Hello World", this function returns the unmodified "Hello World" string.- Parameters:
string
- the string you want to remove the leading white spaces from.- Returns:
- the new string which does not contain any leading white spaces.
-
removeAllTrailingWhitespaces
-
removeAllLeadingAndTrailingWhitespaces
-
getLines
Splits the string by new line characters, i.e \n or \r etc. Returns a character containing the individual lines. Does not contain empty lines.- Parameters:
string
- the string you want to split, e.g the text from a text file.- Returns:
- the individual lines as an array of strings.
-
getMd5
Generates an MD5 hash from the provided string. This is useful for checksums etc., but keep in mind that MD5 is not safe enough for saving passwords, for example.- Parameters:
string
- the string you want to turn into an MD5 hash.- Returns:
- an MD5 hash.
-
vector3fToString
-