Class CommonHelper

java.lang.Object
org.pac4j.core.util.CommonHelper

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

    • CommonHelper

      public CommonHelper()
  • Method Details

    • isNotBlank

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

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

      public static boolean areEquals(String s1, 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(String s1, 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(String s1, 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(Collection<?> coll)
      Return if a collection is empty.
      Parameters:
      coll - a collection
      Returns:
      whether it is empty
    • isNotEmpty

      public static boolean isNotEmpty(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, 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(String name, String value, 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(String name, 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(String name, 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(String name, Object obj)
      Verify that an Object is null otherwise throw a TechnicalException.
      Parameters:
      name - name of the object
      obj - object
    • addParameter

      public static String addParameter(String url, String name, 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 String urlEncode(String text)
      URL encode a text using UTF-8.
      Parameters:
      text - text to encode
      Returns:
      the encoded text
    • randomString

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

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

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

      public static String substringBetween(String str, String open, String close)

      substringBetween.

      Parameters:
      str - a String object
      open - a String object
      close - a String object
      Returns:
      a String object
    • substringAfter

      public static String substringAfter(String str, String separator)

      substringAfter.

      Parameters:
      str - a String object
      separator - a String object
      Returns:
      a String object
    • substringBefore

      public static String substringBefore(String str, String separator)

      substringBefore.

      Parameters:
      str - a String object
      separator - a String object
      Returns:
      a String object
    • getConstructor

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

      public static String ifBlank(String value, String defaultValue)

      ifBlank.

      Parameters:
      value - a String object
      defaultValue - a String object
      Returns:
      a String object