/** * Retrieves {@link #enumValues}. * * @return list of possible enum values for this YoEnum * @throws UnsupportedOperationException if this YoEnum is not backed by a Class for enumType */ public T[] getEnumValues() { checkIfBackedByEnum(); return enumValues; }
/** * Retrieve the enum value of this YoEnum. * * @return this YoEnum's internal enum value * @throws UnsupportedOperationException if this YoEnum is not backed by a Class for enumType */ public T getEnumValue() { checkIfBackedByEnum(); return valueOrdinal == NULL_VALUE ? null : enumValues[valueOrdinal]; }
/** * Retrieves this YoEnum's enumType if it is backed by an enum. * * @return enumType * @throws UnsupportedOperationException from {@link #checkIfBackedByEnum()} */ public Class<T> getEnumType() { checkIfBackedByEnum(); return enumType; }
/** * Check if the value contained by this variable is equal to the given enum. * * @param value Enum to be compared * @return boolean if the given enum value and this YoEnum's value are the same, or both null * @throws UnsupportedOperationException from {@link #checkIfBackedByEnum()} */ public boolean valueEquals(T value) { checkIfBackedByEnum(); if (valueOrdinal == NULL_VALUE) return value == null; return (value.ordinal() == valueOrdinal); }
/** * Sets the YoEnum to the given enum. * * @param enumValue enum to set this YoEnum's internal enum state to * @param notifyListeners boolean determining whether or not to call {@link #notifyVariableChangedListeners()} * @return boolean if given value is valid and YoEnum is set or the same * @throws RuntimeException if enumValue is null and null values are disallowed for this YoEnum * @throws RuntimeException if enumValue ordinal falls out of allowed range for this YoEnum */ public boolean set(T enumValue, boolean notifyListeners) { checkIfBackedByEnum(); if (!allowNullValue && (enumValue == null)) { throw new RuntimeException( "Setting YoEnum " + getName() + " to null. Must set allowNullValue to true in the constructor if you ever want to set it to null."); } return set(enumValue == null ? NULL_VALUE : enumValue.ordinal(), notifyListeners); }