public final class CommonHelper extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
CLASSPATH_PREFIX |
protected static String |
FILE_PREFIX |
static String |
INVALID_PATH_MESSAGE |
static String |
RESOURCE_PREFIX |
| Constructor and Description |
|---|
CommonHelper() |
| Modifier and Type | Method and Description |
|---|---|
static String |
addParameter(String url,
String name,
String value)
Add a new parameter to an url.
|
static boolean |
areEquals(String s1,
String s2)
Compare two String to see if they are equals (both null is ok).
|
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).
|
static boolean |
areNotEquals(String s1,
String s2)
Compare two String to see if they are not equals.
|
static void |
assertNotBlank(String name,
String value)
Verify that a String is not blank otherwise throw a
TechnicalException. |
static void |
assertNotNull(String name,
Object obj)
Verify that an Object is not
null otherwise throw a TechnicalException. |
static void |
assertNull(String name,
Object obj)
Verify that an Object is
null otherwise throw a TechnicalException. |
static void |
assertTrue(boolean value,
String message)
Verify that a boolean is true otherwise throw a
TechnicalException. |
protected static String |
extractPrefix(String name)
Extract the prefix of the name.
|
static InputStream |
getInputStreamFromName(String name)
Returns an
InputStream from given name depending on its format:
- loads from the classloader of this class if name starts with "resource:" (add a slash a the beginning if absent)
- loads from the classloader of the current thread if name starts with "classpath:"
- loads from the given url if name starts with "http:" or "https:"
- loads as FileInputStream otherwise |
static Resource |
getResource(String filePath) |
static boolean |
isBlank(String s)
Return if the String is blank.
|
static boolean |
isEmpty(Collection<?> coll)
Return if a collection is empty.
|
static boolean |
isNotBlank(String s)
Return if the String is not blank.
|
static boolean |
isNotEmpty(Collection<?> coll)
Return if a collection is not empty.
|
static Date |
newDate(Date original)
Copy a date.
|
static String |
randomString(int size)
Return a random string of a certain size.
|
protected static String |
startWithSlash(String path)
Add a slash at the beginning of a path if missing.
|
static String |
substringAfter(String str,
String separator) |
static String |
substringBefore(String str,
String separator) |
static String |
substringBetween(String str,
String open,
String close) |
static String |
toString(Class<?> clazz,
Object... args)
Build a normalized "toString" text for an object.
|
static String |
urlEncode(String text)
URL encode a text using UTF-8.
|
public static final String RESOURCE_PREFIX
public static final String CLASSPATH_PREFIX
protected static final String FILE_PREFIX
public static final String INVALID_PATH_MESSAGE
public static boolean isNotBlank(String s)
s - stringpublic static boolean isBlank(String s)
s - stringpublic static boolean areEquals(String s1, String s2)
s1 - strings2 - stringpublic static boolean areEqualsIgnoreCaseAndTrim(String s1, String s2)
s1 - strings2 - stringpublic static boolean areNotEquals(String s1, String s2)
s1 - strings2 - stringpublic static boolean isEmpty(Collection<?> coll)
coll - a collectionpublic static boolean isNotEmpty(Collection<?> coll)
coll - a collectionpublic static void assertTrue(boolean value,
String message)
TechnicalException.value - the value to be checked for truthmessage - the message to include in the exception if the value is falsepublic static void assertNotBlank(String name, String value)
TechnicalException.name - name if the stringvalue - value of the stringpublic static void assertNotNull(String name, Object obj)
null otherwise throw a TechnicalException.name - name of the objectobj - objectpublic static void assertNull(String name, Object obj)
null otherwise throw a TechnicalException.name - name of the objectobj - objectpublic static String addParameter(String url, String name, String value)
url - urlname - name of the parametervalue - value of the parameterpublic static String urlEncode(String text)
text - text to encodepublic static String toString(Class<?> clazz, Object... args)
clazz - classargs - argumentsprotected static String extractPrefix(String name)
name - the nameprotected static String startWithSlash(String path)
path - the pathpublic static InputStream getInputStreamFromName(String name)
InputStream from given name depending on its format:
- loads from the classloader of this class if name starts with "resource:" (add a slash a the beginning if absent)
- loads from the classloader of the current thread if name starts with "classpath:"
- loads from the given url if name starts with "http:" or "https:"
- loads as FileInputStream otherwise
Caller is responsible for closing inputstream
name - name of the resourcepublic static String randomString(int size)
size - the sizepublic static Date newDate(Date original)
original - original dateCopyright © 2017. All Rights Reserved.