Class Strings


  • public class Strings
    extends Object
    Utility class to handle String common methods
    Since:
    3.7.0
    • Method Detail

      • isEmpty

        public static boolean isEmpty​(String string)
        Returns true if the given string is null or is the empty string.
        Parameters:
        string - a string reference to check
        Returns:
        true if the string is null or is the empty string
      • nonEmpty

        public static boolean nonEmpty​(String string)
        Returns true if the given string is nor null nor is the empty string.
        Parameters:
        string - a string reference to check
        Returns:
        true if the string is not null nor is the empty string
      • requireNonEmpty

        public static String requireNonEmpty​(String string)
        Checks that the specified string is not null nor the empty string. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:
         public Foo(String bar) {
             this.bar = Strings.requireNonEmpty(bar);
         }
         
        Parameters:
        string - the string to check for nullity and emptiness
        Returns:
        string if not null nor empty
        Throws:
        NullPointerException - if string is null or the empty string
      • requireNonEmpty

        public static String requireNonEmpty​(String string,
                                             String message)
        Checks that the specified string is not null nor the empty string and throws a customized NullPointerException if it is. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:
         public Foo(String bar) {
             this.bar = Strings.requireNonEmpty(bar, "bar must not be null nor empty");
         }
         
        Parameters:
        string - the string to check for nullity and emptiness
        message - detail message to be used in the event that a NullPointerException is thrown
        Returns:
        string if not null nor empty
        Throws:
        NullPointerException - if string is null or the empty string