Class EnumFinder<E extends Enum<E>>
java.lang.Object
com.bandwidth.sdk.model.bxml.utils.EnumFinder<E>
- Type Parameters:
E
- the type of the enum
Allows for convenient finding of enums based on custom enum fields.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionFinds an enum based on aPredicate
.findOptional
(Predicate<? super E> predicate) Finds anOptional
enum based on aPredicate
.findRequired
(Predicate<? super E> predicate) Finds an enum based on aPredicate
that must match otherwise anIllegalArgumentException
will be thrown.static <T extends Enum<T>>
EnumFinder<T> Convenience method to create an enum finder with less generics mess.
-
Constructor Details
-
EnumFinder
-
-
Method Details
-
findOptional
Finds anOptional
enum based on aPredicate
.Example:
Note: Finds the first enum that matches the predicate using the order the enums are declared in.find(thing -> thing.code == code)
- Parameters:
predicate
- the predicate to match the enum against- Returns:
- the
Optional
enum matching the predicate
-
findRequired
Finds an enum based on aPredicate
that must match otherwise anIllegalArgumentException
will be thrown.- Parameters:
predicate
- the predicate to match the enum against- Returns:
- the enum matching the predicate
- Throws:
IllegalArgumentException
- thrown if predicate doesn't match- See Also:
-
find
Finds an enum based on aPredicate
.- Parameters:
predicate
- the predicate to match the enum against- Returns:
- the enum matching the predicate,
null
if no match - See Also:
-
of
Convenience method to create an enum finder with less generics mess.AnEnum anEnum = EnumFinder.of(AnEnum.class).find(e -> e.code == code).orElse(null)
- Parameters:
enumClass
- the type of the enum- Returns:
- the enum finder
-