public class JUtil
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
EMPTY_STRING
Empty string, literally ""
|
| Constructor and Description |
|---|
JUtil() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
contains(java.lang.String source,
java.lang.String searchTerm)
Does source has searchTerm in it?
|
static boolean |
containsIgnoreCase(java.lang.String source,
java.lang.String searchTerm)
Does source has searchTerm in it ignoring case?
|
static java.util.Map<java.lang.String,java.lang.String> |
emptyMapMutable()
Get empty mutable hashMap
|
static java.util.Set<java.lang.String> |
emptySetMutable()
Get empty mutable hashSet
|
static boolean |
equals(java.lang.Object a,
java.lang.Object b)
Are two strings equal?
|
static boolean |
equalsRelaxed(java.lang.Object a,
java.lang.Object b)
Are two strings equal ignoring case?
|
static java.lang.Character |
get(java.lang.CharSequence cs,
int index)
Safely get a character from CharSequence
|
static java.lang.Character |
get(java.lang.CharSequence cs,
int index,
java.lang.Character defaultValue)
Safely get a character from CharSequence
|
static <T> T |
get(java.util.List<T> list,
int index)
Safely get an item from list
|
static <T> T |
get(java.util.List<T> list,
int index,
T defaultValue)
Safely get an item from list
|
static java.lang.Character |
get(java.lang.String s,
int index)
Safely get a character from String
|
static java.lang.Character |
get(java.lang.String s,
int index,
java.lang.Character defaultValue)
Safely get a character from String
|
static <T> T |
get(T[] array,
int index)
Safely get an item from array
|
static <T> T |
get(T[] array,
int index,
T defaultValue)
Safely get an item from array
|
static java.lang.Character |
getLastItem(java.lang.CharSequence cs)
Safely get last item from charSequence
|
static java.lang.Character |
getLastItem(java.lang.CharSequence cs,
java.lang.Character defaultValue)
Safely get last item from charSequence
|
static <T> T |
getLastItem(java.util.List<T> list)
Safely get last item from list
|
static <T> T |
getLastItem(java.util.List<T> list,
T defaultValue)
Safely get an item from list
|
static java.lang.Character |
getLastItem(java.lang.String s)
Safely get last item from string
|
static java.lang.Character |
getLastItem(java.lang.String s,
java.lang.Character defaultValue)
Safely get last item from string
|
static <T> T |
getLastItem(T[] array)
Safely get last item from array
|
static <T> T |
getLastItem(T[] array,
T defaultValue)
Safely get an item from array
|
static java.lang.String |
getString(java.lang.Object o)
Get string from an object
|
static java.lang.String |
getStringSafe(java.lang.Object o)
Get string from an object
|
static boolean |
isAllEmpty(java.lang.Object... objects)
Are all the object passed is null or empty.
|
static boolean |
isAnyEmpty(java.lang.Object... objects)
Is any object passed is null or empty.
|
static boolean |
isEmpty(java.lang.CharSequence cs)
Is the CharSequence null or empty?
|
static <T> boolean |
isEmpty(java.util.Collection<T> collection)
Is the Collection null or empty?
|
static <K,V> boolean |
isEmpty(java.util.Map<K,V> m)
Is the Map null or empty?
|
static boolean |
isEmpty(java.lang.String s)
Is the String null or empty?
|
static <T> boolean |
isEmpty(T[] array)
Is the array null or empty?
|
static java.lang.String |
safeUrlEncode(java.lang.String s,
java.lang.String enc)
Safe url encode.
|
static int |
size(java.lang.CharSequence cs)
Get the size of the charSequence
|
static <T> int |
size(java.util.Collection<T> collection)
Get the size of the collection
|
static int |
size(java.lang.String s)
Get the size of the string
|
static <T> int |
size(T[] array)
Get the size of the array
|
static java.lang.String |
stringify(java.util.Collection collection)
Get string out of Collection
|
static java.lang.String |
stringify(java.util.Map map)
Get string out of Map
|
static java.lang.String |
stringify(java.lang.String message,
java.util.Collection collection)
Get string out of Collection
|
static java.lang.String |
stringify(java.lang.String message,
java.util.Map map)
Get string out of Map
|
static <T> T |
typeCast(java.lang.Object o,
java.lang.Class<T> clazz)
Integer i=typeCast(object,Integer.class);
|
public static final java.lang.String EMPTY_STRING
public static <T> T get(T[] array,
int index)
same as calling get(array,index,null)
array - The arrayindex - the index at which the item needs to be fetchedget(array,index,defaultValue)public static <T> T get(T[] array,
int index,
T defaultValue)
array - The arrayindex - the index at which the item needs to be fetcheddefaultValue - in case of array is null or index out of bound, return this valueget(array,index)public static <T> T get(java.util.List<T> list,
int index)
same as calling get(list,index,null)
list - The listindex - the index at which the item needs to be fetchedget(list,index,defaultValue)public static <T> T get(java.util.List<T> list,
int index,
T defaultValue)
list - The listindex - the index at which the item needs to be fetcheddefaultValue - in case of array is null or index out of bound, return this valueget(list,index)public static java.lang.Character get(java.lang.String s,
int index)
same as calling get(string,index,null)
s - The Stringindex - the index at which the character needs to be fetchedget(string,index,defaultValue)public static java.lang.Character get(java.lang.String s,
int index,
java.lang.Character defaultValue)
s - The Stringindex - the index at which the character needs to be fetcheddefaultValue - in case of string is null or index out of bound, return this valueget(string,index)public static java.lang.Character get(java.lang.CharSequence cs,
int index)
same as calling get(charsequence,index,null)
cs - The CharSequenceindex - the index at which the character needs to be fetchedget(charsequence,index,defaultValue)public static java.lang.Character get(java.lang.CharSequence cs,
int index,
java.lang.Character defaultValue)
cs - The CharSequenceindex - the index at which the character needs to be fetcheddefaultValue - in case of charSequence is null or index out of bound, return this valueget(charsequence,index)public static <T> T getLastItem(T[] array)
same as calling getLastItem(array,null)
array - The arraygetLastItem(array,defaultValue)public static <T> T getLastItem(T[] array,
T defaultValue)
array - The arraydefaultValue - in case of array is null or empty, return this valuegetLastItem(array)public static <T> T getLastItem(java.util.List<T> list)
same as calling getLastItem(list,null)
list - The listgetLastItem(list,defaultValue)public static <T> T getLastItem(java.util.List<T> list,
T defaultValue)
list - The listdefaultValue - in case of list is null or empty, return this valuegetLastItem(list)public static java.lang.Character getLastItem(java.lang.String s)
same as calling getLastItem(string,null)
s - The StringgetLastItem(string,defaultValue)public static java.lang.Character getLastItem(java.lang.String s,
java.lang.Character defaultValue)
s - The StringdefaultValue - in case of string is null or empty, return this valuegetLastItem(string)public static java.lang.Character getLastItem(java.lang.CharSequence cs)
same as calling getLastItem(charSequence,null)
cs - The CharSequencegetLastItem(charSequence,defaultValue)public static java.lang.Character getLastItem(java.lang.CharSequence cs,
java.lang.Character defaultValue)
cs - The CharSequencedefaultValue - in case of charSequence is null or empty, return this valuegetLastItem(charSequence,defaultValue)public static <T> boolean isEmpty(T[] array)
array - The arrayisEmpty(Collection),
isEmpty(String),
isEmpty(CharSequence),
isEmpty(Map)public static <T> boolean isEmpty(java.util.Collection<T> collection)
collection - The collectionisEmpty(Object[]),
isEmpty(String),
isEmpty(CharSequence),
isEmpty(Map)public static boolean isEmpty(java.lang.String s)
s - The stringisEmpty(Collection),
isEmpty(Object[]),
isEmpty(CharSequence),
isEmpty(Map)public static boolean isEmpty(java.lang.CharSequence cs)
cs - The CharSequenceisEmpty(Collection),
isEmpty(Object[]),
isEmpty(String),
isEmpty(Map)public static <K,V> boolean isEmpty(java.util.Map<K,V> m)
m - The mapisEmpty(Collection),
isEmpty(Object[]),
isEmpty(String),
isEmpty(CharSequence)public static <T> int size(java.util.Collection<T> collection)
collection - The collectionsize(Object[]),
size(String),
size(CharSequence)public static <T> int size(T[] array)
array - The arraysize(Collection),
size(String),
size(CharSequence)public static int size(java.lang.String s)
s - The stringsize(Collection),
size(Object[]),
size(CharSequence)public static int size(java.lang.CharSequence cs)
cs - The charSequencesize(Collection),
size(Object[]),
size(String)public static boolean equals(java.lang.Object a,
java.lang.Object b)
a - first stringb - second stringpublic static boolean equalsRelaxed(java.lang.Object a,
java.lang.Object b)
a - first stringb - second stringpublic static boolean contains(java.lang.String source,
java.lang.String searchTerm)
source - the source to be searchedsearchTerm - the term to searchpublic static boolean containsIgnoreCase(java.lang.String source,
java.lang.String searchTerm)
source - the source to be searchedsearchTerm - the term to searchpublic static <T> T typeCast(java.lang.Object o,
java.lang.Class<T> clazz)
o - Object to be castedclazz - casting typepublic static java.lang.String stringify(java.lang.String message,
java.util.Collection collection)
message - Optional prefix textcollection - The collectionpublic static java.lang.String stringify(java.util.Collection collection)
same as calling stringify(null,collection)
collection - The collectionpublic static java.lang.String stringify(java.lang.String message,
java.util.Map map)
message - Optional prefix textmap - The Mappublic static java.lang.String stringify(java.util.Map map)
same as calling stringify(null,collection)
map - The mappublic static boolean isAnyEmpty(java.lang.Object... objects)
Usage: isAnyEmpty(string1,string2,string3,string4)
Usage: isAnyEmpty(collection,map,string,charSequence,object)
objects - objects to be checkedpublic static boolean isAllEmpty(java.lang.Object... objects)
Usage: isAnyEmpty(string1,string2,string3,string4)
Usage: isAnyEmpty(collection,map,string,charSequence,object)
objects - objects to be checkedpublic static java.lang.String getString(java.lang.Object o)
o - The objectnull if object is null, otherwise a string representation of the objectpublic static java.lang.String getStringSafe(java.lang.Object o)
o - The objectpublic static java.util.Map<java.lang.String,java.lang.String> emptyMapMutable()
public static java.util.Set<java.lang.String> emptySetMutable()
public static java.lang.String safeUrlEncode(java.lang.String s,
java.lang.String enc)
x-www-form-urlencoded
format.s - String to UrlEncodeenc - The name of a supported character encoding.