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

* @return

The boolean value, or an illegal argument exception if called on DEFAULT

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

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)); } } }