Class MathExpressions


  • public final class MathExpressions
    extends Object
    Defines helper methods for the math expressions
    Since:
    2.0
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected MathExpressions()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static dev.morphia.aggregation.expressions.impls.Expression abs​(dev.morphia.aggregation.expressions.impls.Expression value)
      Returns the absolute value of a number.
      static dev.morphia.aggregation.expressions.impls.MathExpression add​(dev.morphia.aggregation.expressions.impls.Expression first, dev.morphia.aggregation.expressions.impls.Expression... additional)
      Adds numbers together or adds numbers and a date.
      static dev.morphia.aggregation.expressions.impls.Expression ceil​(dev.morphia.aggregation.expressions.impls.Expression value)
      Returns the smallest integer greater than or equal to the specified number.
      static dev.morphia.aggregation.expressions.impls.Expression divide​(dev.morphia.aggregation.expressions.impls.Expression numerator, dev.morphia.aggregation.expressions.impls.Expression divisor)
      Returns the result of dividing the first number by the second.
      static dev.morphia.aggregation.expressions.impls.Expression exp​(dev.morphia.aggregation.expressions.impls.Expression value)
      Raises e to the specified exponent.
      static dev.morphia.aggregation.expressions.impls.Expression floor​(dev.morphia.aggregation.expressions.impls.Expression value)
      Returns the largest integer less than or equal to the specified number.
      static dev.morphia.aggregation.expressions.impls.Expression ln​(dev.morphia.aggregation.expressions.impls.Expression value)
      Calculates the natural log of a number.
      static dev.morphia.aggregation.expressions.impls.Expression log​(dev.morphia.aggregation.expressions.impls.Expression number, dev.morphia.aggregation.expressions.impls.Expression base)
      Calculates the log of a number in the specified base.
      static dev.morphia.aggregation.expressions.impls.Expression log10​(dev.morphia.aggregation.expressions.impls.Expression value)
      Calculates the log base 10 of a number.
      static dev.morphia.aggregation.expressions.impls.Expression mod​(dev.morphia.aggregation.expressions.impls.Expression dividend, dev.morphia.aggregation.expressions.impls.Expression divisor)
      Returns the remainder of the first number divided by the second.
      static dev.morphia.aggregation.expressions.impls.Expression multiply​(dev.morphia.aggregation.expressions.impls.Expression first, dev.morphia.aggregation.expressions.impls.Expression... additional)
      Multiplies numbers together and returns the result.
      static dev.morphia.aggregation.expressions.impls.Expression pow​(dev.morphia.aggregation.expressions.impls.Expression number, dev.morphia.aggregation.expressions.impls.Expression exponent)
      Raises a number to the specified exponent.
      static dev.morphia.aggregation.expressions.impls.Expression round​(dev.morphia.aggregation.expressions.impls.Expression number, dev.morphia.aggregation.expressions.impls.Expression place)
      Rounds a number to to a whole integer or to a specified decimal place.
      static dev.morphia.aggregation.expressions.impls.Expression sqrt​(dev.morphia.aggregation.expressions.impls.Expression value)
      Calculates the square root.
      static dev.morphia.aggregation.expressions.impls.Expression subtract​(dev.morphia.aggregation.expressions.impls.Expression minuend, dev.morphia.aggregation.expressions.impls.Expression subtrahend)
      Returns the result of subtracting the second value from the first.
      static dev.morphia.aggregation.expressions.impls.Expression trunc​(dev.morphia.aggregation.expressions.impls.Expression number, dev.morphia.aggregation.expressions.impls.Expression place)
      Truncates a number to a whole integer or to a specified decimal place.
    • Constructor Detail

      • MathExpressions

        protected MathExpressions()
    • Method Detail

      • abs

        public static dev.morphia.aggregation.expressions.impls.Expression abs​(dev.morphia.aggregation.expressions.impls.Expression value)
        Returns the absolute value of a number.
        Parameters:
        value - the value
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $abs
      • add

        public static dev.morphia.aggregation.expressions.impls.MathExpression add​(dev.morphia.aggregation.expressions.impls.Expression first,
                                                                                   dev.morphia.aggregation.expressions.impls.Expression... additional)
        Adds numbers together or adds numbers and a date. If one of the arguments is a date, $add treats the other arguments as milliseconds to add to the date.
        Parameters:
        first - the first expression to sum
        additional - any subsequent expressions to include in the sum
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $add
      • ceil

        public static dev.morphia.aggregation.expressions.impls.Expression ceil​(dev.morphia.aggregation.expressions.impls.Expression value)
        Returns the smallest integer greater than or equal to the specified number.
        Parameters:
        value - the value
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $ceil
      • divide

        public static dev.morphia.aggregation.expressions.impls.Expression divide​(dev.morphia.aggregation.expressions.impls.Expression numerator,
                                                                                  dev.morphia.aggregation.expressions.impls.Expression divisor)
        Returns the result of dividing the first number by the second. Accepts two argument expressions.
        Parameters:
        numerator - the numerator
        divisor - the divisor
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $divide
      • exp

        public static dev.morphia.aggregation.expressions.impls.Expression exp​(dev.morphia.aggregation.expressions.impls.Expression value)
        Raises e to the specified exponent.
        Parameters:
        value - the value
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $exp
      • floor

        public static dev.morphia.aggregation.expressions.impls.Expression floor​(dev.morphia.aggregation.expressions.impls.Expression value)
        Returns the largest integer less than or equal to the specified number.
        Parameters:
        value - the value
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $floor
      • ln

        public static dev.morphia.aggregation.expressions.impls.Expression ln​(dev.morphia.aggregation.expressions.impls.Expression value)
        Calculates the natural log of a number.
        Parameters:
        value - the value
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $ln
      • log

        public static dev.morphia.aggregation.expressions.impls.Expression log​(dev.morphia.aggregation.expressions.impls.Expression number,
                                                                               dev.morphia.aggregation.expressions.impls.Expression base)
        Calculates the log of a number in the specified base.
        Parameters:
        number - the number to log
        base - the base to use
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $log
      • log10

        public static dev.morphia.aggregation.expressions.impls.Expression log10​(dev.morphia.aggregation.expressions.impls.Expression value)
        Calculates the log base 10 of a number.
        Parameters:
        value - the value
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $log10
      • mod

        public static dev.morphia.aggregation.expressions.impls.Expression mod​(dev.morphia.aggregation.expressions.impls.Expression dividend,
                                                                               dev.morphia.aggregation.expressions.impls.Expression divisor)
        Returns the remainder of the first number divided by the second. Accepts two argument expressions.
        Parameters:
        dividend - the dividend
        divisor - the divisor
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $mod
      • multiply

        public static dev.morphia.aggregation.expressions.impls.Expression multiply​(dev.morphia.aggregation.expressions.impls.Expression first,
                                                                                    dev.morphia.aggregation.expressions.impls.Expression... additional)
        Multiplies numbers together and returns the result. Pass the arguments to $multiply in an array.
        Parameters:
        first - the first expression to add
        additional - any additional expressions
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $multiply
      • pow

        public static dev.morphia.aggregation.expressions.impls.Expression pow​(dev.morphia.aggregation.expressions.impls.Expression number,
                                                                               dev.morphia.aggregation.expressions.impls.Expression exponent)
        Raises a number to the specified exponent.
        Parameters:
        number - the base name
        exponent - the exponent
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $pow
      • round

        public static dev.morphia.aggregation.expressions.impls.Expression round​(dev.morphia.aggregation.expressions.impls.Expression number,
                                                                                 dev.morphia.aggregation.expressions.impls.Expression place)
        Rounds a number to to a whole integer or to a specified decimal place.
        Parameters:
        number - the value
        place - the place to round to
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $round
      • sqrt

        public static dev.morphia.aggregation.expressions.impls.Expression sqrt​(dev.morphia.aggregation.expressions.impls.Expression value)
        Calculates the square root.
        Parameters:
        value - the value
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $sqrt
      • subtract

        public static dev.morphia.aggregation.expressions.impls.Expression subtract​(dev.morphia.aggregation.expressions.impls.Expression minuend,
                                                                                    dev.morphia.aggregation.expressions.impls.Expression subtrahend)
        Returns the result of subtracting the second value from the first. If the two values are numbers, return the difference. If the two values are dates, return the difference in milliseconds. If the two values are a date and a number in milliseconds, return the resulting date. Accepts two argument expressions. If the two values are a date and a number, specify the date argument first as it is not meaningful to subtract a date from a number.
        Parameters:
        minuend - the number to subtract from
        subtrahend - the number to subtract
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $subtract
      • trunc

        public static dev.morphia.aggregation.expressions.impls.Expression trunc​(dev.morphia.aggregation.expressions.impls.Expression number,
                                                                                 dev.morphia.aggregation.expressions.impls.Expression place)
        Truncates a number to a whole integer or to a specified decimal place.

        NOTE: Prior to 4.2, the place value wasn't available. Pass null if your server is older than 4.2.

        Parameters:
        number - the value
        place - the place to trunc to
        Returns:
        the new expression
        MongoDB documentation
        Aggregration Expression: $trunc