Class SwitchExpression
- java.lang.Object
-
- dev.morphia.aggregation.experimental.expressions.impls.Expression
-
- dev.morphia.aggregation.experimental.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 SwitchExpression
branch(Expression caseExpression, Expression then)
Adds a new branch to the switchSwitchExpression
defaultCase(Expression caseExpression)
Adds a default case if nothing is matched.void
encode(Mapper mapper, org.bson.BsonWriter writer, org.bson.codecs.EncoderContext encoderContext)
-
Methods inherited from class dev.morphia.aggregation.experimental.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(Mapper mapper, org.bson.BsonWriter writer, org.bson.codecs.EncoderContext encoderContext)
- Overrides:
encode
in classExpression
- Parameters:
mapper
- the mapperwriter
- the writerencoderContext
- the context
-
-