Skip to content

Instantly share code, notes, and snippets.

@muller
Created June 4, 2015 09:09
Show Gist options
  • Save muller/72353afceca73b1d84cb to your computer and use it in GitHub Desktop.
Save muller/72353afceca73b1d84cb to your computer and use it in GitHub Desktop.
import java.util.BitSet;
import java.util.HashMap;
public class BooDecisions {
public static void main(String[] args) {
System.out.println(getType(true, false, false));
System.out.println(getType(false, true, false));
System.out.println(getType(false, true, true));
BitSet x = bitSet(true, false, false);
BitSet y = bitSet(false, true, false);
BitSet z = bitSet(false, true, true);
HashMap<BitSet, Type> decisions = new HashMap<>();
decisions.put(x, Type.X);
decisions.put(y, Type.Y);
decisions.put(z, Type.Z);
System.out.println(decisions.get(x));
System.out.println(decisions.get(y));
System.out.println(decisions.get(z));
}
enum Type {
X, Y, Z
}
private static Type getType(boolean condition1, boolean condition2, boolean condition3) {
if (condition1) {
return Type.X;
} else {
if (condition2) {
return Type.Z;
} else if (condition3) {
return Type.Y;
}
}
return null;
}
static BitSet bitSet(boolean... booleans) {
BitSet bitSet = new BitSet(booleans.length);
for (int i = 0; i < booleans.length; i++) {
bitSet.set(i, booleans[i]);
}
return bitSet;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment