Class FunctionUtils

    • Method Detail

      • asInteger

        public static int asInteger​(@NonNull
                                    INumericItem value)
        Converts a INumericItem value to an integer value.
        Parameters:
        value - the value to convert
        Returns:
        the integer value
        Throws:
        ArithmeticException - if the provided value will not exactly fit in an int
      • asInteger

        public static int asInteger​(@NonNull
                                    BigInteger value)
        Converts a BigInteger value to an integer value.
        Parameters:
        value - the value to convert
        Returns:
        the integer value
        Throws:
        ArithmeticException - if the provided value will not exactly fit in an int
      • asLong

        public static long asLong​(@NonNull
                                  INumericItem value)
        Converts a INumericItem value to a long value.
        Parameters:
        value - the value to convert
        Returns:
        the long value
        Throws:
        ArithmeticException - if the provided value will not exactly fit in an long
      • asLong

        public static long asLong​(@NonNull
                                  BigInteger value)
        Converts a BigInteger value to a long value.
        Parameters:
        value - the value to convert
        Returns:
        the long value
        Throws:
        ArithmeticException - if the provided value will not exactly fit in an long
      • requireFirstItem

        @NonNull
        public static <ITEM extends IItem> ITEM requireFirstItem​(@NonNull
                                                                 ISequence<ITEM> sequence,
                                                                 boolean requireSingleton)
        Retrieves the first item in a sequence. If the sequence is empty, a TypeMetapathException exception is thrown. If requireSingleton is true and the sequence contains more than one item, a TypeMetapathException is thrown.
        Type Parameters:
        ITEM - the item type to return derived from the provided sequence
        Parameters:
        sequence - the sequence to retrieve the first item from
        requireSingleton - if true then a TypeMetapathException is thrown if the sequence contains more than one item
        Returns:
        null if the sequence is empty, or the item otherwise
        Throws:
        TypeMetapathException - if the sequence is empty, or contains more than one item and requireSingleton is true
      • getFirstItem

        @Nullable
        public static <ITEM extends IItem> ITEM getFirstItem​(@NonNull
                                                             ISequence<ITEM> sequence,
                                                             boolean requireSingleton)
        Retrieves the first item in a sequence. If the sequence is empty, a null result is returned. If requireSingleton is true and the sequence contains more than one item, a TypeMetapathException is thrown.
        Type Parameters:
        ITEM - the item type to return derived from the provided sequence
        Parameters:
        sequence - the sequence to retrieve the first item from
        requireSingleton - if true then a TypeMetapathException is thrown if the sequence contains more than one item
        Returns:
        null if the sequence is empty, or the item otherwise
        Throws:
        TypeMetapathException - if the sequence contains more than one item and requireSingleton is true
      • toNumeric

        @Nullable
        public static INumericItem toNumeric​(@NonNull
                                             ISequence<?> sequence,
                                             boolean requireSingleton)
        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

        @NonNull
        public static INumericItem toNumeric​(@NonNull
                                             IItem item)
        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
      • asType

        @NonNull
        public static <TYPE extends IItem> TYPE asType​(@NonNull
                                                       IItem item)