Java Utililty Methods EnumSet Usage

List of utility methods to do EnumSet Usage

Description

The list of methods to do EnumSet Usage are organized into topic(s).

Method

TnextEnum(T ce)
next Enum
EnumSet valList = EnumSet.allOf(ce.getClass());
int pLoc = ce.ordinal() + 1;
if (pLoc >= valList.size()) {
    pLoc = 0;
if (pLoc < 0 || pLoc >= valList.size()) {
    pLoc = 0;
int pos = 0;
for (Object g : valList) {
    if (pos == pLoc) {
        return (T) g;
    pos++;
return null;
Iterablepossibilities(Class enumClass)
possibilities
EnumSet<ENUM> values = EnumSet.allOf(enumClass);
List<String> result = new ArrayList<>(values.size());
for (ENUM value : values) {
    result.add(value.toString());
return result;
TrotateEnum(T ce, boolean backwards, EnumSet ValidOptions)
rotate Enum
do {
    if (backwards) {
        ce = prevEnum(ce);
    } else {
        ce = nextEnum(ce);
} while (!ValidOptions.contains(ce));
return ce;
...
EnumSetsetOnly(EnumSet theSet, E flag)
set Only
theSet.clear();
theSet.add(flag);
return theSet;
TvalueOfIgnoreCase(String text, Class cls)
find enum value ignoring case
T result = null;
for (T item : EnumSet.allOf(cls)) {
    if (item.name().equalsIgnoreCase(text)) {
        result = item;
        break;
return result;
...
TvalueOfOrNull(Class enumType, String name)
value Of Or Null
if (name == null)
    return null;
for (T enumValue : EnumSet.allOf(enumType)) {
    if (enumValue.toString().equals(name))
        return enumValue;
return null;
TvalueOfOrNull(Class enumType, String name, boolean checkCase)
value Of Or Null
if (name == null) {
    return null;
for (T enumValue : EnumSet.allOf(enumType)) {
    if (checkCase) {
        if (enumValue.toString().equals(name)) {
            return enumValue;
    } else {
        if (enumValue.toString().equalsIgnoreCase(name)) {
            return enumValue;
return null;