Class MathExpressions

java.lang.Object
dev.morphia.aggregation.expressions.MathExpressions

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

    • abs

      public static Expression abs(Object value)
      Returns the absolute value of a number.
      Parameters:
      value - the value
      Returns:
      the new expression
      MongoDB documentation
      Aggregration Expression: $abs
    • add

      public static Expression add(Object first, Object... 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 value to sum
      additional - any subsequent values to include in the sum
      Returns:
      the new expression
      MongoDB documentation
      Aggregration Expression: $add
    • bitAnd

      public static Expression bitAnd(Object first, Object second)
      Returns the result of a bitwise and operation on an array of int or long values.
      Parameters:
      first - the first value to use
      second - the second value to use
      Returns:
      the new expression
      Since:
      3.0
      Since server release
      6.3
      MongoDB documentation
      Aggregration Expression: $bitAnd
    • bitNot

      public static Expression bitNot(Object value)
      Returns the result of a bitwise not operation on a single int or long value.
      Parameters:
      value - the value to use
      Returns:
      the new expression
      Since:
      3.0
      Since server release
      6.3
      MongoDB documentation
      Aggregration Expression: $bitNot
    • bitOr

      public static Expression bitOr(Object first, Object second)
      Returns the result of a bitwise or operation on an array of int or long values.
      Parameters:
      first - the first value to use
      second - the second value to use
      Returns:
      the new expression
      Since:
      3.0
      Since server release
      6.3
      MongoDB documentation
      Aggregration Expression: $bitOr
    • bitXor

      public static Expression bitXor(Object first, Object second)
      Returns the result of a bitwise xor operation on an array of int xor long values.
      Parameters:
      first - the first value to use
      second - the second value to use
      Returns:
      the new expression
      Since:
      3.0
      Since server release
      6.3
      MongoDB documentation
      Aggregration Expression: $bitXor
    • ceil

      public static Expression ceil(Object 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 Expression divide(Object numerator, Object 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 Expression exp(Object value)
      Raises e to the specified exponent.
      Parameters:
      value - the value
      Returns:
      the new expression
      MongoDB documentation
      Aggregration Expression: $exp
    • floor

      public static Expression floor(Object 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 Expression ln(Object value)
      Calculates the natural log of a number.
      Parameters:
      value - the value
      Returns:
      the new expression
      MongoDB documentation
      Aggregration Expression: $ln
    • log

      public static Expression log(Object number, Object 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 Expression log10(Object value)
      Calculates the log base 10 of a number.
      Parameters:
      value - the value
      Returns:
      the new expression
      MongoDB documentation
      Aggregration Expression: $log10
    • median

      public static Expression median(Object input)
      Returns an approximation of the median, the 50th percentile, as a scalar value.
      Parameters:
      input - the input
      Returns:
      the new expression
      Since:
      3.0
      Since server release
      7.0
      MongoDB documentation
      Aggregration Expression: $median
    • mod

      public static Expression mod(Object dividend, Object 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 Expression multiply(Object first, Object... additional)
      Multiplies numbers together and returns the result. Pass the arguments to $multiply in an array.
      Parameters:
      first - the first value to multiply
      additional - any additional values
      Returns:
      the new expression
      MongoDB documentation
      Aggregration Expression: $multiply
    • percentile

      public static Expression percentile(Object input, List<Object> percentiles)
      Returns an array of scalar values that correspond to specified percentile values.
      Parameters:
      input - the input field or expression
      percentiles - the percentiles to compute
      Returns:
      the new expression
      Since:
      3.0
      Since server release
      7.0
      MongoDB documentation
      Aggregration Expression: $percentile
    • percentile

      public static Expression percentile(List<Object> inputs, List<Object> percentiles)
      Returns an array of scalar values that correspond to specified percentile values.
      Parameters:
      inputs - the input fields or expressions
      percentiles - the percentiles to compute
      Returns:
      the new expression
      Since:
      3.0
      Since server release
      7.0
      MongoDB documentation
      Aggregration Expression: $percentile
    • pow

      public static Expression pow(Object number, Object 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 Expression round(Object number, Object place)
      Rounds a number to a whole integer or to a specified decimal place.
      Parameters:
      number - the value
      place - the place to round to
      Returns:
      the new expression
      Since server release
      4.2
      MongoDB documentation
      Aggregration Expression: $round
    • sqrt

      public static Expression sqrt(Object value)
      Calculates the square root.
      Parameters:
      value - the value
      Returns:
      the new expression
      MongoDB documentation
      Aggregration Expression: $sqrt
    • subtract

      public static Expression subtract(Object minuend, Object 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 Expression trunc(Object number)
      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
      Returns:
      the new expression
      MongoDB documentation
      Aggregration Expression: $trunc
    • trunc

      public static Expression trunc(Object number, Object 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. Use trunc(Object) if your server is older than 4.2.

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