@Override public boolean check(ValidationContext ctx, ASTNode node) { // In operators... if (node.isOperator() || set.contains(node.getType())) { // all children must be numbers for (ASTNode n : node.getChildren()) { if (ValidationTools.getDataType(n) != ValidationTools.DT_NUMBER) { return false; } } } return true; }
/** * Returns {@code true} if the current ASTNode or any of his descendant has a unit * defined. * * @return {@code true} if the current ASTNode or any of his descendant has a unit * defined. */ public boolean hasUnits() { boolean hasUnits = isSetUnits(); if (!hasUnits) { for (ASTNode child : getChildren()) { hasUnits = child.hasUnits(); if (hasUnits) { break; } } } return hasUnits; }
/** * @param astNode */ private void compileUserFunction(ASTNode astNode) { try { writer.writeCharacters(indent); writer.writeStartElement(ASTNode.URI_MATHML_DEFINITION, "apply"); writer.writeCharacters("\n"); indent += " "; compileCi(astNode); for (ASTNode arg : astNode.getChildren()) { compile(arg); } writeEndElement(); } catch (XMLStreamException e) { e.printStackTrace(); } }
@Override public boolean check(ValidationContext ctx, ASTNode node) { // We don't validate inside FunctionDefinition if (node.getParentSBMLObject() instanceof FunctionDefinition) { return true; } // In logical operators... if (node.isLogical()) { // all children must be booleans for (ASTNode n : node.getChildren()) { if (!n.isBoolean()) { return false; } } } return true; } };
/** * Returns a simple tree view of the ASTNode internal, including mainly * node type and hierarchy. * * @param n * @param tree * @param indent * @return a simple tree view of the ASTNode internal */ public static String astNodeToTree(ASTNode n, String tree, String indent) { //tree = tree + indent + n.getType() + " " + // (n.isInteger() ? n.getInteger() : "") + (n.isReal() ? n.getReal() : "") + '\n'; tree = tree + indent + n.toSimpleString() + " unit:" + n.deriveUnit() + '\n'; for (ASTNode child : n.getChildren()) { tree = astNodeToTree(child, tree, indent + " "); } return tree; }
if (useId) { ASTNode piecewise = new ASTNode(ASTNode.Type.FUNCTION_PIECEWISE); piecewise.getChildren().addAll(compiledValues); setNode(piecewise); return dummy;
if (node.getChildCount() == 0) { double result = 1; node.getChildren().clear(); node.setType(ASTNode.Type.PLUS); if (values.size() > 0) {
boolean isResultSet = false; node.setType(ASTNode.Type.LOGICAL_XOR); node.getChildren().clear(); if (values.size() > 0) { for (int i = 0; i < values.size(); ++i) {
/** * @param values * @param vector * @throws SBMLException */ private void piecewiseRecursive(List<ASTNode> values, ASTNode vector) throws SBMLException{ if (!vector.isVector()) { vector.setType(ASTNode.Type.FUNCTION_PIECEWISE); vector.getChildren().clear(); for (ASTNode value : values) { vector.addChild(value); } return; } for (int i = 0; i < vector.getChildCount(); ++i) { List<ASTNode> children = new ArrayList<ASTNode>(); for (ASTNode value : values) { if (value.getChildCount() == 0) { children.add(value.clone()); } else if (value.isVector()) { if (value.getChildCount() != vector.getChildCount()) { throw new SBMLException(); } children.add(value.getChild(i).clone()); } } piecewiseRecursive(children, vector.getChild(i)); } } /* (non-Javadoc)
boolean isResultSet = false; node.setType(ASTNode.Type.LOGICAL_OR); node.getChildren().clear(); if (values.size() > 0) { for (int i = 0; i < values.size(); ++i) {
/** * 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(); } }
double result = 0; node.getChildren().clear();
if (useId) { node.setType(ASTNode.Type.FUNCTION_POWER); node.getChildren().clear(); node.addChild(left); node.addChild(right);
if (useId) { node.setType(ASTNode.Type.RELATIONAL_LT); node.getChildren().clear(); node.addChild(left); node.addChild(right);
if (useId) { node.setType(ASTNode.Type.RELATIONAL_GT); node.getChildren().clear(); node.addChild(left); node.addChild(right);
if (useId) { node.setType(ASTNode.Type.RELATIONAL_LEQ); node.getChildren().clear(); node.addChild(left); node.addChild(right);
if (useId) { node.setType(ASTNode.Type.RELATIONAL_EQ); node.getChildren().clear(); node.addChild(left); node.addChild(right);
if (useId) { node.setType(ASTNode.Type.RELATIONAL_GEQ); node.getChildren().clear(); node.addChild(left); node.addChild(right);
if (useId) { node.setType(ASTNode.Type.RELATIONAL_NEQ); node.getChildren().clear(); node.addChild(left); node.addChild(right);
if (useId) { node.setType(ASTNode.Type.RATIONAL); node.getChildren().clear(); node.addChild(left); node.addChild(right);