Enums { public static <T extends Enum<?>> Maybe<T> valueOfIgnoreCase(Class<T> type, String givenValue) { return valueOfIgnoreCase(JavaClassNames.simpleClassName(type), values(type), givenValue); }  static Function<Enum<?>,String> nameFunction(); static Function<String,T> fromStringFunction(Class<T> type); @SuppressWarnings("unchecked") static T[] values(Class<T> type); static void checkAllEnumeratedIgnoreCase(Class<? extends Enum<?>> type, String ...explicitValues); static void checkAllEnumeratedIgnoreCase(String contextMessage, Enum<?>[] enumValues, String ...explicitValues); static Maybe<T> valueOfIgnoreCase(Class<T> type, String givenValue); static Maybe<T> valueOfIgnoreCase(String contextMessage, T[] enumValues, String givenValue);  }
@Test public static void testValueOf() { Assert.assertEquals(Enums.valueOfIgnoreCase(SomeENum.class, "e_300").get(), SomeENum.E_300); Assert.assertEquals(Enums.valueOfIgnoreCase(SomeENum.class, "e_624").get(), SomeENum.E_624); Assert.assertEquals(Enums.valueOfIgnoreCase(SomeENum.class, "ALICE_THE_CAMEL").get(), SomeENum.aliceTheCamel); Assert.assertEquals(Enums.valueOfIgnoreCase(SomeENum.class, "alice_the_camel").get(), SomeENum.aliceTheCamel); Assert.assertEquals(Enums.valueOfIgnoreCase(SomeENum.class, "wordUp").get(), SomeENum.WORD_UP); Assert.assertEquals(Enums.valueOfIgnoreCase(SomeENum.class, "wordup").get(), SomeENum.WORD_UP); Assert.assertFalse(Enums.valueOfIgnoreCase(SomeENum.class, "MSG").isPresent()); Assert.assertFalse(Enums.valueOfIgnoreCase(SomeENum.class, "alice_thecamel").isPresent()); Assert.assertFalse(Enums.valueOfIgnoreCase(SomeENum.class, "_word_up").isPresent()); }