Class SwitchExpression
- java.lang.Object
-
- dev.morphia.aggregation.expressions.impls.Expression
-
- dev.morphia.aggregation.expressions.impls.SwitchExpression
-
public class SwitchExpression extends Expression
Evaluates a series of case expressions. When it finds an expression which evaluates to true, $switch executes a specified expression and breaks out of the control flow.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description SwitchExpression()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SwitchExpressionbranch(Expression caseExpression, Expression then)Adds a new branch to the switchSwitchExpressiondefaultCase(Expression caseExpression)Adds a default case if nothing is matched.voidencode(Datastore datastore, BsonWriter writer, EncoderContext encoderContext)-
Methods inherited from class dev.morphia.aggregation.expressions.impls.Expression
getOperation, getValue, toString
-
-
-
-
Method Detail
-
branch
public SwitchExpression branch(Expression caseExpression, Expression then)
Adds a new branch to the switch- Parameters:
caseExpression- Can be any valid expression that resolves to a boolean. If the result is not a boolean, it is coerced to a boolean value.then- the expression to evaluate if the case is true- Returns:
- this
-
defaultCase
public SwitchExpression defaultCase(Expression caseExpression)
Adds a default case if nothing is matched.- Parameters:
caseExpression- the default case- Returns:
- this
-
encode
public void encode(Datastore datastore, BsonWriter writer, EncoderContext encoderContext)
- Overrides:
encodein classExpression- Parameters:
datastore- the datastorewriter- the writerencoderContext- the context
-
-