Class MathExpressions
- java.lang.Object
-
- dev.morphia.aggregation.experimental.expressions.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 Expression
abs(Expression value)
Returns the absolute value of a number.static MathExpression
add(Expression first, Expression... additional)
Adds numbers together or adds numbers and a date.static Expression
ceil(Expression value)
Returns the smallest integer greater than or equal to the specified number.static Expression
divide(Expression numerator, Expression divisor)
Returns the result of dividing the first number by the second.static Expression
exp(Expression value)
Raises e to the specified exponent.static Expression
floor(Expression value)
Returns the largest integer less than or equal to the specified number.static Expression
ln(Expression value)
Calculates the natural log of a number.static Expression
log(Expression number, Expression base)
Calculates the log of a number in the specified base.static Expression
log10(Expression value)
Calculates the log base 10 of a number.static Expression
mod(Expression dividend, Expression divisor)
Returns the remainder of the first number divided by the second.static Expression
multiply(Expression first, Expression... additional)
Multiplies numbers together and returns the result.static Expression
pow(Expression number, Expression exponent)
Raises a number to the specified exponent.static Expression
round(Expression number, Expression place)
Rounds a number to to a whole integer or to a specified decimal place.static Expression
sqrt(Expression value)
Calculates the square root.static Expression
subtract(Expression minuend, Expression subtrahend)
Returns the result of subtracting the second value from the first.static Expression
trunc(Expression number, Expression place)
Truncates a number to a whole integer or to a specified decimal place.
-
-
-
Method Detail
-
abs
public static Expression abs(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 MathExpression add(Expression first, 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 sumadditional
- any subsequent expressions to include in the sum- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $add
-
ceil
public static Expression ceil(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 Expression divide(Expression numerator, Expression divisor)
Returns the result of dividing the first number by the second. Accepts two argument expressions.- Parameters:
numerator
- the numeratordivisor
- the divisor- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $divide
-
exp
public static Expression exp(Expression 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(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 Expression ln(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 Expression log(Expression number, Expression base)
Calculates the log of a number in the specified base.- Parameters:
number
- the number to logbase
- the base to use- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $log
-
log10
public static Expression log10(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 Expression mod(Expression dividend, Expression divisor)
Returns the remainder of the first number divided by the second. Accepts two argument expressions.- Parameters:
dividend
- the dividenddivisor
- the divisor- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $mod
-
multiply
public static Expression multiply(Expression first, Expression... additional)
Multiplies numbers together and returns the result. Pass the arguments to $multiply in an array.- Parameters:
first
- the first expression to addadditional
- any additional expressions- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $multiply
-
pow
public static Expression pow(Expression number, Expression exponent)
Raises a number to the specified exponent.- Parameters:
number
- the base nameexponent
- the exponent- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $pow
-
round
public static Expression round(Expression number, Expression place)
Rounds a number to to a whole integer or to a specified decimal place.- Parameters:
number
- the valueplace
- the place to round to- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $round
-
sqrt
public static Expression sqrt(Expression value)
Calculates the square root.- Parameters:
value
- the value- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $sqrt
-
subtract
public static Expression subtract(Expression minuend, 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 fromsubtrahend
- the number to subtract- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $subtract
-
trunc
public static Expression trunc(Expression number, 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 valueplace
- the place to trunc to- Returns:
- the new expression
- MongoDB documentation
- Aggregration Expression: $trunc
-
-