示例#1
0
  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);
  }
示例#2
0
  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());
  }
示例#3
0
 public void testGetIfPresent_whenNoMatchingConstant() {
   assertEquals(Optional.absent(), Enums.getIfPresent(TestEnum.class, "WOMBAT"));
 }
示例#4
0
 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());
 }
示例#5
0
 public static CpuFamily fromValue(String v) {
   return Enums.getIfPresent(CpuFamily.class, v).or(UNRECOGNIZED);
 }