Java EnumSet Usage valueOfOrNull(Class enumType, String name, boolean checkCase)

Here you can find the source of valueOfOrNull(Class enumType, String name, boolean checkCase)

Description

value Of Or Null

License

Open Source License

Declaration

public static <T extends Enum<T>> T valueOfOrNull(Class<T> enumType, String name, boolean checkCase) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.EnumSet;

public class Main {
    public static <T extends Enum<T>> T valueOfOrNull(Class<T> enumType, String name, boolean checkCase) {
        if (name == null) {
            return null;
        }//from   w ww  .j a va 2  s  .  com
        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;
    }
}

Related

  1. possibilities(Class enumClass)
  2. rotateEnum(T ce, boolean backwards, EnumSet ValidOptions)
  3. setOnly(EnumSet theSet, E flag)
  4. valueOfIgnoreCase(String text, Class cls)
  5. valueOfOrNull(Class enumType, String name)