Skip to content

Instantly share code, notes, and snippets.

@carlostse
Created April 4, 2018 01:27
Show Gist options
  • Select an option

  • Save carlostse/119de051e9a4ec25ed4d1cd0fd293040 to your computer and use it in GitHub Desktop.

Select an option

Save carlostse/119de051e9a4ec25ed4d1cd0fd293040 to your computer and use it in GitHub Desktop.
/**
* Check if the object is null or empty
*
* @param obj - the test object
* @return true if the value is missing
*/
public static boolean isMissing(Object obj) {
if (obj == null) return true;
if (obj instanceof CharSequence) return (obj).toString().trim().length() < 1;
if (obj instanceof Collection) return ((Collection) obj).size() < 1;
if (obj instanceof Map) return ((Map) obj).size() < 1;
// more to come
return false; // default just check not null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment