Initial commit
This commit is contained in:
@ -0,0 +1,65 @@
|
||||
package net.knarcraft.paidsigns.property;
|
||||
|
||||
/**
|
||||
* A class representing the different available states for a paid sign option
|
||||
*/
|
||||
public enum OptionState {
|
||||
|
||||
/**
|
||||
* The option is enabled
|
||||
*/
|
||||
TRUE,
|
||||
|
||||
/**
|
||||
* The option is disabled
|
||||
*/
|
||||
FALSE,
|
||||
|
||||
/**
|
||||
* The option is the same as the default value
|
||||
*/
|
||||
DEFAULT;
|
||||
|
||||
/**
|
||||
* Gets the boolean value of the given option state if it's boolean compatible
|
||||
*
|
||||
* @param optionState <p>The option state to get the boolean from</p>
|
||||
* @return <p>The boolean value, or an illegal argument exception if called on DEFAULT</p>
|
||||
*/
|
||||
public static boolean getBooleanValue(OptionState optionState) {
|
||||
return switch (optionState) {
|
||||
case TRUE -> true;
|
||||
case FALSE -> false;
|
||||
case DEFAULT -> throw new IllegalArgumentException("No boolean value available for DEFAULT");
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the corresponding option state from the given boolean
|
||||
*
|
||||
* @param value <p>The boolean to parse</p>
|
||||
* @return <p>The corresponding option state</p>
|
||||
*/
|
||||
public static OptionState getFromBoolean(boolean value) {
|
||||
if (value) {
|
||||
return OptionState.TRUE;
|
||||
} else {
|
||||
return OptionState.FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the option state corresponding to the given string
|
||||
*
|
||||
* @param string <p>The string to parse to an option state</p>
|
||||
* @return <p>The option state corresponding to the given string</p>
|
||||
*/
|
||||
public static OptionState fromString(String string) {
|
||||
if (string.equalsIgnoreCase("default") || string.equalsIgnoreCase("def")) {
|
||||
return OptionState.DEFAULT;
|
||||
} else {
|
||||
return getFromBoolean(Boolean.parseBoolean(string));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user