code: public static Object findEnumConstant(Class<?> type, String constantName, boolean caseSensitive) {
          if (!type.isEnum()) {
              return null;
          }
          for (Object obj : type.getEnumConstants()) {
              String name = obj.toString();
              if ((caseSensitive && name.equals(constantName)) || (!caseSensitive && name.equalsIgnoreCase(constantName))) {
                  return obj;
              }
          }
          // otherwise, it wasn't found
          return null;
      }
docs: Finds an instance of an Enum constant on a class. Useful for safely
  getting the value of an enum constant without an exception being thrown
  like the Enum.valueOf() method causes. Also, this method optionally allows
  the caller to choose whether case matters during the search.