Module de.carne
Package de.carne.util

Class Strings


  • public final class Strings
    extends java.lang.Object
    Utility class providing String related functions.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ELLIPSIS
      Ellipsis string.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String decode​(java.lang.CharSequence chars)
      Decodes a CharSequence previously encoded via encode(CharSequence).
      static java.lang.String encode​(java.lang.CharSequence chars)
      Encodes a CharSequence to a pure ASCII representation by quoting non printable characters.
      static java.lang.StringBuilder encode​(java.lang.StringBuilder buffer, java.lang.CharSequence chars)
      Encodes a CharSequence to a pure ASCII representation by quoting non printable characters.
      static java.lang.String encodeHtml​(java.lang.CharSequence chars)
      Encodes a CharSequence to a HTML conform representation by quoting special characters.
      static java.lang.StringBuilder encodeHtml​(java.lang.StringBuilder buffer, java.lang.CharSequence chars)
      Encodes a CharSequence to a HTML conform representation by quoting special characters.
      static boolean isEmpty​(@Nullable java.lang.String s)
      Checks whether a String is empty.
      static java.lang.String join​(java.lang.Iterable<?> objects, java.lang.String delim)
      Joins the String representation of multiple Objects into a single String.
      static java.lang.String join​(java.lang.Iterable<?> objects, java.lang.String delim, int limit)
      Joins the String representation of multiple Objects into a single String.
      static java.lang.String join​(java.lang.Iterable<?> objects, java.lang.String delim, int limit, java.lang.String ellipsis)
      Joins the String representation of multiple Objects into a single String.
      static java.lang.String join​(java.lang.Object[] objects, java.lang.String delim)
      Joins the String representation of multiple Objects into a single String.
      static java.lang.String join​(java.lang.Object[] objects, java.lang.String delim, int limit)
      Joins the String representation of multiple Objects into a single String.
      static java.lang.String join​(java.lang.Object[] objects, java.lang.String delim, int limit, java.lang.String ellipsis)
      Joins the String representation of multiple Objects into a single String.
      static boolean notEmpty​(@Nullable java.lang.String s)
      Checks whether a String is not empty.
      static java.lang.String safe​(@Nullable java.lang.String s)
      Makes sure a String is not null.
      static java.lang.String safeTrim​(@Nullable java.lang.String s)
      Makes sure a String is not null and trimmed.
      static @NonNull java.lang.String[] split​(java.lang.String s, char delim, boolean all)
      Splits a String according to a given delimiter.
      static @Nullable java.lang.String trim​(@Nullable java.lang.String s)
      Makes sure a String is either null or trimmed.
      static java.lang.String valueOf​(@Nullable java.lang.Object o)
      Gets the string representation of the submitted object and never returns null.
      • Methods inherited from class java.lang.Object

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

      • ELLIPSIS

        public static final java.lang.String ELLIPSIS
        Ellipsis string.
    • Method Detail

      • isEmpty

        public static boolean isEmpty​(@Nullable java.lang.String s)
        Checks whether a String is empty.

        A String is considered empty if it is either null or of length 0.

        Parameters:
        s - the String to check.
        Returns:
        true if the string is empty.
      • notEmpty

        public static boolean notEmpty​(@Nullable java.lang.String s)
        Checks whether a String is not empty.

        A String is considered empty if it is either null or of length 0.

        Parameters:
        s - the String to check.
        Returns:
        true if the string is not empty.
      • valueOf

        public static java.lang.String valueOf​(@Nullable java.lang.Object o)
        Gets the string representation of the submitted object and never returns null.
        Parameters:
        o - the object to get the string representation of.
        Returns:
        the string representation of the submitted object (never null).
      • safe

        public static java.lang.String safe​(@Nullable java.lang.String s)
        Makes sure a String is not null.
        Parameters:
        s - the String to check.
        Returns:
        the submitted String or "" if null was submitted.
      • safeTrim

        public static java.lang.String safeTrim​(@Nullable java.lang.String s)
        Makes sure a String is not null and trimmed.
        Parameters:
        s - the String to trim.
        Returns:
        the submitted String in trimmed form or "" if null was submitted.
      • trim

        public static @Nullable java.lang.String trim​(@Nullable java.lang.String s)
        Makes sure a String is either null or trimmed.
        Parameters:
        s - the String to trim.
        Returns:
        the submitted String in trimmed form or null if null was submitted.
      • split

        public static @NonNull java.lang.String[] split​(java.lang.String s,
                                                        char delim,
                                                        boolean all)
        Splits a String according to a given delimiter.
        Parameters:
        s - the String to split.
        delim - the delimiter character to split at.
        all - whether to split at all occurrences of the delimiter character (true) or only at the first one (false).
        Returns:
        the splitted sub-strings. The actual number of sub-strings depends on the actual occurrences of the delimiter character as well as the all flag.
      • join

        public static java.lang.String join​(java.lang.Object[] objects,
                                            java.lang.String delim)
        Joins the String representation of multiple Objects into a single String.

        The Object.toString() is used to retrieve the Objects' String representation.

        Parameters:
        objects - the Objectss to join.
        delim - the delimiter to use for joining.
        Returns:
        the joined String.
      • join

        public static java.lang.String join​(java.lang.Iterable<?> objects,
                                            java.lang.String delim)
        Joins the String representation of multiple Objects into a single String.

        The Object.toString() is used to retrieve the Objects' String representation.

        Parameters:
        objects - the Objectss to join.
        delim - the delimiter to use for joining.
        Returns:
        the joined String.
      • join

        public static java.lang.String join​(java.lang.Object[] objects,
                                            java.lang.String delim,
                                            int limit)
        Joins the String representation of multiple Objects into a single String.

        The Object.toString() is used to retrieve the Objects' String representation.

        Parameters:
        objects - the Strings to join.
        delim - the delimiter to use for joining.
        limit - the maximum length of the joined String.
        Returns:
        the joined String.
      • join

        public static java.lang.String join​(java.lang.Iterable<?> objects,
                                            java.lang.String delim,
                                            int limit)
        Joins the String representation of multiple Objects into a single String.

        The Object.toString() is used to retrieve the Objects' String representation.

        Parameters:
        objects - the Strings to join.
        delim - the delimiter to use for joining.
        limit - the maximum length of the joined String.
        Returns:
        the joined String.
      • join

        public static java.lang.String join​(java.lang.Object[] objects,
                                            java.lang.String delim,
                                            int limit,
                                            java.lang.String ellipsis)
        Joins the String representation of multiple Objects into a single String.

        The Object.toString() is used to retrieve the Objects' String representation.

        Parameters:
        objects - the Objectss to join.
        delim - the delimiter to use for joining.
        limit - the maximum length of the joined String.
        ellipsis - the ellipsis to place at the end of the joined string in case limit is reached.
        Returns:
        the joined String.
      • join

        public static java.lang.String join​(java.lang.Iterable<?> objects,
                                            java.lang.String delim,
                                            int limit,
                                            java.lang.String ellipsis)
        Joins the String representation of multiple Objects into a single String.

        The Object.toString() is used to retrieve the Objects' String representation.

        Parameters:
        objects - the Objectss to join.
        delim - the delimiter to use for joining.
        limit - the maximum length of the joined String.
        ellipsis - the ellipsis to place at the end of the joined string in case limit is reached.
        Returns:
        the joined String.
      • encode

        public static java.lang.String encode​(java.lang.CharSequence chars)
        Encodes a CharSequence to a pure ASCII representation by quoting non printable characters.
        Parameters:
        chars - the CharSequence to encode.
        Returns:
        the encoded characters.
      • encode

        public static java.lang.StringBuilder encode​(java.lang.StringBuilder buffer,
                                                     java.lang.CharSequence chars)
        Encodes a CharSequence to a pure ASCII representation by quoting non printable characters.
        Parameters:
        buffer - the StringBuilder to encode into.
        chars - the CharSequence to encode.
        Returns:
        the encoded characters.
      • decode

        public static java.lang.String decode​(java.lang.CharSequence chars)
        Decodes a CharSequence previously encoded via encode(CharSequence).
        Parameters:
        chars - the CharSequence to decode.
        Returns:
        the decoded characters.
      • encodeHtml

        public static java.lang.String encodeHtml​(java.lang.CharSequence chars)
        Encodes a CharSequence to a HTML conform representation by quoting special characters.
        Parameters:
        chars - the CharSequence to encode.
        Returns:
        the encoded characters.
      • encodeHtml

        public static java.lang.StringBuilder encodeHtml​(java.lang.StringBuilder buffer,
                                                         java.lang.CharSequence chars)
        Encodes a CharSequence to a HTML conform representation by quoting special characters.
        Parameters:
        buffer - the StringBuilder to encode into.
        chars - the CharSequence to encode.
        Returns:
        the encoded characters.