Class FormatUtils

java.lang.Object
redempt.redlib.misc.FormatUtils

public class FormatUtils extends Object
Contains utilities for formatting various information
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    color(String input)
    Shorthand for ChatColor.translateAlternateColorCodes(char, String) which also formats hex color codes
    static String
    color(String input, boolean hex)
    Shorthand for ChatColor.translateAlternateColorCodes(char, String) with the option to format hex color codes
    static String
    Formats a large number with commas, like 12345 as 12,345
    static String
    formatMoney(double money)
    Formats money like 3.5B representing 3.5 billion
    static 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)
    static List<String>
    lineWrap(String line, int maxLength)
    Splits a line of text across multiple lines, attempting to limit the length of each line
    static String
    Converts a string to camelCase, where every character after a space is capitalized.
    static 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FormatUtils

      public FormatUtils()
  • Method Details

    • formatTimeOffset

      public static String formatTimeOffset(long millis, int truncate)
      Formats a time offset like 1h3m8s (1 hour, 3 minutes, 8 seconds)
      Parameters:
      millis - The time offset, in milliseconds
      truncate - 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

      public static String formatTimeOffset(long millis)
      Formats a time offset like 1h3m8s (1 hour, 3 minutes, 8 seconds)
      Parameters:
      millis - The time offset, in milliseconds
      Returns:
      The formatted string
    • truncateDouble

      public static String truncateDouble(double input)
      Truncates a double using a DecimalFormat with 0.00 as its format string
      Parameters:
      input - The input double
      Returns:
      The formatted double
    • color

      public static String color(String input)
      Shorthand for ChatColor.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

      public static String color(String input, boolean hex)
      Shorthand for ChatColor.translateAlternateColorCodes(char, String) with the option to format hex color codes
      Parameters:
      input - The input string
      hex - Whether to translate hex color codes for 1.16+ (format: &#FF0000)
      Returns:
      The colored string, replacing color codes using ampersands with proper codes
    • formatMoney

      public static String formatMoney(double money)
      Formats money like 3.5B representing 3.5 billion
      Parameters:
      money - The money
      Returns:
      The formatted output string
    • formatLargeInteger

      public static String formatLargeInteger(long num)
      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

      public static String toTitleCase(String string)
      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

      public static String toCamelCase(String string)
      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

      public static List<String> lineWrap(String line, int maxLength)
      Splits a line of text across multiple lines, attempting to limit the length of each line
      Parameters:
      line - The line to wrap
      maxLength - The max length to cap each line at
      Returns:
      The list of separate lines