Class EnumUtil

java.lang.Object
cz.cvut.kbss.jsonld.common.EnumUtil

public class EnumUtil extends Object
Utilities for mapping enum constants.
  • Constructor Details

    • EnumUtil

      public EnumUtil()
  • Method Details

    • resolveMappedIndividual

      public static String resolveMappedIndividual(Enum<?> value)
      Resolves an individual mapped by the specified enum constant.

      This method looks for the value of the Individual annotation.

      Parameters:
      value - Value to map to individual
      Returns:
      Matching individual identifier
      Throws:
      InvalidEnumMappingException - When no matching individual is found
    • findMatchingConstant

      public static <T, E extends Enum<?>> Optional<T> findMatchingConstant(Class<E> enumType, BiPredicate<E,String> filter, BiFunction<E,String,T> mapper)
      Finds an enum constant matching the specified filtering predicate and transforms it using the specified mapper.

      Note that the enum constants are also filtered so that only those annotated with Individual are accepted.

      Type Parameters:
      T - Target type
      E - Enum type
      Parameters:
      enumType - Enum class
      filter - BiFilter to apply to the processed enum constants and their individual IRIs
      mapper - BiFunction mapping enum constant and its individual IRI to the required target type
      Returns:
      Matching enum constant transformed according to the specified mapper. Empty Optional if no constant of the specified enum type matches the filter predicate