2017-07-25 14:21:00 -07:00
|
|
|
package org.nwapw.abacus.tree;
|
|
|
|
|
|
|
|
import org.nwapw.abacus.number.NaiveNumber;
|
2017-07-25 14:26:31 -07:00
|
|
|
import org.nwapw.abacus.number.NumberInterface;
|
2017-07-25 14:21:00 -07:00
|
|
|
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* A node implementation that represents a single number.
|
|
|
|
*/
|
2017-07-25 14:21:00 -07:00
|
|
|
public class NumberNode extends TreeNode {
|
|
|
|
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* The number that is represented by this number node.
|
|
|
|
*/
|
2017-07-25 14:26:31 -07:00
|
|
|
private NumberInterface number;
|
2017-07-25 14:21:00 -07:00
|
|
|
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* Creates a number node with no number.
|
|
|
|
*/
|
2017-07-25 14:21:00 -07:00
|
|
|
public NumberNode(){
|
|
|
|
number = null;
|
|
|
|
}
|
|
|
|
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* Creates a new number node with the given double value.
|
|
|
|
* @param value the value to use.
|
|
|
|
*/
|
2017-07-25 14:21:00 -07:00
|
|
|
public NumberNode(double value){
|
|
|
|
number = new NaiveNumber(value);
|
|
|
|
}
|
|
|
|
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* Creates a new number node with the given string value, converted
|
|
|
|
* to a double.
|
|
|
|
* @param value the value.
|
|
|
|
*/
|
2017-07-25 14:21:00 -07:00
|
|
|
public NumberNode(String value){
|
|
|
|
this(Double.parseDouble(value));
|
|
|
|
}
|
|
|
|
|
2017-07-26 10:10:37 -07:00
|
|
|
/**
|
|
|
|
* Gets the number value of this node.
|
|
|
|
* @return the number value of this node.
|
|
|
|
*/
|
2017-07-25 14:26:31 -07:00
|
|
|
public NumberInterface getNumber() {
|
2017-07-25 14:21:00 -07:00
|
|
|
return number;
|
|
|
|
}
|
|
|
|
}
|