Class Strings


  • public final class Strings
    extends java.lang.Object
    Utility methods related to Strings.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Strings.StringsToJoin
      Knows how to join Strings using a given delimiter.
      static class  Strings.StringToAppend
      Knows how to append a given String to the given target, only if the target does not end with the given String to append.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Strings()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Strings.StringToAppend append​(java.lang.String toAppend)
      Appends a given String to the given target, only if the target does not end with the given String to append.
      static java.lang.String concat​(java.lang.Object... objects)
      Concatenates the given objects into a single String.
      static java.lang.String escapePercent​(java.lang.String value)
      Escape any % to %% to avoid interpreting it in String.format(String, Object...).
      private static java.lang.String escapePercentExceptWhenFollowedBy_n​(java.lang.String message)  
      static java.lang.String formatIfArgs​(java.lang.String message, java.lang.Object... args)
      Format with String.format(String, Object...) the given message if some args have been given otherwise just return the message.
      static boolean isNullOrEmpty​(java.lang.String s)
      Indicates whether the given String is null or empty.
      static Strings.StringsToJoin join​(java.lang.Iterable<?> toStringable)
      Joins the given Objects using a given delimiter.
      static Strings.StringsToJoin join​(java.lang.String... strings)
      Joins the given Strings using a given delimiter.
      static java.lang.Object quote​(java.lang.Object o)
      Returns the given object surrounded by single quotes, only if the object is a String.
      static java.lang.String quote​(java.lang.String s)
      Returns the given String surrounded by single quotes, or null if the given String is null.
      private static java.lang.String revertEscapingPercent_n​(java.lang.String value)  
      • Methods inherited from class java.lang.Object

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

      • Strings

        private Strings()
    • Method Detail

      • isNullOrEmpty

        public static boolean isNullOrEmpty​(java.lang.String s)
        Indicates whether the given String is null or empty.
        Parameters:
        s - the String to check.
        Returns:
        true if the given String is null or empty, otherwise false.
      • quote

        public static java.lang.String quote​(java.lang.String s)
        Returns the given String surrounded by single quotes, or null if the given String is null.
        Parameters:
        s - the given String.
        Returns:
        the given String surrounded by single quotes, or null if the given String is null.
      • quote

        public static java.lang.Object quote​(java.lang.Object o)
        Returns the given object surrounded by single quotes, only if the object is a String.
        Parameters:
        o - the given object.
        Returns:
        the given object surrounded by single quotes, only if the object is a String.
        See Also:
        quote(String)
      • concat

        public static java.lang.String concat​(java.lang.Object... objects)
        Concatenates the given objects into a single String. This method is more efficient than concatenating using "+", since only one StringBuilder is created.
        Parameters:
        objects - the objects to concatenate.
        Returns:
        a String containing the given objects.
      • formatIfArgs

        public static java.lang.String formatIfArgs​(java.lang.String message,
                                                    java.lang.Object... args)
        Format with String.format(String, Object...) the given message if some args have been given otherwise just return the message.
        Parameters:
        message - the string to format
        args - args used to format the message, can be null or empty
        Returns:
        the formatted string if any args were given
      • escapePercent

        public static java.lang.String escapePercent​(java.lang.String value)
        Escape any % to %% to avoid interpreting it in String.format(String, Object...).
        Parameters:
        value - the String to escape
        Returns:
        the escaped String
      • join

        public static Strings.StringsToJoin join​(java.lang.String... strings)
        Joins the given Strings using a given delimiter. The following example illustrates proper usage of this method:
         Strings.join("a", "b", "c").with("|");
        which will result in the String "a|b|c".
        Parameters:
        strings - the Strings to join.
        Returns:
        an intermediate object that takes a given delimiter and knows how to join the given Strings.
        See Also:
        Strings.StringsToJoin.with(String)
      • join

        public static Strings.StringsToJoin join​(java.lang.Iterable<?> toStringable)
        Joins the given Objects using a given delimiter. The following example illustrates proper usage of this method:
         Strings.join(new ArrayList("a", "b", "c")).with("|");
        which will result in the String "a|b|c".
        Parameters:
        toStringable - the Objects to join.
        Returns:
        an intermediate object that takes a given delimiter and knows how to join the given Objects.
        See Also:
        Strings.StringsToJoin.with(String)
      • append

        public static Strings.StringToAppend append​(java.lang.String toAppend)
        Appends a given String to the given target, only if the target does not end with the given String to append. The following example illustrates proper usage of this method:
         Strings.append("c").to("ab");
         Strings.append("c").to("abc");
        resulting in the String "abc" for both cases.
        Parameters:
        toAppend - the String to append.
        Returns:
        an intermediate object that takes the target String and knows to append the given String.
        See Also:
        Strings.StringToAppend.to(String)
      • escapePercentExceptWhenFollowedBy_n

        private static java.lang.String escapePercentExceptWhenFollowedBy_n​(java.lang.String message)
      • revertEscapingPercent_n

        private static java.lang.String revertEscapingPercent_n​(java.lang.String value)