Class FunctionUtils

java.lang.Object
dev.metaschema.core.metapath.function.FunctionUtils

public final class FunctionUtils extends Object
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 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 a INumericItem value. If the sequence is empty, then a null value is returned.
      Parameters:
      sequence - a Metapath sequence containing the value to convert
      requireSingleton - if true then a TypeMetapathException is thrown if the sequence contains more than one item
      Returns:
      the numeric item value, or null if 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 a INumericItem value.
      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 a INumericItem value.
      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.
      Use castToNumeric(IAnyAtomicItem) with null checking instead
      Gets the provided item value as a INumericItem value. If the item is null, then a null value 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

      @NonNull public static INumericItem castToNumeric(@NonNull IAnyAtomicItem item)
      Casts the provided item value to a INumericItem value.

      This method wraps INumericItem.cast(IAnyAtomicItem) and converts InvalidValueForCastFunctionException to InvalidTypeMetapathException for 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

      @Nullable public static <TYPE extends IItem> TYPE asTypeOrNull(@Nullable IItem item)
      Casts the provided item as the result type, if the item is not null.
      Type Parameters:
      TYPE - the Java type to cast to
      Parameters:
      item - the value to cast
      Returns:
      the item cast to the required type or null if the item is null
      Throws:
      ClassCastException - if the item's type is not compatible with the requested type
    • asType

      @NonNull public static <TYPE extends IItem> TYPE asType(@NonNull IItem item)
      Casts the provided item as 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

      @NonNull public static <TYPE extends IItem> ISequence<TYPE> asType(@NonNull ISequence<?> sequence)
      Casts the provided item as 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 provided item as the result type.
      Type Parameters:
      TYPE - the Java type to cast to
      Parameters:
      clazz - the Java class instance for the requested type
      item - the value to cast
      Returns:
      the item cast to the required type
      Throws:
      InvalidTypeMetapathException - if the provided item is null or 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 provided item as the result type, if the item is not null.
      Type Parameters:
      TYPE - the Java type to cast to
      Parameters:
      clazz - the Java class instance for the requested type
      item - the value to cast
      Returns:
      the item cast to the required type or null if the item is null
      Throws:
      InvalidTypeMetapathException - if the provided item is null or 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 item classes used in the set of provided items.
      Type Parameters:
      T - the class type
      Parameters:
      classes - the Metapath item classes to count
      items - the Metapath items to analyze
      Returns:
      a mapping of Metapath item class to count