Skip to content

Instantly share code, notes, and snippets.

@gubatron
Created December 11, 2013 04:00
Show Gist options
  • Select an option

  • Save gubatron/7904896 to your computer and use it in GitHub Desktop.

Select an option

Save gubatron/7904896 to your computer and use it in GitHub Desktop.
Miss Python's "in" keyword when coding in Java. Here's something that may help avoid long OR statements.
package com.frostwire.util;
public class Condition {
/**
* Useful to shorten long "or" boolean expressions.
* @param needle
* @param args
* @return true if needle is in any of the args.
*/
public static <T> boolean in(T needle, T... args) {
boolean in = false;
for (T t : args) {
if (t.equals(needle)) {
in = true;
break;
}
}
return in;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment