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

public class EnumFinder<E extends Enum<E>> extends Object
Allows for convenient finding of enums based on custom enum fields.
  • Constructor Details

    • EnumFinder

      public EnumFinder(Class<E> enumClass)
  • Method Details

    • findOptional

      public Optional<E> findOptional(Predicate<? super E> predicate)
      Finds an Optional enum based on a Predicate.

      Example: find(thing -> thing.code == code)

      Note: Finds the first enum that matches the predicate using the order the enums are declared in.
      Parameters:
      predicate - the predicate to match the enum against
      Returns:
      the Optional enum matching the predicate
    • findRequired

      public E findRequired(Predicate<? super E> predicate)
      Finds an enum based on a Predicate that must match otherwise an IllegalArgumentException 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

      public E find(Predicate<? super E> predicate)
      Finds an enum based on a Predicate.
      Parameters:
      predicate - the predicate to match the enum against
      Returns:
      the enum matching the predicate, null if no match
      See Also:
    • of

      public static <T extends Enum<T>> EnumFinder<T> of(Class<T> enumClass)
      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