/** * @param arg */ private void compileBvar(ASTNode arg) { try { writer.writeCharacters(indent); writer.writeStartElement(ASTNode.URI_MATHML_DEFINITION, "bvar"); writer.writeCharacters("\n"); indent += " "; if (!arg.isString()) { logger.warn("compileBvar: can only have node of type NAME there !!!!"); } compileCi(arg); writeEndElement(); } catch (XMLStreamException e) { e.printStackTrace(); } }
/** * Returns a set of all the {@link NamedSBase} referenced on this node and * all his descendant. * * Just for testing purposes... * * @return a set of all the {@link NamedSBase} referenced on this node and * all his descendant. */ public Set<SBase> getReferencedNamedSBases() { Set<SBase> l = new HashSet<SBase>(); if (isString()) { if (getVariable() != null) { l.add(getVariable()); } else { logger.warn(MessageFormat.format( resourceBundle.getString("ASTNode.getReferencedNamedSBases"), getName())); } } for (ASTNode child : listOfNodes) { l.addAll(child.getReferencedNamedSBases()); } return l; }
/** * Get the argument named name to this {@link FunctionDefinition}. * * @param name * the exact name (case-sensitive) of the sought-after argument * @return the argument (bound variable) having the given name, or null if * no such argument exists. */ public ASTNode getArgument(String name) { ASTNode arg = null; for (int i = 0; i < getArgumentCount(); i++) { arg = getArgument(i); if (arg.isString() && arg.getName().equals(name)) { return arg; } } return null; }
/** * Returns {@code true} if this node or one of its descendants contains some * identifier with the given id. This method can be used to scan a formula * for a specific parameter or species and detect whether this component is * used by this formula. This search is done using a DFS. * * @param id * the id of an SBML element. * @return {@code true} if this node or one of its descendants contains the * given id. */ public boolean refersTo(String id) { if (isString() && (getName() != null) && getName().equals(id)) { return true; } boolean childContains = false; for (ASTNode child : listOfNodes) { childContains |= child.refersTo(id); } return childContains; }
/** * @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; } }
/** * @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); } }
/** * Replaces occurrences of a name within this ASTNode with the * name/value/formula represented by the second argument ASTNode, e.g., if * the formula in this ASTNode is x + y; bvar is x and arg is an ASTNode * representing the real value 3 ReplaceArgument substitutes 3 for x within * this ASTNode. * * @param bvar * a string representing the variable name to be substituted * @param arg * an ASTNode representing the name/value/formula to substitute */ public void replaceArgument(String bvar, ASTNode arg) { int n = 0; for (ASTNode child : listOfNodes) { if (child.isString() && child.getName().equals(bvar)) { replaceChild(n, arg.clone()); } else if (child.getChildCount() > 0) { child.replaceArgument(bvar, arg); } n++; } }
/** * 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); } }
/** * 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 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(); }
if ((node.getChildCount() == 0) && (node.isString()) && (node.getType() != Type.NAME_TIME) &&
/** * For a better performance {@link ASTNode}s can store a direct pointer to a * variable element. This is particularly useful when performing more * complex computation on these data structures. However, if the model is * changed, it may happen that these pointer become invalid. For instance, a * previously local parameter may be added to the model in form of a global * parameter while keeping the same identifier. The local parameter may then * be removed. Whenever performing changes like this, you may want to update * pointers within {@link ASTNode} constructs as well. */ public void updateVariables() { if (isString()) { if (variable != null) { CallableSBase oldValue = getVariable(); name = variable.getId(); variable = null; variable = getVariable(); firePropertyChange(TreeNodeChangeEvent.variable, oldValue, variable); } else if ((type != Type.NAME_TIME) && (type != Type.NAME_AVOGADRO)) { // Try to register a direct link to the variable (if the name represent one). variable = getVariable(); } } for (ASTNode child : getChildren()) { child.updateVariables(); } }
if (node.isString()) { String id = node.toString(); SBase sbase = model.findNamedSBase(id);
if (arg.isString()) { math = replaceMath(math, arg.toString(), args.get(i)); } else {
else if (node.isString()) { String id = node.toString(); SBase sbase = model.findNamedSBase(id);
if (arg != null && arg.isString() && arg.getName() != null && body.getName() != null)
return true; if (isString()) { if ((type == Type.NAME_TIME) && (isSetParentSBMLObject())) { Model model = getParentSBMLObject().getModel();