Package dev.vortex.api.expressions
Class Binary
java.lang.Object
dev.vortex.api.expressions.Binary
- All Implemented Interfaces:
Expression
Represents a binary expression that operates on two child expressions using a binary operator.
Binary expressions support comparison operations (equality, inequality, relational comparisons)
and boolean algebra operations (AND, OR).
This class is immutable and implements the Expression
interface, making it suitable
for use in expression trees and query processing pipelines.
Example usage:
// Create equality comparison: left == right Binary equalExpr = Binary.eq(leftExpr, rightExpr); // Create logical AND: expr1 && expr2 && expr3 Binary andExpr = Binary.and(expr1, expr2, expr3); // Create greater than comparison: left > right Binary gtExpr = Binary.gt(leftExpr, rightExpr);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Enumeration of binary operators supported by binary expressions.Nested classes/interfaces inherited from interface dev.vortex.api.Expression
Expression.Visitor<T>
-
Method Summary
Modifier and TypeMethodDescription<T> T
accept
(Expression.Visitor<T> visitor) Accepts a visitor and dispatches to the appropriate visit method based on the expression type.static Binary
and
(Expression first, Expression... rest) Creates a logical AND expression combining multiple expressions.children()
Returns the children of this expression.static Binary
eq
(Expression left, Expression right) Creates an equality comparison expression (==).boolean
getLeft()
Returns the left operand expression.Returns the binary operator used in this expression.getRight()
Returns the right operand expression.static Binary
gt
(Expression left, Expression right) Creates a greater-than comparison expression (>).static Binary
gtEq
(Expression left, Expression right) Creates a greater-than-or-equal comparison expression (>=).int
hashCode()
id()
The globally unique identifier for this type of expression.static Binary
lt
(Expression left, Expression right) Creates a less-than comparison expression (<).static Binary
ltEq
(Expression left, Expression right) Creates a less-than-or-equal comparison expression (<=).Optional<byte[]>
metadata()
Returns the serialized metadata for this expression, or empty if serialization is not supported.static Binary
notEq
(Expression left, Expression right) Creates an inequality comparison expression (!=).static Binary
of
(Binary.BinaryOp operator, Expression left, Expression right) Creates a new Binary expression with the specified operator and operands.static Binary
or
(Expression first, Expression... rest) Creates a logical OR expression combining multiple expressions.static Binary
parse
(byte[] metadata, List<Expression> children) Parses a Binary expression from protobuf metadata and child expressions.toString()
-
Method Details
-
parse
Parses a Binary expression from protobuf metadata and child expressions.- Parameters:
metadata
- the serialized protobuf metadata containing the binary operatorchildren
- the list of child expressions, must contain exactly 2 expressions- Returns:
- a new Binary expression instance
- Throws:
RuntimeException
- if children size is not 2 or if metadata parsing fails
-
of
Creates a new Binary expression with the specified operator and operands.- Parameters:
operator
- the binary operator to applyleft
- the left operand expressionright
- the right operand expression- Returns:
- a new Binary expression instance
-
and
Creates a logical AND expression combining multiple expressions. If only one expression is provided, it returns an AND with a literal true. Multiple expressions are right-associated:first && (rest[0] && rest[1] && ...)
.- Parameters:
first
- the first expression (left operand)rest
- additional expressions to AND together (right operands)- Returns:
- a new Binary expression representing the logical AND operation
-
or
Creates a logical OR expression combining multiple expressions. If only one expression is provided, it returns an OR with a literal false. Multiple expressions are right-associated:first || (rest[0] || rest[1] || ...)
.- Parameters:
first
- the first expression (left operand)rest
- additional expressions to OR together (right operands)- Returns:
- a new Binary expression representing the logical OR operation
-
eq
Creates an equality comparison expression (==).- Parameters:
left
- the left operand expressionright
- the right operand expression- Returns:
- a new Binary expression representing left == right
-
notEq
Creates an inequality comparison expression (!=).- Parameters:
left
- the left operand expressionright
- the right operand expression- Returns:
- a new Binary expression representing left != right
-
gt
Creates a greater-than comparison expression (>).- Parameters:
left
- the left operand expressionright
- the right operand expression- Returns:
- a new Binary expression representing left > right
-
gtEq
Creates a greater-than-or-equal comparison expression (>=).- Parameters:
left
- the left operand expressionright
- the right operand expression- Returns:
- a new Binary expression representing left >= right
-
lt
Creates a less-than comparison expression (<).- Parameters:
left
- the left operand expressionright
- the right operand expression- Returns:
- a new Binary expression representing left < right
-
ltEq
Creates a less-than-or-equal comparison expression (<=).- Parameters:
left
- the left operand expressionright
- the right operand expression- Returns:
- a new Binary expression representing left <= right
-
id
Description copied from interface:Expression
The globally unique identifier for this type of expression.- Specified by:
id
in interfaceExpression
-
children
Description copied from interface:Expression
Returns the children of this expression.- Specified by:
children
in interfaceExpression
-
metadata
Description copied from interface:Expression
Returns the serialized metadata for this expression, or empty if serialization is not supported.- Specified by:
metadata
in interfaceExpression
-
toString
-
equals
-
hashCode
public int hashCode() -
accept
Description copied from interface:Expression
Accepts a visitor and dispatches to the appropriate visit method based on the expression type. This method implements the visitor pattern, allowing different operations to be performed on expressions without modifying the expression classes themselves.- Specified by:
accept
in interfaceExpression
- Type Parameters:
T
- the return type of the visitor- Parameters:
visitor
- the visitor to accept- Returns:
- the result of the visitor's operation on this expression
-
getOperator
Returns the binary operator used in this expression.- Returns:
- the binary operator
-
getLeft
Returns the left operand expression.- Returns:
- the left operand expression
-
getRight
Returns the right operand expression.- Returns:
- the right operand expression
-