Record Class BinaryOpNode
java.lang.Object
java.lang.Record
cloud.opencode.base.expression.ast.BinaryOpNode
- Record Components:
operator- the operator | 运算符left- the left operand | 左操作数right- the right operand | 右操作数
- All Implemented Interfaces:
Node
Binary Operation Node
二元运算节点
Represents binary operations: arithmetic, comparison, logical.
表示二元运算:算术、比较、逻辑。
Features | 主要功能:
- Arithmetic: +, -, *, /, %, ** - 算术运算
- Comparison: ==, !=, >, >=, <, <= - 比较运算
- Logical: &&, || with short-circuit evaluation - 逻辑运算,支持短路求值
- Pattern matching: matches, instanceof - 模式匹配
- String concatenation via + operator - 通过+运算符进行字符串连接
Usage Examples | 使用示例:
Node left = LiteralNode.of(10);
Node right = LiteralNode.of(3);
Node add = BinaryOpNode.of(left, "+", right);
Object result = add.evaluate(ctx); // 13
Security | 安全性:
- Thread-safe: Yes, immutable record - 线程安全: 是,不可变记录
- Null-safe: No, null operands require non-null - 空值安全: 否,操作数要求非空
- ReDoS protection: regex matching has timeout and length limits - ReDoS防护: 正则匹配有超时和长度限制
- Since:
- JDK 25, opencode-base-expression V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionBinaryOpNode(String operator, Node left, Node right) Creates an instance of aBinaryOpNoderecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.evaluate(EvaluationContext context) Evaluate this node 求值此节点final inthashCode()Returns a hash code value for this object.left()Returns the value of theleftrecord component.static BinaryOpNodeCreate binary operation node 创建二元运算节点operator()Returns the value of theoperatorrecord component.right()Returns the value of therightrecord component.Get string representation for debugging 获取用于调试的字符串表示final StringtoString()Returns a string representation of this record class.Methods inherited from interface Node
getTypeName
-
Constructor Details
-
BinaryOpNode
-
-
Method Details
-
of
Create binary operation node 创建二元运算节点- Parameters:
left- the left operand | 左操作数operator- the operator string | 运算符字符串right- the right operand | 右操作数- Returns:
- the binary operation node | 二元运算节点
-
evaluate
Description copied from interface:NodeEvaluate this node 求值此节点 -
toExpressionString
Description copied from interface:NodeGet string representation for debugging 获取用于调试的字符串表示- Specified by:
toExpressionStringin interfaceNode- Returns:
- the string representation | 字符串表示
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
operator
-
left
-
right
-