Class 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 Detail

      • SwitchExpression

        public SwitchExpression()
        Developer note.
        This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
    • 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 class Expression
        Parameters:
        mapper - the mapper
        writer - the writer
        encoderContext - the context