Class MathUtil


  • public class MathUtil
    extends Object
    A utility class for evaluation of mathematical expressions on RDF literals.
    Author:
    Jeen Broekstra
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_DECIMAL_EXPANSION_SCALE
      The default expansion scale used in division operations resulting in a decimal value with non-terminating decimal expansion.
    • Constructor Summary

      Constructors 
      Constructor Description
      MathUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.eclipse.rdf4j.model.Literal compute​(org.eclipse.rdf4j.model.Literal leftLit, org.eclipse.rdf4j.model.Literal rightLit, MathExpr.MathOp op)  
      static org.eclipse.rdf4j.model.Literal compute​(org.eclipse.rdf4j.model.Literal leftLit, org.eclipse.rdf4j.model.Literal rightLit, MathExpr.MathOp op, org.eclipse.rdf4j.model.ValueFactory vf)
      Computes the result of applying the supplied math operator on the supplied left and right operand.
      static int getDecimalExpansionScale()
      Returns the decimal expansion scale used in division operations resulting in a decimal value with non-terminating decimal expansion.
      static void setDecimalExpansionScale​(int decimalExpansionScale)
      Sets the decimal expansion scale used in divisions resulting in a decimal value with non-terminating decimal expansion.
    • Field Detail

      • DEFAULT_DECIMAL_EXPANSION_SCALE

        public static final int DEFAULT_DECIMAL_EXPANSION_SCALE
        The default expansion scale used in division operations resulting in a decimal value with non-terminating decimal expansion. The OpenRDF default is 24 digits, a value used in various other SPARQL implementations, to make comparison between these systems easy.
        See Also:
        Constant Field Values
    • Constructor Detail

      • MathUtil

        public MathUtil()
    • Method Detail

      • compute

        public static org.eclipse.rdf4j.model.Literal compute​(org.eclipse.rdf4j.model.Literal leftLit,
                                                              org.eclipse.rdf4j.model.Literal rightLit,
                                                              MathExpr.MathOp op,
                                                              org.eclipse.rdf4j.model.ValueFactory vf)
                                                       throws ValueExprEvaluationException
        Computes the result of applying the supplied math operator on the supplied left and right operand.
        Parameters:
        leftLit - a numeric datatype literal
        rightLit - a numeric datatype literal
        op - a mathematical operator, as definied by MathExpr.MathOp.
        vf - a ValueFactory used to create the result
        Returns:
        a numeric datatype literal containing the result of the operation. The result will be datatype according to the most specific data type the two operands have in common per the SPARQL/XPath spec.
        Throws:
        ValueExprEvaluationException
      • getDecimalExpansionScale

        public static int getDecimalExpansionScale()
        Returns the decimal expansion scale used in division operations resulting in a decimal value with non-terminating decimal expansion. By default, this value is set to 24.
        Returns:
        The decimal expansion scale.
      • setDecimalExpansionScale

        public static void setDecimalExpansionScale​(int decimalExpansionScale)
        Sets the decimal expansion scale used in divisions resulting in a decimal value with non-terminating decimal expansion.
        Parameters:
        decimalExpansionScale - The decimal expansion scale to set. Note that a mimimum of 18 is required to stay compliant with the XPath specification of xsd:decimal operations.