/** * Gets the name of this node. This method may be called on nodes that are * not operators ({@code isOperator() == false}) or numbers ({@code isNumber() == false}). * * @return the name of this node. * @throws IllegalArgumentException * if the method is called on nodes that are operators or * numbers. */ public String getName() { if (!isOperator() && !isNumber()) { return (variable == null) ? name : variable.getId(); } if (!isInvalidSBMLAllowed()) { throw new IllegalArgumentException(resourceBundle.getString("ASTNode.getName")); } return name; }
@Override public ASTNodeValue frac(ASTNode numerator, ASTNode denominator) throws SBMLException { ASTNodeValue numValue = numerator.compile(this); ASTNodeValue demValue = denominator.compile(this); if (numerator.isNumber() && denominator.isNumber()) { return new ASTNodeValue(numValue.toDouble() / demValue.toDouble(), this); } return unknownValue(); }
@Override public ASTNodeValue root(ASTNode rootExponent, ASTNode value) throws SBMLException { if (rootExponent.isNumber() && (rootExponent.getReal() == 2d)) { return sqrt(value); } return new ASTNodeValue(concat("\\sqrt[", rootExponent, "]{", value.compile(this), Character.valueOf('}')).toString(), this); }
@Override public ASTNodeValue abs(ASTNode value) throws SBMLException { ASTNodeValue v = value.compile(this); if (value.isDifference() || value.isSum() || value.isUMinus() || value.isNumber()) { v.setValue(Double.valueOf(Math.abs(v.toDouble()))); } return v; }
@Override public boolean getAllowsChildren() { return !(isConstant() || isInfinity() || isNumber() || isNegInfinity() || isNaN() || isRational()); }
/** * Compiles a function with one argument and where we don't want to put the argument * between brackets if it is a number or an id. * * @param name the name of the function, can also be just a sign, like not ('!') or '<='. * @param node the single argument to the function * @return a new {@link ASTNodeValue} that contain the String representation of the function. * @throws SBMLException if an error is detected while going through the {@link ASTNode} */ protected ASTNodeValue functionNotAlwaysBrackets(String name, ASTNode node) throws SBMLException { if (node.isName() || node.isNumber()) { return new ASTNodeValue(concat(name, node.compile(this)).toString(), this); } return new ASTNodeValue(concat(name, brackets(node.compile(this))).toString(), this); }
/** * Creates brackets around the given ASTNode if it is not a simple number or String * or a function (meaning the method {@link ASTNode#isFunction()} returns true). * * @param node the {@link ASTNode} to compile to String * @return a String representing the given ASTNode * @throws SBMLException - if any error occurs while going through the ASTNode */ protected String checkArgumentBrackets(ASTNode node) throws SBMLException { String term = node.compile(this).toString(); if ((node.isNumber() || node.isString() || node.isFunction()) && (! (node.getType() == ASTNode.Type.FUNCTION_POWER || node.getType() == ASTNode.Type.FUNCTION_REM))) { return term; } // for node.isRelational() and node.isLogical(), we want to put brackets return term = brackets(term).toString(); }
@Override public ASTNodeValue root(ASTNode rootExponent, ASTNode radiant) throws SBMLException { if (rootExponent.isSetUnits()) { checkForDimensionlessOrInvalidUnits(rootExponent.getUnitsInstance()); } if (rootExponent.isNumber()) { if (!(rootExponent.isInteger() || rootExponent.isRational())) { checkForDimensionlessOrInvalidUnits(rootExponent .getUnitsInstance()); } return root(rootExponent.compile(this).toDouble(), radiant); } return invalid(); }
/** * @param value */ private void sinRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { sinRecursive(value.getChild(i)); } else if (useId){ ASTNode sinValue = new ASTNode(ASTNode.Type.FUNCTION_SIN, child.getParentSBMLObject()); sinValue.addChild(child.clone()); value.replaceChild(i, sinValue); } else if (child.isNumber()) { value.getChild(i).setValue(Math.sin(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void ceilingRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { ceilingRecursive(value.getChild(i)); } else if (useId){ ASTNode ceilValue = new ASTNode(ASTNode.Type.FUNCTION_CEILING, child.getParentSBMLObject()); ceilValue.addChild(child.clone()); value.replaceChild(i, ceilValue); } else if (child.isNumber()) { value.getChild(i).setValue(Math.ceil(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void logRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { logRecursive(value.getChild(i)); } else if (useId){ ASTNode logValue = new ASTNode(ASTNode.Type.FUNCTION_LOG, child.getParentSBMLObject()); logValue.addChild(child.clone()); value.replaceChild(i, logValue); } else if (child.isNumber()) { value.getChild(i).setValue(Math.log10(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void arctanhRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arctanhRecursive(value.getChild(i)); } else if (useId){ ASTNode arctanhValue = new ASTNode(ASTNode.Type.FUNCTION_ARCTANH, child.getParentSBMLObject()); arctanhValue.addChild(child.clone()); value.replaceChild(i, arctanhValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.arctanh(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void cothRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { cothRecursive(value.getChild(i)); } else if (useId){ ASTNode cothValue = new ASTNode(ASTNode.Type.FUNCTION_COTH, child.getParentSBMLObject()); cothValue.addChild(child.clone()); value.replaceChild(i, cothValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.coth(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void arccothRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arccothRecursive(value.getChild(i)); } else if (useId){ ASTNode arccothValue = new ASTNode(ASTNode.Type.FUNCTION_ARCCOTH, child.getParentSBMLObject()); arccothValue.addChild(child.clone()); value.replaceChild(i, arccothValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.arccoth(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void arccscRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arccscRecursive(value.getChild(i)); } else if (useId){ ASTNode arccscValue = new ASTNode(ASTNode.Type.FUNCTION_ARCCSC, child.getParentSBMLObject()); arccscValue.addChild(child.clone()); value.replaceChild(i, arccscValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.arccsc(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void arcsecRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arcsecRecursive(value.getChild(i)); } else if (useId){ ASTNode arcsecValue = new ASTNode(ASTNode.Type.FUNCTION_ARCSEC, child.getParentSBMLObject()); arcsecValue.addChild(child.clone()); value.replaceChild(i, arcsecValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.arcsec(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void coshRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isNumber()) { value.getChild(i).setValue(Math.cosh(child.getReal())); } else if (child.isVector()) { coshRecursive(value.getChild(i)); } else if (useId){ ASTNode coshValue = new ASTNode(ASTNode.Type.FUNCTION_COSH, child.getParentSBMLObject()); coshValue.addChild(child.clone()); value.replaceChild(i, coshValue); } else { throw new SBMLException(); } } }
/** * @param value */ private void cschRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { cschRecursive(value.getChild(i)); } else if (useId){ ASTNode cschValue = new ASTNode(ASTNode.Type.FUNCTION_CSCH, child.getParentSBMLObject()); cschValue.addChild(child.clone()); value.replaceChild(i, cschValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.csch(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void arcsechRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arcsechRecursive(value.getChild(i)); } else if (useId){ ASTNode arcsechValue = new ASTNode(ASTNode.Type.FUNCTION_ARCSECH, child.getParentSBMLObject()); arcsechValue.addChild(child.clone()); value.replaceChild(i, arcsechValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.arcsech(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void cscRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { cscRecursive(value.getChild(i)); } else if (useId){ ASTNode cscValue = new ASTNode(ASTNode.Type.FUNCTION_CSC, child.getParentSBMLObject()); cscValue.addChild(child.clone()); value.replaceChild(i, cscValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.csc(child.getReal())); } else { throw new SBMLException(); } } }