Package redempt.redlib.misc
Class FormatUtils
java.lang.Object
redempt.redlib.misc.FormatUtils
Contains utilities for formatting various information
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Shorthand forChatColor.translateAlternateColorCodes(char, String)
which also formats hex color codesstatic String
Shorthand forChatColor.translateAlternateColorCodes(char, String)
with the option to format hex color codesstatic String
formatLargeInteger
(long num) Formats a large number with commas, like 12345 as 12,345static String
formatMoney
(double money) Formats money like 3.5B representing 3.5 billionstatic String
formatTimeOffset
(long millis) Formats a time offset like 1h3m8s (1 hour, 3 minutes, 8 seconds)static String
formatTimeOffset
(long millis, int truncate) Formats a time offset like 1h3m8s (1 hour, 3 minutes, 8 seconds)Splits a line of text across multiple lines, attempting to limit the length of each linestatic String
toCamelCase
(String string) Converts a string to camelCase, where every character after a space is capitalized.static String
toTitleCase
(String string) Converts a string to Title Case, where the first character and every character after a space is capitalized.static String
truncateDouble
(double input) Truncates a double using a DecimalFormat with 0.00 as its format string
-
Constructor Details
-
FormatUtils
public FormatUtils()
-
-
Method Details
-
formatTimeOffset
Formats a time offset like 1h3m8s (1 hour, 3 minutes, 8 seconds)- Parameters:
millis
- The time offset, in millisecondstruncate
- The number of units to truncate - 1 for seconds, 2 for seconds and minutes, 3 for seconds, minutes, and hours- Returns:
- The formatted string
-
formatTimeOffset
Formats a time offset like 1h3m8s (1 hour, 3 minutes, 8 seconds)- Parameters:
millis
- The time offset, in milliseconds- Returns:
- The formatted string
-
truncateDouble
Truncates a double using a DecimalFormat with 0.00 as its format string- Parameters:
input
- The input double- Returns:
- The formatted double
-
color
Shorthand forChatColor.translateAlternateColorCodes(char, String)
which also formats hex color codes- Parameters:
input
- The input string- Returns:
- The colored string, replacing color codes using ampersands with proper codes
-
color
Shorthand forChatColor.translateAlternateColorCodes(char, String)
with the option to format hex color codes- Parameters:
input
- The input stringhex
- Whether to translate hex color codes for 1.16+ (format: &#FF0000)- Returns:
- The colored string, replacing color codes using ampersands with proper codes
-
formatMoney
Formats money like 3.5B representing 3.5 billion- Parameters:
money
- The money- Returns:
- The formatted output string
-
formatLargeInteger
Formats a large number with commas, like 12345 as 12,345- Parameters:
num
- The number to format- Returns:
- The formatted String representing the number
-
toTitleCase
Converts a string to Title Case, where the first character and every character after a space is capitalized. Preserves spaces.- Parameters:
string
- The string to convert to Title Case- Returns:
- The Title Case string
-
toCamelCase
Converts a string to camelCase, where every character after a space is capitalized. Removes spaces.- Parameters:
string
- The string to convert to camelCase- Returns:
- The camelCase string
-
lineWrap
Splits a line of text across multiple lines, attempting to limit the length of each line- Parameters:
line
- The line to wrapmaxLength
- The max length to cap each line at- Returns:
- The list of separate lines
-