Created
December 11, 2013 04:00
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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