@Override public TreeNode getChildAt(int i) { return getChild(i); // TODO - add semantics XMLNode ?? }
/** * @param math * @return */ public static boolean isVectorOperation(ASTNode math) { boolean hasVector = false; for (int i = 0; i < math.getChildCount(); ++i) { if (math.getChild(i).isVector()) { hasVector = true; break; } } return hasVector; }
/** * @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); } }
/** * Gets the left child of this node. * * @return the left child of this ASTNode. This is equivalent to * getChild(0); */ public ASTNode getLeftChild() { return getChild(0); }
/** * Recursively checks if a node is of type FUNCTION_SELECTOR. If so, * add to the list of selector nodes. * * @param math * @param listOfNodes */ private void getSelectorNodes(ASTNode math, List<ASTNode> listOfNodes) { if (math.getType() == ASTNode.Type.FUNCTION_SELECTOR) { listOfNodes.add(math); } for (int i = 0; i < math.getChildCount(); ++i) { getSelectorNodes(math.getChild(i), listOfNodes); } }
/** * Get the nth argument to this function. * * Callers should first find out the number of arguments to the function by * calling {@link #getArgumentCount()}. * * @param n * an integer index for the argument sought. * @return the nth argument (bound variable) passed to this * {@link FunctionDefinition}. */ public ASTNode getArgument(int n) { if (getArgumentCount() < n) { throw new IndexOutOfBoundsException(String.format( "No such argument with index {0,number,integer}.", n)); } return getMath().getChild(n); }
@Override public boolean check(ValidationContext ctx, ASTNode node) { if (node.getType() == ASTNode.Type.FUNCTION_RATE_OF) { // check that the child of a rateOf is a ci element. if (node.getChildCount() > 0 && !(node.getChild(0).getType().equals(ASTNode.Type.NAME))) { return false; } } return true; }
@Override public ASTNodeValue function(FunctionDefinition function, List<ASTNode> args) throws SBMLException { ASTNode lambda = function.getMath(); HashMap<String, ASTNodeValue> argValues = new HashMap<String, ASTNodeValue>(); for (int i = 0; i < args.size(); i++) { argValues.put(lambda.getChild(i).compile(this).toString(), args .get(i).compile(this)); } try { namesToUnits = argValues; ASTNodeValue value = lambda.getRightChild().compile(this); namesToUnits.clear(); return value; } catch (SBMLException e) { return new ASTNodeValue(this); } }
@Override public boolean check(ValidationContext ctx, ASTNode node) { // In comparator... if (node.isRelational() && node.getChildCount() > 0) { byte dt = ValidationTools.getDataType(node.getChild(0)); // all children must have same Type for (int i = 1; i < node.getNumChildren(); i++) { if (dt != ValidationTools.getDataType(node.getChild(i))) { return false; } } } return true; } };
@Override public ASTNodeValue selector(List<ASTNode> nodes) throws SBMLException { ASTNode object = nodes.get(0); ASTNode result; if (object.isVector()) { result = object; for (int i = 1; i < nodes.size(); ++i) { int index = (int) nodes.get(i).compile(this).toDouble(); result = result.getChild(index); } return result.compile(this); } else if (object.isVariable()) { compile(object.getVariable()); } else if (object.isString()) { compile(object.getName()); } return unknownValue(); }
/** * Replaces dimension id with the appropriate integer value. * * @param math * @param id * @param index */ private static void recursiveReplaceDimensionId(ASTNode math, String id, int index) { if (math.getChildCount() == 0) { if (math.isString() && math.getName().equals(id)) { math.setValue(index); } return; } for (int i = 0; i < math.getChildCount(); ++i) { recursiveReplaceDimensionId(math.getChild(i), id, index); } }
@Override public boolean check(ValidationContext ctx, ASTNode node) { // If is piecewise... if (node.isPiecewise() && node.getNumChildren() > 0) { byte dt = ValidationTools.getDataType(node.getLeftChild()); if (dt == ValidationTools.DT_STRING) { return false; } // all children must have same Type for (int i = 0; i < node.getNumChildren(); i += 2) { if (dt != ValidationTools.getDataType(node.getChild(i))) { return false; } } } return true; } };
/** * @param node * @param value */ private void updateASTNodeName(ASTNode node, int value) { if (node.isVector()) { for (int i = 0; i < node.getChildCount(); ++i) { ASTNode child = node.getChild(i); updateASTNodeName(child, value); } } else if (node.isName()) { node.setName("_" + String.valueOf(value) + node.getName()); } else { node.setName("unknown"); } }
/** * @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 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 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(); } } }