Class CommonHelper


  • public final class CommonHelper
    extends java.lang.Object
    This class gathers all the utilities methods.
    Since:
    1.4.0
    Author:
    Jerome Leleu
    • Constructor Summary

      Constructors 
      Constructor Description
      CommonHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String addParameter​(java.lang.String url, java.lang.String name, java.lang.String value)
      Add a new parameter to an url.
      static boolean areEquals​(java.lang.String s1, java.lang.String s2)
      Compare two String to see if they are equals (both null is ok).
      static boolean areEqualsIgnoreCaseAndTrim​(java.lang.String s1, java.lang.String s2)
      Compare two String to see if they are equals ignoring the case and the blank spaces (both null is ok).
      static boolean areNotEquals​(java.lang.String s1, java.lang.String s2)
      Compare two String to see if they are not equals.
      static void assertNotBlank​(java.lang.String name, java.lang.String value)
      Verify that a String is not blank otherwise throw a TechnicalException.
      static void assertNotBlank​(java.lang.String name, java.lang.String value, java.lang.String msg)
      Verify that a String is not blank otherwise throw a TechnicalException.
      static void assertNotNull​(java.lang.String name, java.lang.Object obj)
      Verify that an Object is not null otherwise throw a TechnicalException.
      static void assertNull​(java.lang.String name, java.lang.Object obj)
      Verify that an Object is null otherwise throw a TechnicalException.
      static void assertTrue​(boolean value, java.lang.String message)
      Verify that a boolean is true otherwise throw a TechnicalException.
      static java.net.URI asURI​(java.lang.String s)
      Convert a string into an URI.
      static java.lang.reflect.Constructor getConstructor​(java.lang.String name)
      Get the constructor of the class.
      static boolean isBlank​(java.lang.String s)
      Return if the String is blank.
      static boolean isEmpty​(java.util.Collection<?> coll)
      Return if a collection is empty.
      static boolean isNotBlank​(java.lang.String s)
      Return if the String is not blank.
      static boolean isNotEmpty​(java.util.Collection<?> coll)
      Return if a collection is not empty.
      static java.util.Date newDate​(java.util.Date original)
      Copy a date.
      static java.lang.String randomString​(int size)
      Return a random string of a certain size.
      static java.lang.String substringAfter​(java.lang.String str, java.lang.String separator)  
      static java.lang.String substringBefore​(java.lang.String str, java.lang.String separator)  
      static java.lang.String substringBetween​(java.lang.String str, java.lang.String open, java.lang.String close)  
      static java.lang.String toNiceString​(java.lang.Class<?> clazz, java.lang.Object... args)
      Build a "nice toString" for an object.
      static java.lang.String urlEncode​(java.lang.String text)
      URL encode a text using UTF-8.
      • Methods inherited from class java.lang.Object

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

      • CommonHelper

        public CommonHelper()
    • Method Detail

      • isNotBlank

        public static boolean isNotBlank​(java.lang.String s)
        Return if the String is not blank.
        Parameters:
        s - string
        Returns:
        if the String is not blank
      • isBlank

        public static boolean isBlank​(java.lang.String s)
        Return if the String is blank.
        Parameters:
        s - string
        Returns:
        if the String is blank
      • areEquals

        public static boolean areEquals​(java.lang.String s1,
                                        java.lang.String s2)
        Compare two String to see if they are equals (both null is ok).
        Parameters:
        s1 - string
        s2 - string
        Returns:
        if two String are equals
      • areEqualsIgnoreCaseAndTrim

        public static boolean areEqualsIgnoreCaseAndTrim​(java.lang.String s1,
                                                         java.lang.String s2)
        Compare two String to see if they are equals ignoring the case and the blank spaces (both null is ok).
        Parameters:
        s1 - string
        s2 - string
        Returns:
        if two String are equals ignoring the case and the blank spaces
      • areNotEquals

        public static boolean areNotEquals​(java.lang.String s1,
                                           java.lang.String s2)
        Compare two String to see if they are not equals.
        Parameters:
        s1 - string
        s2 - string
        Returns:
        if two String are not equals
      • isEmpty

        public static boolean isEmpty​(java.util.Collection<?> coll)
        Return if a collection is empty.
        Parameters:
        coll - a collection
        Returns:
        whether it is empty
      • isNotEmpty

        public static boolean isNotEmpty​(java.util.Collection<?> coll)
        Return if a collection is not empty.
        Parameters:
        coll - a collection
        Returns:
        whether it is not empty
      • assertTrue

        public static void assertTrue​(boolean value,
                                      java.lang.String message)
        Verify that a boolean is true otherwise throw a TechnicalException.
        Parameters:
        value - the value to be checked for truth
        message - the message to include in the exception if the value is false
      • assertNotBlank

        public static void assertNotBlank​(java.lang.String name,
                                          java.lang.String value,
                                          java.lang.String msg)
        Verify that a String is not blank otherwise throw a TechnicalException.
        Parameters:
        name - name if the string
        value - value of the string
        msg - an expanatory message
      • assertNotBlank

        public static void assertNotBlank​(java.lang.String name,
                                          java.lang.String value)
        Verify that a String is not blank otherwise throw a TechnicalException.
        Parameters:
        name - name if the string
        value - value of the string
      • assertNotNull

        public static void assertNotNull​(java.lang.String name,
                                         java.lang.Object obj)
        Verify that an Object is not null otherwise throw a TechnicalException.
        Parameters:
        name - name of the object
        obj - object
      • assertNull

        public static void assertNull​(java.lang.String name,
                                      java.lang.Object obj)
        Verify that an Object is null otherwise throw a TechnicalException.
        Parameters:
        name - name of the object
        obj - object
      • addParameter

        public static java.lang.String addParameter​(java.lang.String url,
                                                    java.lang.String name,
                                                    java.lang.String value)
        Add a new parameter to an url.
        Parameters:
        url - url
        name - name of the parameter
        value - value of the parameter
        Returns:
        the new url with the parameter appended
      • urlEncode

        public static java.lang.String urlEncode​(java.lang.String text)
        URL encode a text using UTF-8.
        Parameters:
        text - text to encode
        Returns:
        the encoded text
      • toNiceString

        public static java.lang.String toNiceString​(java.lang.Class<?> clazz,
                                                    java.lang.Object... args)
        Build a "nice toString" for an object.
        Parameters:
        clazz - class
        args - arguments
        Returns:
        a "nice toString" text
      • randomString

        public static java.lang.String randomString​(int size)
        Return a random string of a certain size.
        Parameters:
        size - the size
        Returns:
        the random size
      • newDate

        public static java.util.Date newDate​(java.util.Date original)
        Copy a date.
        Parameters:
        original - original date
        Returns:
        date copy
      • asURI

        public static java.net.URI asURI​(java.lang.String s)
        Convert a string into an URI.
        Parameters:
        s - the string
        Returns:
        the URI
      • substringBetween

        public static java.lang.String substringBetween​(java.lang.String str,
                                                        java.lang.String open,
                                                        java.lang.String close)
      • substringAfter

        public static java.lang.String substringAfter​(java.lang.String str,
                                                      java.lang.String separator)
      • substringBefore

        public static java.lang.String substringBefore​(java.lang.String str,
                                                       java.lang.String separator)
      • getConstructor

        public static java.lang.reflect.Constructor getConstructor​(java.lang.String name)
                                                            throws java.lang.ClassNotFoundException,
                                                                   java.lang.NoSuchMethodException
        Get the constructor of the class.
        Parameters:
        name - the name of the class
        Returns:
        the constructor
        Throws:
        java.lang.ClassNotFoundException - class not found
        java.lang.NoSuchMethodException - method not found