Package cz.cvut.kbss.jsonld.common
Class EnumUtil
java.lang.Object
cz.cvut.kbss.jsonld.common.EnumUtil
Utilities for mapping enum constants.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfindMatchingConstant
(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.static String
resolveMappedIndividual
(Enum<?> value) Resolves an individual mapped by the specified enum constant.
-
Constructor Details
-
EnumUtil
public EnumUtil()
-
-
Method Details
-
resolveMappedIndividual
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 typeE
- Enum type- Parameters:
enumType
- Enum classfilter
- BiFilter to apply to the processed enum constants and their individual IRIsmapper
- 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
-