/** * Recursively replaces dimension id with the appropriate integer value. * * @param math * @param id * @param index * @return */ private static ASTNode replaceDimensionId(ASTNode math, String id, int index) { ASTNode clone = math.clone(); recursiveReplaceDimensionId(clone, id, index); return clone; }
/** * Creates a MathContainer instance from an ASTNode, level and version. By * default, the math is {@code null}. * * @param math the ASTNode representing the math. * @param level the SBML level * @param version the SBML version */ public AbstractMathContainer(ASTNode math, int level, int version) { super(level, version); if (math != null) { setMath(math.clone()); } else { this.math = null; } }
/** * @param math * @param bvar * @param value * @return */ private ASTNode replaceMath(ASTNode math, String bvar, ASTNode value) { ASTNode clone = math.clone(); if (math.isString() && math.toString().equals(bvar)) { return value.clone(); } else { recursiveReplaceDimensionId(clone, bvar, value); return clone; } }
/** * Creates a MathContainer instance from a given MathContainer. * * @param sb an {@code AbstractMathContainer} object to clone */ public AbstractMathContainer(AbstractMathContainer sb) { super(sb); if (sb.isSetMath()) { setMath(sb.getMath().clone()); } else { math = null; } }
/** * @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 arcsinRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arcsinRecursive(value.getChild(i)); } else if (useId){ ASTNode arcsinValue = new ASTNode(ASTNode.Type.FUNCTION_ARCSIN, child.getParentSBMLObject()); arcsinValue.addChild(child.clone()); value.replaceChild(i, arcsinValue); } else if (child.isNumber()) { value.getChild(i).setValue(Math.asin(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void floorRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { floorRecursive(value.getChild(i)); } else if (useId){ ASTNode floorValue = new ASTNode(ASTNode.Type.FUNCTION_FLOOR, child.getParentSBMLObject()); floorValue.addChild(child.clone()); value.replaceChild(i, floorValue); } else if (child.isNumber()) { value.getChild(i).setValue(Math.floor(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void lnRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { lnRecursive(value.getChild(i)); } else if (useId){ ASTNode lnValue = new ASTNode(ASTNode.Type.FUNCTION_LN, child.getParentSBMLObject()); lnValue.addChild(child.clone()); value.replaceChild(i, lnValue); } else if (child.isNumber()) { value.getChild(i).setValue(Math.log(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void tanRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { tanRecursive(value.getChild(i)); } else if (useId) { ASTNode tanValue = new ASTNode(ASTNode.Type.FUNCTION_TAN, child.getParentSBMLObject()); tanValue.addChild(child.clone()); value.replaceChild(i, tanValue); } else if (child.isNumber()) { value.getChild(i).setValue(Math.tan(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void sqrtRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { sqrtRecursive(value.getChild(i)); } else if (useId){ ASTNode sqrtValue = new ASTNode(ASTNode.Type.FUNCTION_ROOT, child.getParentSBMLObject()); sqrtValue.addChild(new ASTNode(2)); sqrtValue.addChild(child.clone()); value.replaceChild(i, sqrtValue); } else if (child.isNumber()) { value.getChild(i).setValue(Math.sqrt(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 cotRecursive(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(Maths.cot(child.getReal())); } else if (child.isVector()) { cotRecursive(value.getChild(i)); } else if (useId){ ASTNode cotValue = new ASTNode(ASTNode.Type.FUNCTION_COT, child.getParentSBMLObject()); cotValue.addChild(child.clone()); value.replaceChild(i, cotValue); } else { throw new SBMLException(); } } }
/** * @param value */ private void sechRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { sechRecursive(value.getChild(i)); } else if (useId){ ASTNode sechValue = new ASTNode(ASTNode.Type.FUNCTION_SECH, child.getParentSBMLObject()); sechValue.addChild(child.clone()); value.replaceChild(i, sechValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.sech(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(); } } }
/** * @param value * @throws SBMLException */ private void arccoshRecursive(ASTNode value) throws SBMLException { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { arccoshRecursive(value.getChild(i)); } else if (useId){ ASTNode arccoshValue = new ASTNode(ASTNode.Type.FUNCTION_ARCCOSH, child.getParentSBMLObject()); arccoshValue.addChild(child.clone()); value.replaceChild(i, arccoshValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.arccosh(child.getReal())); } else { throw new SBMLException(); } } }
/** * @param value */ private void factorialRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { factorialRecursive(value.getChild(i)); } else if (useId){ ASTNode factValue = new ASTNode(ASTNode.Type.FUNCTION_FACTORIAL, child.getParentSBMLObject()); factValue.addChild(child.clone()); value.replaceChild(i, factValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.factorial(child.getInteger())); } else { throw new SBMLException(); } } } /* (non-Javadoc)
/** * @param value */ private void secRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { secRecursive(value.getChild(i)); } else if (useId){ ASTNode secValue = new ASTNode(ASTNode.Type.FUNCTION_SEC, child.getParentSBMLObject()); secValue.addChild(child.clone()); value.replaceChild(i, secValue); } else if (child.isNumber()) { value.getChild(i).setValue(Maths.sec(child.getReal())); } else { throw new SBMLException(); } } } /* (non-Javadoc)
/** * @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(); } } }