Added ObjectUtil class
This commit is contained in:
parent
beb0ce754e
commit
501fbf1a5f
2 changed files with 56 additions and 0 deletions
27
src/zutil/ObjectUtil.java
Normal file
27
src/zutil/ObjectUtil.java
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package zutil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A utility class containing general object functions
|
||||
*/
|
||||
public class ObjectUtil {
|
||||
|
||||
/**
|
||||
* @return true if obj is null or empty String, List, Map
|
||||
*/
|
||||
public static boolean isEmpty(Object obj) {
|
||||
if (obj == null)
|
||||
return true;
|
||||
|
||||
if (obj instanceof Map)
|
||||
return ((Map) obj).isEmpty();
|
||||
else if (obj instanceof List)
|
||||
return ((List) obj).isEmpty();
|
||||
else if (obj instanceof CharSequence)
|
||||
return ((CharSequence) obj).length() == 0;
|
||||
|
||||
return false; // We don't know the type of class, but it is not null
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue