EnumByName<T extends Enum> extension
Access enum values by name.
Extensions on a collection of enum values,intended for use on thevalues list of an enum type,which allows looking up a value by its name.
Since enum classes are expected to be relatively small,lookup ofbyName is performed by linearly iterating through the valuesand comparing their name to the provided name.If a more efficient lookup is needed, perhaps because the lookup operationhappens very often, consider building a map instead usingasNameMap:
static myEnumNameMap = MyEnum.values.asNameMap();and then use that for lookups.
- on
- Iterable<
T>
- Iterable<
- @Since.new("2.15")
Methods
- asNameMap(
)→Map< String,T> Available onIterable<
Creates a map from the names of enum values to the values.T> , provided by theEnumByName extension- byName(
Stringname)→ T Available onIterable<
Finds the enum value in this list with nameT> , provided by theEnumByName extensionname.