Class TextUtil


  • public class TextUtil
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      TextUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean containsValue​(java.lang.String configString, java.lang.String value)
      Checks if a comma-separated configuration string contains a specific value.
      static java.lang.String formatNumber​(double number)
      Specialization of format.
      static java.lang.String formatNumber​(long number)
      Specialization of format.
      static java.lang.String formatString​(java.lang.String... str)  
      static boolean isNumeric​(java.lang.String str)
      Checks if a string is numeric.
      static java.lang.String joinConfig​(java.lang.String[] values)
      Joins an array of strings into a comma-separated, lowercase string.
      static boolean npcNameMatchesConfig​(java.lang.String npcName, java.lang.String configString)
      Checks if an NPC name matches any pattern in the configuration string.
      static java.lang.String quantityToRSDecimalStack​(int quantity)
      Convert a quantity to stack size as it would appear in RuneScape.
      static java.lang.String quantityToRSStackSize​(int quantity)
      Convert a quantity to stack size as it would appear in RuneScape.
      static java.lang.String quantityToStackSize​(long quantity)
      Convert a quantity to a nicely formatted stack size.
      static java.util.List<java.lang.String> splitByComma​(java.lang.String input)
      Splits a comma-separated string into a List of Strings.
      static java.lang.String[] splitConfig​(java.lang.String configString)
      Splits a configuration string by commas and converts to lowercase.
      static java.lang.String[] splitConfigExact​(java.lang.String configString)
      Splits a configuration string by commas without modifying case.
      static java.util.List<java.lang.Integer> splitConfigInt​(java.lang.String configString)
      Splits a comma-separated configuration string into a List of Integers.
      static java.util.Set<java.lang.String> splitConfigSet​(java.lang.String configString)
      Splits a comma-separated configuration string into a Set of Strings.
      static long stackSizeToQuantity​(java.lang.String stackSizeString)
      Converts a string representation of a stack back to (close to) it's original value.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TextUtil

        public TextUtil()
    • Method Detail

      • isNumeric

        public static boolean isNumeric​(java.lang.String str)
        Checks if a string is numeric.
        Parameters:
        str - the string to check
        Returns:
        true if str is numeric, false otherwise
      • splitConfigSet

        public static java.util.Set<java.lang.String> splitConfigSet​(java.lang.String configString)
        Splits a comma-separated configuration string into a Set of Strings.
        Parameters:
        configString - the comma-separated configuration string
        Returns:
        a Set of trimmed strings split by commas
      • splitConfigInt

        public static java.util.List<java.lang.Integer> splitConfigInt​(java.lang.String configString)
        Splits a comma-separated configuration string into a List of Integers. Only valid integers are added to the list; invalid values are ignored.
        Parameters:
        configString - the comma-separated configuration string
        Returns:
        a List of Integers parsed from the string
      • splitByComma

        public static java.util.List<java.lang.String> splitByComma​(java.lang.String input)
        Splits a comma-separated string into a List of Strings.
        Parameters:
        input - the comma-separated string
        Returns:
        a List of trimmed strings, or an empty list if the input is null or empty
      • npcNameMatchesConfig

        public static boolean npcNameMatchesConfig​(java.lang.String npcName,
                                                   java.lang.String configString)
        Checks if an NPC name matches any pattern in the configuration string. Patterns can use '*' as a prefix or suffix for wildcard matching.
        Parameters:
        npcName - the name of the NPC
        configString - the comma-separated configuration patterns
        Returns:
        true if the NPC name matches any pattern; false otherwise
      • splitConfig

        public static java.lang.String[] splitConfig​(java.lang.String configString)
        Splits a configuration string by commas and converts to lowercase.
        Parameters:
        configString - the comma-separated configuration string
        Returns:
        an array of lowercase strings split by commas
      • splitConfigExact

        public static java.lang.String[] splitConfigExact​(java.lang.String configString)
        Splits a configuration string by commas without modifying case.
        Parameters:
        configString - the comma-separated configuration string
        Returns:
        an array of strings split by commas
      • containsValue

        public static boolean containsValue​(java.lang.String configString,
                                            java.lang.String value)
        Checks if a comma-separated configuration string contains a specific value.
        Parameters:
        configString - the comma-separated configuration string
        value - the value to search for
        Returns:
        true if the value is found; false otherwise
      • joinConfig

        public static java.lang.String joinConfig​(java.lang.String[] values)
        Joins an array of strings into a comma-separated, lowercase string.
        Parameters:
        values - the array of strings to join
        Returns:
        a comma-separated string of lowercase values
      • quantityToStackSize

        public static java.lang.String quantityToStackSize​(long quantity)
        Convert a quantity to a nicely formatted stack size. See the StackFormatterTest to see expected output.
        Parameters:
        quantity - The quantity to convert.
        Returns:
        A condensed version, with commas, K, M or B as needed to 3 significant figures.
      • quantityToRSStackSize

        public static java.lang.String quantityToRSStackSize​(int quantity)
        Convert a quantity to stack size as it would appear in RuneScape.
        Parameters:
        quantity - The quantity to convert.
        Returns:
        The stack size as it would appear in RS, with K after 100,000 and M after 10,000,000
      • quantityToRSDecimalStack

        public static java.lang.String quantityToRSDecimalStack​(int quantity)
        Convert a quantity to stack size as it would appear in RuneScape. (with decimals)

        This differs from quantityToRSStack in that it displays decimals. Ex: 27100 is 27.1k (not 27k)

        Parameters:
        quantity - The quantity to convert.
        Returns:
        The stack size as it would appear in RS, with decimals, with K after 100,000 and M after 10,000,000
      • stackSizeToQuantity

        public static long stackSizeToQuantity​(java.lang.String stackSizeString)
                                        throws java.text.ParseException
        Converts a string representation of a stack back to (close to) it's original value.
        Parameters:
        stackSizeString - The string representation of the stack size to convert.
        Returns:
        A long representation of the quantity derived from the stack size.
        Throws:
        java.text.ParseException - If the input string cannot be parsed.
      • formatNumber

        public static java.lang.String formatNumber​(long number)
        Specialization of format.
        Parameters:
        number - the long number to format
        Returns:
        the formatted String
        Throws:
        java.lang.ArithmeticException - if rounding is needed with rounding mode being set to RoundingMode.UNNECESSARY
        See Also:
        Format.format(java.lang.Object)
      • formatNumber

        public static java.lang.String formatNumber​(double number)
        Specialization of format.
        Parameters:
        number - the double number to format
        Returns:
        the formatted String
        Throws:
        java.lang.ArithmeticException - if rounding is needed with rounding mode being set to RoundingMode.UNNECESSARY
        See Also:
        Format.format(java.lang.Object)
      • formatString

        public static java.lang.String formatString​(java.lang.String... str)