Package org.pac4j.core.util
Class CommonHelper
java.lang.Object
org.pac4j.core.util.CommonHelper
This class gathers all the utilities methods.
- Since:
- 1.4.0
- Author:
- Jerome Leleu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringaddParameter(String url, String name, String value) Add a new parameter to an url.static booleanCompare two String to see if they are equals (both null is ok).static booleanareEqualsIgnoreCaseAndTrim(String s1, String s2) Compare two String to see if they are equals ignoring the case and the blank spaces (both null is ok).static booleanareNotEquals(String s1, String s2) Compare two String to see if they are not equals.static voidassertNotBlank(String name, String value) Verify that a String is not blank otherwise throw aTechnicalException.static voidassertNotBlank(String name, String value, String msg) Verify that a String is not blank otherwise throw aTechnicalException.static voidassertNotNull(String name, Object obj) Verify that an Object is notnullotherwise throw aTechnicalException.static voidassertNull(String name, Object obj) Verify that an Object isnullotherwise throw aTechnicalException.static voidassertTrue(boolean value, String message) Verify that a boolean is true otherwise throw aTechnicalException.static URIConvert a string into an URI.static ConstructorgetConstructor(String name) Get the constructor of the class.static Stringstatic booleanReturn if the String is blank.static booleanisEmpty(Collection<?> coll) Return if a collection is empty.static booleanisNotBlank(String s) Return if the String is not blank.static booleanisNotEmpty(Collection<?> coll) Return if a collection is not empty.static DateCopy a date.static StringrandomString(int size) Return a random string of a certain size.static StringsubstringAfter(String str, String separator) static StringsubstringBefore(String str, String separator) static StringsubstringBetween(String str, String open, String close) static StringtoNiceString(Class<?> clazz, Object... args) Build a "nice toString" for an object.static StringURL encode a text using UTF-8.
-
Constructor Details
-
CommonHelper
public CommonHelper()
-
-
Method Details
-
isNotBlank
Return if the String is not blank.- Parameters:
s- string- Returns:
- if the String is not blank
-
isBlank
Return if the String is blank.- Parameters:
s- string- Returns:
- if the String is blank
-
areEquals
Compare two String to see if they are equals (both null is ok).- Parameters:
s1- strings2- string- Returns:
- if two String are equals
-
areEqualsIgnoreCaseAndTrim
Compare two String to see if they are equals ignoring the case and the blank spaces (both null is ok).- Parameters:
s1- strings2- string- Returns:
- if two String are equals ignoring the case and the blank spaces
-
areNotEquals
Compare two String to see if they are not equals.- Parameters:
s1- strings2- string- Returns:
- if two String are not equals
-
isEmpty
Return if a collection is empty.- Parameters:
coll- a collection- Returns:
- whether it is empty
-
isNotEmpty
Return if a collection is not empty.- Parameters:
coll- a collection- Returns:
- whether it is not empty
-
assertTrue
Verify that a boolean is true otherwise throw aTechnicalException.- Parameters:
value- the value to be checked for truthmessage- the message to include in the exception if the value is false
-
assertNotBlank
Verify that a String is not blank otherwise throw aTechnicalException.- Parameters:
name- name if the stringvalue- value of the stringmsg- an expanatory message
-
assertNotBlank
Verify that a String is not blank otherwise throw aTechnicalException.- Parameters:
name- name if the stringvalue- value of the string
-
assertNotNull
Verify that an Object is notnullotherwise throw aTechnicalException.- Parameters:
name- name of the objectobj- object
-
assertNull
Verify that an Object isnullotherwise throw aTechnicalException.- Parameters:
name- name of the objectobj- object
-
addParameter
Add a new parameter to an url.- Parameters:
url- urlname- name of the parametervalue- value of the parameter- Returns:
- the new url with the parameter appended
-
urlEncode
URL encode a text using UTF-8.- Parameters:
text- text to encode- Returns:
- the encoded text
-
toNiceString
Build a "nice toString" for an object.- Parameters:
clazz- classargs- arguments- Returns:
- a "nice toString" text
-
randomString
Return a random string of a certain size.- Parameters:
size- the size- Returns:
- the random size
-
newDate
Copy a date.- Parameters:
original- original date- Returns:
- date copy
-
asURI
Convert a string into an URI.- Parameters:
s- the string- Returns:
- the URI
-
substringBetween
-
substringAfter
-
substringBefore
-
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 foundNoSuchMethodException- method not found
-
ifBlank
-