Skip to content

Instantly share code, notes, and snippets.

@osmanizbat
Created March 12, 2012 10:09
Show Gist options
  • Save osmanizbat/2021027 to your computer and use it in GitHub Desktop.
Save osmanizbat/2021027 to your computer and use it in GitHub Desktop.
if(foo == null || bar == null || baz == null || qux == null){
...
}
vs.
if(ObjectUtils.anyNull(foo, bar, baz, qux)){
...
}
if(obj.equals(foo) || obj.equals(bar) || obj.equals(baz) || obj.equals(qux)){
...
}
vs.
if(ObjectUtils.equalsAny(obj, foo, bar, baz, qux)){
...
}
public class ObjectUtils {
public static boolean equalsAny(Object obj, Object... others) {
for (Object other: others) {
if (obj.equals(other))
return true;
}
return false;
}
public static boolean anyNull(Object... objects) {
for (Object o: objects) {
if (o == null)
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment