@Override public boolean accepts(Object o) { if (o instanceof ASTNode) { ASTNode current = (ASTNode) o; if (current.equals(bvar)) { ASTNode parent = (ASTNode) current.getParent(); int index = parent.getIndex(current); if (index != -1) { parent.replaceChild(index, expandedBVar); } } } return false; } });
/** * @param math * @param bvar * @param value */ private void recursiveReplaceDimensionId(ASTNode math, String bvar, ASTNode value) { for (int i = 0; i < math.getChildCount(); ++i) { if (math.getChild(i).isString() && math.getChild(i).getName().equals(bvar)) { math.replaceChild(i, value); } recursiveReplaceDimensionId(math.getChild(i), bvar, value); } }
/** * * @param vectorLHS * @param scalarRHS */ private void vectorScalarPow(ASTNode vectorLHS, ASTNode scalarRHS) { for (int i = 0; i < vectorLHS.getChildCount(); ++i) { ASTNode child = vectorLHS.getChild(i); child.compile(this); ASTNode result = getNode(); if (result.isVector()) { vectorScalarLt(child, scalarRHS); } else if (useId) { vectorLHS.replaceChild(i, ASTNode.pow(result, scalarRHS)); } else if (result.isNumber() && scalarRHS.isNumber()) { vectorLHS.getChild(i).setValue(Math.pow(result.getReal(), scalarRHS.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 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 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 vectorLHS * @param scalarRHS */ private void vectorScalarLeq(ASTNode vectorLHS, ASTNode scalarRHS) { for (int i = 0; i < vectorLHS.getChildCount(); ++i) { ASTNode child = vectorLHS.getChild(i); child.compile(this); ASTNode result = getNode(); if (result.isVector()) { vectorScalarLeq(child, scalarRHS); } else if (useId) { vectorLHS.replaceChild(i, ASTNode.leq(result, scalarRHS)); } else if (result.isNumber() && scalarRHS.isNumber()) { vectorLHS.getChild(i).setValue(result.getReal() <= scalarRHS.getReal() ? 1 : 0); } else { throw new SBMLException(); } } }
/** * * @param vector * @param scalar */ private void scalarVectorNeq(ASTNode vector, ASTNode scalar) { for (int i = 0; i < vector.getChildCount(); ++i) { ASTNode child = vector.getChild(i); child.compile(this); ASTNode result = getNode(); if (result.isVector()) { scalarVectorNeq(child, scalar); } else if (useId) { vector.replaceChild(i, ASTNode.neq(result, scalar)); } else if (result.isNumber() && scalar.isNumber()) { vector.getChild(i).setValue(result.getReal() != scalar.getReal() ? 1 : 0); } else { throw new SBMLException(); } } }
/** * * @param scalarLHS * @param vectorRHS */ private void scalarVectorLt(ASTNode scalarLHS, ASTNode vectorRHS) { for (int i = 0; i < vectorRHS.getChildCount(); ++i) { ASTNode child = vectorRHS.getChild(i); child.compile(this); ASTNode result = getNode(); if (result.isVector()) { scalarVectorLt(scalarLHS, child); } else if (useId) { vectorRHS.replaceChild(i, ASTNode.lt(scalarLHS, result)); } else if (result.isNumber() && scalarLHS.isNumber()) { vectorRHS.getChild(i).setValue(result.getReal() >= scalarLHS.getReal() ? 1 : 0); } 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 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 * @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 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 */ 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)