java.lang.Object
dev.metaschema.core.metapath.function.FunctionUtils
A collection of utility functions for use in implementing Metapath functions.
This class is thread-safe as all methods are stateless and the internal constant is immutable.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <TYPE extends IItem>
TYPECasts the provideditemas the result type.Casts the provideditemas the result sequence type.static <TYPE extends IItem>
TYPEasTypeOrNull(IItem item) Casts the provideditemas the result type, if the item is notnull.static INumericItemcastToNumeric(IAnyAtomicItem item) Casts the provided item value to aINumericItemvalue.countTypes(Set<Class<? extends T>> classes, Collection<? extends T> items) Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.static <TYPE extends IItem>
TYPErequireType(Class<TYPE> clazz, IItem item) Deprecated, for removal: This API element is subject to removal in a future version.static <TYPE extends IItem>
TYPErequireTypeOrNull(Class<TYPE> clazz, IItem item) Deprecated, for removal: This API element is subject to removal in a future version.static INumericItemtoNumeric(IAnyAtomicItem item) Deprecated, for removal: This API element is subject to removal in a future version.static INumericItemDeprecated, for removal: This API element is subject to removal in a future version.static INumericItemDeprecated, for removal: This API element is subject to removal in a future version.static INumericItemDeprecated, for removal: This API element is subject to removal in a future version.
-
Method Details
-
toNumeric
@Deprecated(since="3.0.0", forRemoval=true) @Nullable public static INumericItem toNumeric(@NonNull ISequence<?> sequence, boolean requireSingleton) Deprecated, for removal: This API element is subject to removal in a future version.Gets the first item of the provided sequence as aINumericItemvalue. If the sequence is empty, then anullvalue is returned.- Parameters:
sequence- a Metapath sequence containing the value to convertrequireSingleton- iftruethen aTypeMetapathExceptionis thrown if the sequence contains more than one item- Returns:
- the numeric item value, or
nullif the result is an empty sequence - Throws:
TypeMetapathException- if the sequence contains more than one item, or the item cannot be cast to a numeric value
-
toNumeric
@Deprecated(since="3.0.0", forRemoval=true) @NonNull public static INumericItem toNumeric(@NonNull IItem item) Deprecated, for removal: This API element is subject to removal in a future version.Gets the provided item value as aINumericItemvalue.- Parameters:
item- the value to convert- Returns:
- the numeric item value
- Throws:
TypeMetapathException- if the sequence contains more than one item, or the item cannot be cast to a numeric value
-
toNumeric
@Deprecated(since="3.0.0", forRemoval=true) @NonNull public static INumericItem toNumeric(@NonNull IAnyAtomicItem item) Deprecated, for removal: This API element is subject to removal in a future version.Gets the provided item value as aINumericItemvalue.- Parameters:
item- the value to convert- Returns:
- the numeric item value
- Throws:
TypeMetapathException- if the item cannot be cast to a numeric value
-
toNumericOrNull
@Deprecated(since="3.0.0", forRemoval=true) @Nullable public static INumericItem toNumericOrNull(@Nullable IAnyAtomicItem item) Deprecated, for removal: This API element is subject to removal in a future version.UsecastToNumeric(IAnyAtomicItem)with null checking insteadGets the provided item value as aINumericItemvalue. If the item isnull, then anullvalue is returned.- Parameters:
item- the value to convert- Returns:
- the numeric item value
- Throws:
TypeMetapathException- if the item cannot be cast to a numeric value
-
castToNumeric
Casts the provided item value to aINumericItemvalue.This method wraps
INumericItem.cast(IAnyAtomicItem)and convertsInvalidValueForCastFunctionExceptiontoInvalidTypeMetapathExceptionfor consistent exception handling.- Parameters:
item- the value to cast- Returns:
- the numeric item value
- Throws:
InvalidTypeMetapathException- if the item cannot be cast to a numeric value
-
asTypeOrNull
Casts the provideditemas the result type, if the item is notnull.- Type Parameters:
TYPE- the Java type to cast to- Parameters:
item- the value to cast- Returns:
- the item cast to the required type or
nullif the item isnull - Throws:
ClassCastException- if the item's type is not compatible with the requested type
-
asType
Casts the provideditemas the result type.- Type Parameters:
TYPE- the Java type to cast to- Parameters:
item- the value to cast- Returns:
- the item cast to the required type
- Throws:
ClassCastException- if the item's type is not compatible with the requested type
-
asType
Casts the provideditemas the result sequence type.- Type Parameters:
TYPE- the Java type to cast to- Parameters:
sequence- the values to cast- Returns:
- the sequence cast to the required type
- Throws:
ClassCastException- if the sequence's type is not compatible with the requested type
-
requireType
@Deprecated(since="3.0.0", forRemoval=true) @NonNull public static <TYPE extends IItem> TYPE requireType(Class<TYPE> clazz, IItem item) Deprecated, for removal: This API element is subject to removal in a future version.Casts the provideditemas the result type.- Type Parameters:
TYPE- the Java type to cast to- Parameters:
clazz- the Java class instance for the requested typeitem- the value to cast- Returns:
- the item cast to the required type
- Throws:
InvalidTypeMetapathException- if the provided item isnullor if the item's type is not assignment compatible to the requested type
-
requireTypeOrNull
@Deprecated(since="3.0.0", forRemoval=true) @Nullable public static <TYPE extends IItem> TYPE requireTypeOrNull(Class<TYPE> clazz, @Nullable IItem item) Deprecated, for removal: This API element is subject to removal in a future version.Casts the provideditemas the result type, if the item is notnull.- Type Parameters:
TYPE- the Java type to cast to- Parameters:
clazz- the Java class instance for the requested typeitem- the value to cast- Returns:
- the item cast to the required type or
nullif the item isnull - Throws:
InvalidTypeMetapathException- if the provided item isnullor if the item's type is not assignment compatible to the requested type
-
getTypes
@Deprecated(since="3.0.0", forRemoval=true) @NonNull public static Stream<Class<?>> getTypes(@NonNull Stream<? extends IItem> items) Deprecated, for removal: This API element is subject to removal in a future version.Get a stream of item data types for the stream of items.- Parameters:
items- the Metapath items to get the data types for- Returns:
- a stream of data type classes
-
getTypes
@Deprecated(since="3.0.0", forRemoval=true) @NonNull public static <T extends IItem> List<Class<? extends T>> getTypes(@NonNull List<T> items) Deprecated, for removal: This API element is subject to removal in a future version.Generate a list of Metapath item Java type classes from a list of Metapath items.- Type Parameters:
T- the base Java types of the items- Parameters:
items- the items to get Java type class for- Returns:
- a list of corresponding Java type classes for the provided items
-
countTypes
@Deprecated(since="3.0.0", forRemoval=true) @NonNull public static <T extends IItem> Map<Class<? extends T>,Integer> countTypes(@NonNull Set<Class<? extends T>> classes, @NonNull Collection<? extends T> items) Deprecated, for removal: This API element is subject to removal in a future version.Count the occurrences of the provided data type itemclassesused in the set of provideditems.- Type Parameters:
T- the class type- Parameters:
classes- the Metapath item classes to countitems- the Metapath items to analyze- Returns:
- a mapping of Metapath item class to count
-
castToNumeric(IAnyAtomicItem)with null checking instead