Last active
April 26, 2018 11:08
-
-
Save asflierl/84537bea60a9ed64db50653adc1a3580 to your computer and use it in GitHub Desktop.
This file contains 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
import java.util.Locale; | |
public enum EBoolA { | |
FALSE, | |
NULL, | |
TRUE; | |
public static final int fromBool(Boolean b) { | |
for (EBoolA mb : values()) { | |
StringBuilder sb = new StringBuilder(); | |
String name = sb.append(b).toString(); | |
if (mb.name().intern() == name.toUpperCase(Locale.US).intern()) { | |
return mb.ordinal() / 2; | |
} | |
} | |
throw new IllegalArgumentException("unknown boolean value: " + b); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tongue-in-cheek "answer" to https://stackoverflow.com/questions/3793650/convert-boolean-to-int-in-java