public IndicatorStyle seenIndicatorStyle() { String value = preferences.getString("pref_seen_indicator_style", IndicatorStyle.NONE.toString()); assert value != null; return Enums.getIfPresent(IndicatorStyle.class, value).or(IndicatorStyle.NONE); }
public void testGetIfPresent() { assertEquals(Optional.of(TestEnum.CHEETO), Enums.getIfPresent(TestEnum.class, "CHEETO")); assertEquals(Optional.of(TestEnum.HONDA), Enums.getIfPresent(TestEnum.class, "HONDA")); assertEquals(Optional.of(TestEnum.POODLE), Enums.getIfPresent(TestEnum.class, "POODLE")); assertTrue(Enums.getIfPresent(TestEnum.class, "CHEETO").isPresent()); assertTrue(Enums.getIfPresent(TestEnum.class, "HONDA").isPresent()); assertTrue(Enums.getIfPresent(TestEnum.class, "POODLE").isPresent()); assertEquals(TestEnum.CHEETO, Enums.getIfPresent(TestEnum.class, "CHEETO").get()); assertEquals(TestEnum.HONDA, Enums.getIfPresent(TestEnum.class, "HONDA").get()); assertEquals(TestEnum.POODLE, Enums.getIfPresent(TestEnum.class, "POODLE").get()); }
public void testGetIfPresent_whenNoMatchingConstant() { assertEquals(Optional.absent(), Enums.getIfPresent(TestEnum.class, "WOMBAT")); }
public void testGetIfPresent_caseSensitive() { assertFalse(Enums.getIfPresent(TestEnum.class, "cHEETO").isPresent()); assertFalse(Enums.getIfPresent(TestEnum.class, "Honda").isPresent()); assertFalse(Enums.getIfPresent(TestEnum.class, "poodlE").isPresent()); }
public static CpuFamily fromValue(String v) { return Enums.getIfPresent(CpuFamily.class, v).or(UNRECOGNIZED); }