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

The option state to get the boolean from

* @param defaultValue

The default value to use if the option state is DEFAULT

* @return

The boolean value

*/ public static boolean getBooleanValue(OptionState optionState, boolean defaultValue) { return switch (optionState) { case TRUE -> true; case FALSE -> false; case DEFAULT -> defaultValue; }; } /** * Gets the corresponding option state from the given boolean * * @param value

The boolean to parse

* @return

The corresponding option state

*/ 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

The string to parse to an option state

* @return

The option state corresponding to the given string

*/ public static OptionState fromString(String string) { if (string.equalsIgnoreCase("default") || string.equalsIgnoreCase("def")) { return OptionState.DEFAULT; } else { return getFromBoolean(Boolean.parseBoolean(string)); } } }