From eac4ce860014055ce8eb09b6ca812bf8dd551146 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 28 Jul 2017 14:47:34 -0700 Subject: [PATCH] Change the constructor for NumberNode --- src/org/nwapw/abacus/tree/NumberNode.java | 15 +++------------ src/org/nwapw/abacus/tree/TreeBuilder.java | 4 +++- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/org/nwapw/abacus/tree/NumberNode.java b/src/org/nwapw/abacus/tree/NumberNode.java index 41112e7..77dc7a1 100644 --- a/src/org/nwapw/abacus/tree/NumberNode.java +++ b/src/org/nwapw/abacus/tree/NumberNode.java @@ -22,19 +22,10 @@ public class NumberNode extends TreeNode { /** * Creates a new number node with the given double value. - * @param value the value to use. + * @param newNumber the number for which to create a number node. */ - public NumberNode(double value){ - number = new NaiveNumber(value); - } - - /** - * Creates a new number node with the given string value, converted - * to a double. - * @param value the value. - */ - public NumberNode(String value){ - this(Double.parseDouble(value)); + public NumberNode(NumberInterface newNumber){ + this.number = newNumber; } /** diff --git a/src/org/nwapw/abacus/tree/TreeBuilder.java b/src/org/nwapw/abacus/tree/TreeBuilder.java index 9bc55de..83f2ebd 100644 --- a/src/org/nwapw/abacus/tree/TreeBuilder.java +++ b/src/org/nwapw/abacus/tree/TreeBuilder.java @@ -5,6 +5,8 @@ import org.nwapw.abacus.function.OperatorType; import org.nwapw.abacus.lexing.Lexer; import org.nwapw.abacus.lexing.pattern.Match; import org.nwapw.abacus.lexing.pattern.Pattern; +import org.nwapw.abacus.number.NaiveNumber; +import org.nwapw.abacus.number.PreciseNumber; import java.util.*; @@ -170,7 +172,7 @@ public class TreeBuilder { else return new UnaryPrefixNode(operator, applyTo); } } else if(matchType == TokenType.NUM){ - return new NumberNode(Double.parseDouble(source.substring(match.getFrom(), match.getTo()))); + return new NumberNode(new NaiveNumber(Double.parseDouble(source.substring(match.getFrom(), match.getTo())))); } else if(matchType == TokenType.FUNCTION){ String functionName = source.substring(match.getFrom(), match.getTo()); FunctionNode node = new FunctionNode(functionName);