Rename OpNode to BinaryInfixNode.

This commit is contained in:
Danila Fedorin 2017-07-28 11:15:36 -07:00
parent 5228773b5e
commit 2ba6e22fcb
3 changed files with 7 additions and 7 deletions

View File

@ -3,7 +3,7 @@ package org.nwapw.abacus.tree;
/**
* A tree node that represents an operation being applied to two operands.
*/
public class OpNode extends TreeNode {
public class BinaryInfixNode extends TreeNode {
/**
* The operation being applied.
@ -18,14 +18,14 @@ public class OpNode extends TreeNode {
*/
private TreeNode right;
private OpNode() {}
private BinaryInfixNode() {}
/**
* Creates a new operation node with the given operation
* and no child nodes.
* @param operation the operation.
*/
public OpNode(String operation){
public BinaryInfixNode(String operation){
this(operation, null, null);
}
@ -36,7 +36,7 @@ public class OpNode extends TreeNode {
* @param left the left node of the expression.
* @param right the right node of the expression.
*/
public OpNode(String operation, TreeNode left, TreeNode right){
public BinaryInfixNode(String operation, TreeNode left, TreeNode right){
this.operation = operation;
this.left = left;
this.right = right;

View File

@ -27,10 +27,10 @@ public class NumberReducer implements Reducer<NumberInterface> {
public NumberInterface reduceNode(TreeNode node, Object... children) {
if(node instanceof NumberNode) {
return ((NumberNode) node).getNumber();
} else if(node instanceof OpNode){
} else if(node instanceof BinaryInfixNode){
NumberInterface left = (NumberInterface) children[0];
NumberInterface right = (NumberInterface) children[1];
Function function = manager.operatorFor(((OpNode) node).getOperation()).getFunction();
Function function = manager.operatorFor(((BinaryInfixNode) node).getOperation()).getFunction();
if(function == null) return null;
return function.apply(left, right);
} else if(node instanceof UnaryPrefixNode) {

View File

@ -163,7 +163,7 @@ public class TreeBuilder {
TreeNode right = fromStringRecursive(source, matches);
TreeNode left = fromStringRecursive(source, matches);
if(left == null || right == null) return null;
else return new OpNode(operator, left, right);
else return new BinaryInfixNode(operator, left, right);
} else {
TreeNode applyTo = fromStringRecursive(source, matches);
if(applyTo == null) return null;