/** * Looks up an instance by name. * <p> * This finds the instance matching the specified name. * Instances may have alternate names (aliases), thus the returned instance * may have a name other than that requested. * * @param name the enum name to return * @return the named enum * @throws IllegalArgumentException if the name is not found */ public T lookup(String name) { return find(name) .orElseThrow(() -> new IllegalArgumentException(type.getSimpleName() + " name not found: " + name)); }
public void test_lookup() { assertEquals(UberNamed.of("Standard"), SampleNameds.STANDARD); assertEquals(UberNamed.of("More"), MoreSampleNameds.MORE); CombinedExtendedEnum<UberNamed> combined = CombinedExtendedEnum.of(UberNamed.class); assertEquals(combined.find("Rubbish"), Optional.empty()); assertThrows(IllegalArgumentException.class, () -> combined.lookup("Rubbish")); assertEquals(combined.toString(), "CombinedExtendedEnum[UberNamed]"); }