Java EnumSet Usage valueOfIgnoreCase(String text, Class cls)

Here you can find the source of valueOfIgnoreCase(String text, Class cls)

Description

find enum value ignoring case

License

Open Source License

Parameter

Parameter Description
text enum value name
cls enum class name

Return

enum found (null if not found)

Declaration

public static <T extends Enum<T>> T valueOfIgnoreCase(String text, Class<T> cls) 

Method Source Code


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

import java.util.EnumSet;

public class Main {
    /**//from   w ww  .  j  a va  2  s .c  o m
     * find enum value ignoring case
     * 
     * @param text enum value name
     * @param cls enum class name
     * @return enum found (null if not found)
     */
    public static <T extends Enum<T>> T valueOfIgnoreCase(String text, Class<T> cls) {
        T result = null;
        for (T item : EnumSet.allOf(cls)) {
            if (item.name().equalsIgnoreCase(text)) {
                result = item;
                break;
            }
        }
        return result;
    }
}

Related

  1. nativeLoadEnumDefaultValues(Class enumType)
  2. nextEnum(T ce)
  3. possibilities(Class enumClass)
  4. rotateEnum(T ce, boolean backwards, EnumSet ValidOptions)
  5. setOnly(EnumSet theSet, E flag)
  6. valueOfOrNull(Class enumType, String name)
  7. valueOfOrNull(Class enumType, String name, boolean checkCase)