Last active
August 29, 2015 14:06
-
-
Save AmauryCarrade/a0015b786874c868b1ca to your computer and use it in GitHub Desktop.
getBooleanFromString
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
/** | |
* Returns a boolean from an entered string, or null if the string does not represent a boolean. | |
* | |
* "on", "yes", "y", "true" = true | |
* "off", "no", "n", "false" = false | |
* | |
* @param input the input text. | |
* @return true/false if the string is a boolean; null else. | |
*/ | |
public Boolean getBooleanFromString(String input) { | |
if(input.equalsIgnoreCase("on") || input.equalsIgnoreCase("yes") || input.equalsIgnoreCase("y") || input.equalsIgnoreCase("true")) { | |
return true; | |
} | |
else if(input.equalsIgnoreCase("off") || input.equalsIgnoreCase("no") || input.equalsIgnoreCase("n") || input.equalsIgnoreCase("false")) { | |
return false; | |
} | |
else { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment