@Test public void testParseEnum() throws Exception { assertEquals(some(Mushroom.chanterelle), parseEnum(Mushroom.flyAgaric).apply("chanterelle")); assertEquals(some(Mushroom.deathCap), parseEnum(Mushroom.flyAgaric).apply("deathCap")); assertNotEquals(some(Mushroom.kingOysterMushroom), parseEnum(Mushroom.flyAgaric).apply("flyAgaric")); assertEquals(none(), parseEnum(Mushroom.flyAgaric).apply("pilz")); }
public static <A extends Enum> Function<String, Option<A>> parseEnum(final A e) { return new Function<String, Option<A>>() { @Override public Option<A> apply(String s) { try { return some((A) Enum.valueOf(e.getClass(), s)); } catch (Exception ex) { return none(); } } }; }
EnumSupport { public static <A extends Enum> Function<String, Option<A>> parseEnum(final A e) { return new Function<String, Option<A>>() { @Override public Option<A> apply(String s) { try { return some((A) Enum.valueOf(e.getClass(), s)); } catch (Exception ex) { return none(); } } }; } }
EnumSupport { public static <A extends Enum> Function<String, Option<A>> parseEnum(final A e) { return new Function<String, Option<A>>() { @Override public Option<A> apply(String s) { try { return some((A) Enum.valueOf(e.getClass(), s)); } catch (Exception ex) { return none(); } } }; } private  EnumSupport(); }
EnumSupport { public static <A extends Enum> Function<String, Option<A>> parseEnum(final A e) { return new Function<String, Option<A>>() { @Override public Option<A> apply(String s) { try { return some((A) Enum.valueOf(e.getClass(), s)); } catch (Exception ex) { return none(); } } }; } private  EnumSupport(); @SuppressWarnings("unchecked") static E fromString(Class<E> enumClass, String value); static Function<String, Option<A>> parseEnum(final A e); }
EnumSupport { public static <A extends Enum> Function<String, Option<A>> parseEnum(final A e) { return new Function<String, Option<A>>() { @Override public Option<A> apply(String s) { try { return some((A) Enum.valueOf(e.getClass(), s)); } catch (Exception ex) { return none(); } } }; } private  EnumSupport(); @SuppressWarnings("unchecked") static E fromString(Class<E> enumClass, String value); static Function<String, Option<A>> parseEnum(final A e);  }