Class StringUtils


  • public class StringUtils
    extends java.lang.Object
    Collection of small static helper methods using Strings.
    • Constructor Summary

      Constructors 
      Constructor Description
      StringUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String capitalize​(java.lang.String s)
      Capitalize a string in the default locale.
      static java.lang.String capitalize​(java.lang.String s, java.util.Locale locale)
      Capitalize a string in a specific locale.
      static java.lang.String chop​(java.lang.String str, int maxLength)
      Truncate a string to a maximum length.
      static java.lang.String downCase​(java.lang.String s)
      Downcase a string in the default locale.
      private static java.lang.String downCase​(java.lang.String s, java.util.Locale locale)
      Downcase a string in a specific locale.
      static java.lang.String firstPart​(java.lang.String s, java.lang.String delim)
      Gets the first part of a string before a supplied delimiter.
      static int getBreakingPoint​(java.lang.String string)
      Find a breaking point in a line between two words.
      private static int getBreakingPoint​(java.lang.String string, java.lang.String delim)
      Find a breaking point in a line between two words.
      static java.lang.String getEnumKey​(java.lang.Enum<?> value)
      Get the standard form an enum is used as a key.
      static java.lang.String join​(java.lang.String delimiter, java.lang.String... strings)
      Joins the given strings.
      static java.lang.String join​(java.lang.String delimiter, java.util.Collection<java.lang.String> strings)
      Joins the given strings.
      static java.lang.String lastPart​(java.lang.String s, java.lang.String delim)
      Gets the last part of a string after a supplied delimiter.
      static java.util.List<java.lang.String> splitText​(java.lang.String text, java.lang.String delim, java.awt.FontMetrics fontMetrics, int width)
      Split some text at word boundaries into a list of strings that take up no more than a given width.
      static java.lang.String upCase​(java.lang.String s)
      Upcase a string in the default locale.
      private static java.lang.String upCase​(java.lang.String s, java.util.Locale locale)
      Upcase a string in a specific locale.
      • Methods inherited from class java.lang.Object

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

      • StringUtils

        public StringUtils()
    • Method Detail

      • join

        public static java.lang.String join​(java.lang.String delimiter,
                                            java.lang.String... strings)
        Joins the given strings. In Java 8, we can use String.join.
        Parameters:
        delimiter - The delimiter to place between the individual strings.
        strings - The strings to be joined.
        Returns:
        Each of the strings in the given array delimited by the given string.
      • join

        public static java.lang.String join​(java.lang.String delimiter,
                                            java.util.Collection<java.lang.String> strings)
        Joins the given strings.
        Parameters:
        delimiter - The delimiter to place between the individual strings.
        strings - The strings to be joined.
        Returns:
        Each of the strings in the given array delimited by the given string.
      • chop

        public static java.lang.String chop​(java.lang.String str,
                                            int maxLength)
        Truncate a string to a maximum length.
        Parameters:
        str - The string to chop.
        maxLength - The maximum length.
        Returns:
        A string not exceeding maxLength.
      • firstPart

        public static java.lang.String firstPart​(java.lang.String s,
                                                 java.lang.String delim)
        Gets the first part of a string before a supplied delimiter.
        Parameters:
        s - The string to operate on.
        delim - The delimiter.
        Returns:
        The first part of the string before the first instance of the delimiter, or the original string if the delimiter is not present.
      • lastPart

        public static java.lang.String lastPart​(java.lang.String s,
                                                java.lang.String delim)
        Gets the last part of a string after a supplied delimiter.
        Parameters:
        s - The string to operate on.
        delim - The delimiter.
        Returns:
        The last part of the string after the last instance of the delimiter, or the original string if the delimiter is not present.
      • getEnumKey

        public static java.lang.String getEnumKey​(java.lang.Enum<?> value)
        Get the standard form an enum is used as a key. Convert to lower case, and remove underscores uppercasing the next letter.
        Parameters:
        value - The enum value.
        Returns:
        A suitable key.
      • getBreakingPoint

        public static int getBreakingPoint​(java.lang.String string)
        Find a breaking point in a line between two words. The breaking point is as close to the center as possible.
        Parameters:
        string - The line for which we should determine a breaking point.
        Returns:
        The best breaking point or negative if none found.
      • getBreakingPoint

        private static int getBreakingPoint​(java.lang.String string,
                                            java.lang.String delim)
        Find a breaking point in a line between two words. The breaking point is as close to the center as possible.
        Parameters:
        string - The line for which we should determine a breaking point.
        delim - Characters to consider as word delimiting.
        Returns:
        The best breaking point or negative if none found.
      • splitText

        public static java.util.List<java.lang.String> splitText​(java.lang.String text,
                                                                 java.lang.String delim,
                                                                 java.awt.FontMetrics fontMetrics,
                                                                 int width)
        Split some text at word boundaries into a list of strings that take up no more than a given width.
        Parameters:
        text - The text to split.
        delim - Characters to consider as word delimiting.
        fontMetrics - FontMetrics used to calculate text width.
        width - The text width maximum.
        Returns:
        A list of split text.
      • capitalize

        public static java.lang.String capitalize​(java.lang.String s)
        Capitalize a string in the default locale.
        Parameters:
        s - The String to capitalize.
        Returns:
        The capitalized string.
      • capitalize

        public static java.lang.String capitalize​(java.lang.String s,
                                                  java.util.Locale locale)
        Capitalize a string in a specific locale.
        Parameters:
        s - The String to capitalize.
        locale - The Locale to apply.
        Returns:
        The capitalized string.
      • downCase

        public static java.lang.String downCase​(java.lang.String s)
        Downcase a string in the default locale.
        Parameters:
        s - The String to convert to lower case.
        Returns:
        The converted string.
      • downCase

        private static java.lang.String downCase​(java.lang.String s,
                                                 java.util.Locale locale)
        Downcase a string in a specific locale.
        Parameters:
        s - The String to convert to lower case.
        locale - The Locale to apply.
        Returns:
        The converted string.
      • upCase

        public static java.lang.String upCase​(java.lang.String s)
        Upcase a string in the default locale.
        Parameters:
        s - The String to convert to upper case.
        Returns:
        The converted string.
      • upCase

        private static java.lang.String upCase​(java.lang.String s,
                                               java.util.Locale locale)
        Upcase a string in a specific locale.
        Parameters:
        s - The String to convert to upper case.
        locale - The Locale to apply.
        Returns:
        The converted string.