Class EnumSupportDynamic<T,E extends EnumDynamic<T,E>>

java.lang.Object
com.sinch.sdk.core.utils.EnumSupportDynamic<T,E>
Type Parameters:
T - Value type associated to dynamic enum
E - Dynamic enum class instance

public final class EnumSupportDynamic<T,E extends EnumDynamic<T,E>> extends Object
Utility class to manage extendable enumeration set

Used to define a known set of value but enable to extend it dynamically

Typical use case: being able to send and/or receive values not yet defined at SDK version release

Since:
1.0
  • Constructor Details

    • EnumSupportDynamic

      public EnumSupportDynamic(Class<E> aClass, Function<T,E> surplusFactory, List<E> values)
      Create a new instance of managing a dynamic enum
      Parameters:
      aClass - Related class stored with dynamic enum support
      surplusFactory - Factory T function to create a new dynamic enum value
      values - Values managed/stored by dynamic enum class
      Since:
      1.0
  • Method Details

    • values

      public Stream<E> values()
      Get known values
      Returns:
      Stream of values
      Since:
      1.0
    • valueOf

      public T valueOf(E e)
      Returns the value used to create the enum
      Parameters:
      e - the enum
      Returns:
      Value associated to enum onto creation
    • valuesOf

      public List<T> valuesOf(Collection<E> values)
      Transform Collection to List
      Parameters:
      values - Collection of values to be transformed
      Returns:
      Created List
    • fromValues

      public List<E> fromValues(Collection<T> values)
      Get List of enum from Collection and create undefined Enum from the Collection if required
      Parameters:
      values - Collection of values to be used to fill returned List
      Returns:
      List of enum related to source Collection
    • from

      public E from(T value)
      Get a dynamic enum from value

      If no dynamic enum was already created with value param, a new value is created and returned

      Parameters:
      value - Value to be associated to newly create element
      Returns:
      Dynamic enum
    • compare

      public int compare(Object o1, Object o2)
      Compare two dynamic enum
      Parameters:
      o1 - the first object to compare
      o2 - the second object to compare
      Returns:
      the value 0 if o1 == o2& a value less than 0 if o1 < o2; and a value greater than 0 if o1 > o2