Class MetapathExpression

    • Constructor Detail

      • MetapathExpression

        protected MetapathExpression​(@NonNull
                                     String path,
                                     @NonNull
                                     IExpression expr)
        Construct a new Metapath expression.
        Parameters:
        path - the Metapath as a string
        expr - the Metapath as a compiled abstract syntax tree (AST)
    • Method Detail

      • compile

        @NonNull
        public static MetapathExpression compile​(@NonNull
                                                 String path)
        Compiles a Metapath expression string.
        Parameters:
        path - the metapath expression
        Returns:
        the compiled expression object
        Throws:
        MetapathException - if an error occurred while compiling the Metapath expression
      • getPath

        public String getPath()
        Get the original Metapath expression as a string.
        Returns:
        the expression
      • getASTNode

        @NonNull
        protected IExpression getASTNode()
        Get the compiled abstract syntax tree (AST) representation of the Metapath.
        Returns:
        the Metapath AST
      • evaluateAs

        @Nullable
        public <T> T evaluateAs​(@NonNull
                                MetapathExpression.ResultType resultType)
        Evaluate this Metapath expression without a specific focus. The required result type will be determined by the resultType argument.
        Type Parameters:
        T - the expected result type
        Parameters:
        resultType - the type of result to produce
        Returns:
        the converted result
        Throws:
        TypeMetapathException - if the provided sequence is incompatible with the requested result type
        MetapathException - if an error occurred during evaluation
        See Also:
        toResultType(ISequence, ResultType)
      • evaluateAs

        @Nullable
        public <T> T evaluateAs​(@Nullable
                                IItem focus,
                                @NonNull
                                MetapathExpression.ResultType resultType)
        Evaluate this Metapath expression using the provided focus as the initial evaluation context. The required result type will be determined by the resultType argument.
        Type Parameters:
        T - the expected result type
        Parameters:
        focus - the outer focus of the expression
        resultType - the type of result to produce
        Returns:
        the converted result
        Throws:
        TypeMetapathException - if the provided sequence is incompatible with the requested result type
        MetapathException - if an error occurred during evaluation
        See Also:
        toResultType(ISequence, ResultType)
      • evaluateAs

        @Nullable
        public <T> T evaluateAs​(@NonNull
                                IItem focus,
                                @NonNull
                                MetapathExpression.ResultType resultType,
                                @NonNull
                                DynamicContext dynamicContext)
        Evaluate this Metapath expression using the provided focus as the initial evaluation context. The specific result type will be determined by the resultType argument.

        This variant allow for reuse of a provided dynamicContext.

        Type Parameters:
        T - the expected result type
        Parameters:
        focus - the outer focus of the expression
        resultType - the type of result to produce
        dynamicContext - the dynamic context to use for evaluation
        Returns:
        the converted result
        Throws:
        TypeMetapathException - if the provided sequence is incompatible with the requested result type
        MetapathException - if an error occurred during evaluation
        See Also:
        toResultType(ISequence, ResultType)
      • toResultType

        @Nullable
        protected <T> T toResultType​(@NonNull
                                     ISequence<?> sequence,
                                     @NonNull
                                     MetapathExpression.ResultType resultType)
        Converts the provided sequence to the requested resultType.

        The resultType determines the returned result, which is derived from the evaluation result sequence, as follows:

        • BOOLEAN - the effective boolean result is produced using FnBoolean.fnBoolean(ISequence).
        • NODE - the first result item in the sequence is returned.
        • NUMBER - the sequence is cast to a number using IDecimalItem.cast(IAnyAtomicItem).
        • SEQUENCE - the evaluation result sequence.
        • STRING - the string value of the first result item in the sequence.
        Type Parameters:
        T - the requested return value
        Parameters:
        sequence - the sequence to convert
        resultType - the type of result to produce
        Returns:
        the converted result
        Throws:
        TypeMetapathException - if the provided sequence is incompatible with the requested result type
      • evaluate

        @NonNull
        public <T extends IItemISequence<T> evaluate()
        Evaluate this Metapath expression without a specific focus.
        Type Parameters:
        T - the type of items contained in the resulting sequence
        Returns:
        a sequence of Metapath items representing the result of the evaluation
        Throws:
        MetapathException - if an error occurred during evaluation
      • evaluate

        @NonNull
        public <T extends IItemISequence<T> evaluate​(@Nullable
                                                       IItem focus)
        Evaluate this Metapath expression using the provided focus as the initial evaluation context.
        Type Parameters:
        T - the type of items contained in the resulting sequence
        Parameters:
        focus - the outer focus of the expression
        Returns:
        a sequence of Metapath items representing the result of the evaluation
        Throws:
        MetapathException - if an error occurred during evaluation
      • evaluate

        @NonNull
        public <T extends IItemISequence<T> evaluate​(@Nullable
                                                       IItem focus,
                                                       @NonNull
                                                       DynamicContext dynamicContext)
        Evaluate this Metapath expression using the provided focus as the initial evaluation context.

        This variant allow for reuse of a provided dynamicContext.

        Type Parameters:
        T - the type of items contained in the resulting sequence
        Parameters:
        focus - the outer focus of the expression
        dynamicContext - the dynamic context to use for evaluation
        Returns:
        a sequence of Metapath items representing the result of the evaluation
        Throws:
        MetapathException - if an error occurred during evaluation