From: <nik...@us...> - 2012-08-17 10:25:17
|
Revision: 1369 http://jsbml.svn.sourceforge.net/jsbml/?rev=1369&view=rev Author: niko-rodrigue Date: 2012-08-17 10:25:11 +0000 (Fri, 17 Aug 2012) Log Message: ----------- added a new method to ASTNode to check if an ASTNode is a Variable node to resolve tracker item #3537210 Modified Paths: -------------- trunk/core/src/org/sbml/jsbml/ASTNode.java Modified: trunk/core/src/org/sbml/jsbml/ASTNode.java =================================================================== --- trunk/core/src/org/sbml/jsbml/ASTNode.java 2012-08-17 10:22:01 UTC (rev 1368) +++ trunk/core/src/org/sbml/jsbml/ASTNode.java 2012-08-17 10:25:11 UTC (rev 1369) @@ -2434,14 +2434,14 @@ /** * Returns the variable of this node. This function should be called only - * when {@link #isString()} == <code>true</code>, otherwise and Exception is thrown. + * when {@link #isVariable()} == <code>true</code>, otherwise an Exception is thrown. * * @return the variable of this node * @throws IllegalArgumentException - * if {@link #isString()} returns false. + * if {@link #isVariable()} returns false. */ public CallableSBase getVariable() { - if ((type == Type.NAME) || (type == Type.FUNCTION)) { + if (isVariable()) { if ((variable == null) && (getParentSBMLObject() != null)) { if (getParentSBMLObject() instanceof KineticLaw) { variable = ((KineticLaw) getParentSBMLObject()) @@ -2968,6 +2968,15 @@ } /** + * Returns true if this node represents a {@link Variable}. + * + * @return true if this node represents a {@link Variable}. + */ + public boolean isVariable() { + return type == Type.NAME || type == Type.FUNCTION; + } + + /** * Returns true if this node represents the number zero (either as integer * or as real value). * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nik...@us...> - 2012-08-19 00:16:21
|
Revision: 1388 http://jsbml.svn.sourceforge.net/jsbml/?rev=1388&view=rev Author: niko-rodrigue Date: 2012-08-19 00:16:15 +0000 (Sun, 19 Aug 2012) Log Message: ----------- some bugs corrections to ASTNode + some questions for some other potential problems Modified Paths: -------------- trunk/core/src/org/sbml/jsbml/ASTNode.java Modified: trunk/core/src/org/sbml/jsbml/ASTNode.java =================================================================== --- trunk/core/src/org/sbml/jsbml/ASTNode.java 2012-08-19 00:11:56 UTC (rev 1387) +++ trunk/core/src/org/sbml/jsbml/ASTNode.java 2012-08-19 00:16:15 UTC (rev 1388) @@ -1186,7 +1186,7 @@ /** * Child nodes. */ - private LinkedList<ASTNode> listOfNodes; + private LinkedList<ASTNode> listOfNodes; // TODO : for jsbml 1.0, we should replace that by a simple ArrayList that is much quicker ?? /** * A {@link Logger} for this class. @@ -1266,9 +1266,9 @@ this.exponent = astNode.exponent; this.mantissa = astNode.mantissa; this.name = astNode.name == null ? null : new String(astNode.name); - this.variable = astNode.variable; + this.variable = astNode.variable; // TODO : should we clone the variable this.numerator = astNode.numerator; - this.parent = astNode.getParent(); + this.parent = astNode.getParent(); // This should not be done is the parent is not of the class ASTNode, I think ? this.unitId = astNode.unitId == null ? null : new String(astNode.unitId); for (ASTNode child : astNode.listOfNodes) { @@ -1476,6 +1476,7 @@ public void addChild(ASTNode child) { listOfNodes.add(child); child.parent = this; + setParentSBMLObject(child, parentSBMLObject, 0); child.fireNodeAddedEvent(); } @@ -1503,6 +1504,8 @@ } if (!(astnode.isOne() && (operator == Type.TIMES || operator == Type.DIVIDE))) { ASTNode swap = new ASTNode(type, getParentSBMLObject()); + // TODO : We should do a clone of the ASTNode of the ASTNode here ?? That would guaranty that everything is duplicated properly + // here userObjects are not for example, I think, not entirely sure if they should swap.denominator = denominator; swap.exponent = exponent; swap.mantissa = mantissa; @@ -1803,7 +1806,7 @@ } else { logger.warn(String.format( "ASTNode of type FUNCTION but the variable is null: (%s, %s)! Check that your object is linked to a Model.", - getName(), getParentSBMLObject().getElementName())); + getName(), (getParentSBMLObject() != null ? getParentSBMLObject().getElementName() : null))); value = compiler.function(getName(), getChildren()); } break; @@ -2456,12 +2459,18 @@ // different kinetic law. variable = null; } else if (variable == null) { + // Could be any L3 package elements + // that is not a CallableSBase + // variable = m.findNamedSBase(getName()); + /* * Possibly the name is just from the argument list * of some function definition. Hence, it won't be * possible to determine an element with the same * identifier within the model. In this case, this * warning is kind of senseless. + * + * TODO : we could test if the parent is a FunctionDefinition or not to print a warning or nothing ? */ logger.debug(String.format( "This ASTNode with name '%s' is not linked to the model, the variable attribute is left to null!", @@ -2476,7 +2485,7 @@ } return variable; } - throw new IllegalArgumentException("getVariable() should be called only when isName() == true."); + throw new IllegalArgumentException("getVariable() should be called only when isVariable() == true."); } /* (non-Javadoc) @@ -2562,7 +2571,7 @@ if (listOfNodes == null) { listOfNodes = new LinkedList<ASTNode>(); } else { - listOfNodes.clear(); + listOfNodes.clear(); // TODO : send a nodeRemove event for each child ? We should set parent and parentSBMLObject to null as well ? } variable = null; mantissa = Double.NaN; @@ -2581,6 +2590,8 @@ */ public void insertChild(int n, ASTNode newChild) { listOfNodes.add(n, newChild); + newChild.parent = this; + setParentSBMLObject(newChild, parentSBMLObject, 0); newChild.fireNodeAddedEvent(); } @@ -3129,6 +3140,8 @@ */ public void prependChild(ASTNode child) { listOfNodes.addLast(child); + child.parent = this; + setParentSBMLObject(child, parentSBMLObject, 0); child.fireNodeAddedEvent(); } @@ -3187,6 +3200,7 @@ */ // TODO : should we return an exception to tell people that the method is // not complete ? + // So Exception or not for this method ??? This is called from #arithmeticOperation (called by some public methods) and multiplyWith (this one is public) private void reduceToBinary() { if (getChildCount() > 2) { int i; @@ -3280,6 +3294,7 @@ public boolean removeChild(int n) { if ((listOfNodes.size() > n) && (n >= 0)) { ASTNode removed = listOfNodes.remove(n); + removed.parentSBMLObject = null; removed.fireNodeRemovedEvent(); return true; } @@ -3320,6 +3335,8 @@ * @return the element previously at the specified position */ public ASTNode replaceChild(int n, ASTNode newChild) { + // TODO : we should probably remove the previous child properly before and fire 2 events ?? + setParentSBMLObject(newChild, parentSBMLObject, 0); newChild.parent = this; return listOfNodes.set(n, newChild); @@ -3426,7 +3443,7 @@ // TODO : javadoc not synchronized with the code, we are not using // isOperator() or isNumber() but may be we should. public void setName(String name) { - String oldValue = this.name; + String oldValue = this.name; // TODO : if oldValue != null ==> set variable = null or update it ?? this.name = name; this.firePropertyChange(TreeNodeChangeEvent.name, oldValue, name); if ((!type.toString().startsWith("NAME")) && type != Type.FUNCTION @@ -3690,9 +3707,13 @@ * node's children */ public void swapChildren(ASTNode that) { + // TODO : not sure that the parent/parentSBMLObject will be set properly after this call + // What about nodeRemove, nodeAdded events ?? + // The method is public, so could be called with an ASTNode coming from anywhere !! + LinkedList<ASTNode> swap = that.listOfNodes; that.listOfNodes = listOfNodes; - listOfNodes = swap; + listOfNodes = swap; this.firePropertyChange(TreeNodeChangeEvent.childNode, that.listOfNodes, this.listOfNodes); that.firePropertyChange(TreeNodeChangeEvent.childNode, this.listOfNodes, that.listOfNodes); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <and...@us...> - 2012-08-21 14:02:17
|
Revision: 1393 http://jsbml.svn.sourceforge.net/jsbml/?rev=1393&view=rev Author: andreas-draeger Date: 2012-08-21 14:02:06 +0000 (Tue, 21 Aug 2012) Log Message: ----------- Minor improvements in comments. Modified Paths: -------------- trunk/core/src/org/sbml/jsbml/ASTNode.java Modified: trunk/core/src/org/sbml/jsbml/ASTNode.java =================================================================== --- trunk/core/src/org/sbml/jsbml/ASTNode.java 2012-08-21 14:01:51 UTC (rev 1392) +++ trunk/core/src/org/sbml/jsbml/ASTNode.java 2012-08-21 14:02:06 UTC (rev 1393) @@ -1102,21 +1102,21 @@ } /** - * Creates an ASTNode of type times and adds the given nodes as children. + * Creates an {@link ASTNode} of type times and adds the given nodes as children. * * @param ast - * @return an ASTNode of type times and adds the given nodes as children. + * @return an {@link ASTNode} of type times and adds the given nodes as children. */ public static ASTNode times(ASTNode... ast) { return arithmethicOperation(Type.TIMES, ast); } /** - * Multiplies several NamedSBase objects. + * Multiplies several {@link CallableSBase} objects. * * @param parent * @param sbase - * @return the multiplication of several NamedSBase objects. + * @return the multiplication of several {@link CallableSBase} objects. */ public static ASTNode times(MathContainer parent, CallableSBase... sbase) { @@ -3206,7 +3206,7 @@ } /** - * Raises this ASTNode by the power of the given number. + * Raises this {@link ASTNode} by the power of the given number. * * @param exponent * a double number. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <and...@us...> - 2013-03-19 07:40:37
|
Revision: 1470 http://jsbml.svn.sourceforge.net/jsbml/?rev=1470&view=rev Author: andreas-draeger Date: 2013-03-19 07:40:27 +0000 (Tue, 19 Mar 2013) Log Message: ----------- Improved the raiseByThePowerOf(double) method: It now checks if the given value is an integer and also sets the units of the exponent to dimensionless if Level >= 3. Modified Paths: -------------- trunk/core/src/org/sbml/jsbml/ASTNode.java Modified: trunk/core/src/org/sbml/jsbml/ASTNode.java =================================================================== --- trunk/core/src/org/sbml/jsbml/ASTNode.java 2013-03-18 15:01:27 UTC (rev 1469) +++ trunk/core/src/org/sbml/jsbml/ASTNode.java 2013-03-19 07:40:27 UTC (rev 1470) @@ -340,7 +340,7 @@ * */ UNKNOWN; - + /** * Returns the {@link Type} corresponding to the given {@link String}. * @@ -543,7 +543,7 @@ } } - + /** * Message to indicate that an {@link ASTNode.Type} type has been chosen * which cannot be used as an operator. @@ -559,17 +559,17 @@ * The URI for the definition of the csymbol for avogadro. */ public static final transient String URI_AVOGADRO_DEFINITION = "http://www.sbml.org/sbml/symbols/avogadro"; - + /** * The URI for the definition of the csymbol for delay. */ public static final transient String URI_DELAY_DEFINITION = "http://www.sbml.org/sbml/symbols/delay"; - + /** * URI for the definition of MathML. */ public static final transient String URI_MATHML_DEFINITION = "http://www.w3.org/1998/Math/MathML"; - + // TODO: check how we set the math in level 1 /** @@ -620,38 +620,38 @@ * @return a new {@link ASTNode} of type <code>operator</code> and adds the given nodes as children. */ private static ASTNode arithmethicOperation(Type operator, ASTNode... ast) { - LinkedList<ASTNode> astList = new LinkedList<ASTNode>(); - if (ast != null) { - for (ASTNode node : ast) { - if ((node != null) - && !((operator == Type.TIMES) && node.isOne() && (ast.length > 1))) { - astList.add(node); - } - } - } - if (astList.size() == 0) { - return null; - } - if (astList.size() == 1) { - return astList.getFirst().clone(); - } - if ((operator == Type.PLUS) || (operator == Type.MINUS) - || (operator == Type.TIMES) || (operator == Type.DIVIDE) - || (operator == Type.POWER)) { - MathContainer mc = astList.getFirst().parentSBMLObject; - ASTNode arithmetic = new ASTNode(operator, mc); - for (ASTNode nodes : astList) { - arithmetic.addChild(nodes); - setParentSBMLObject(nodes, mc, 0); - } - if (arithmetic.getChildCount() > 2) { - arithmetic.reduceToBinary(); - } - return arithmetic; - } else { - throw new IllegalArgumentException(String.format( - INVALID_OPERATOR_MSG, operator)); - } + LinkedList<ASTNode> astList = new LinkedList<ASTNode>(); + if (ast != null) { + for (ASTNode node : ast) { + if ((node != null) + && !((operator == Type.TIMES) && node.isOne() && (ast.length > 1))) { + astList.add(node); + } + } + } + if (astList.size() == 0) { + return null; + } + if (astList.size() == 1) { + return astList.getFirst().clone(); + } + if ((operator == Type.PLUS) || (operator == Type.MINUS) + || (operator == Type.TIMES) || (operator == Type.DIVIDE) + || (operator == Type.POWER)) { + MathContainer mc = astList.getFirst().parentSBMLObject; + ASTNode arithmetic = new ASTNode(operator, mc); + for (ASTNode nodes : astList) { + arithmetic.addChild(nodes); + setParentSBMLObject(nodes, mc, 0); + } + if (arithmetic.getChildCount() > 2) { + arithmetic.reduceToBinary(); + } + return arithmetic; + } else { + throw new IllegalArgumentException(String.format( + INVALID_OPERATOR_MSG, operator)); + } } /** @@ -785,7 +785,7 @@ public static ASTNode gt(ASTNode left, ASTNode right) { return relational(Type.RELATIONAL_GT, left, right); } - + /** * Creates an {@link ASTNode} representing less or equal for * the two given left and right child. @@ -798,7 +798,7 @@ public static ASTNode leq(ASTNode left, ASTNode right) { return relational(Type.RELATIONAL_LEQ, left, right); } - + /** * Creates an {@link ASTNode} representing a logarithm to base 10 of the given value. * @@ -850,7 +850,7 @@ public static ASTNode lt(ASTNode left, ASTNode right) { return relational(Type.RELATIONAL_LT, left, right); } - + /** * Creates an {@link ASTNode} that performs a less than comparison between a * variable and another {@link ASTNode}. The parent SBML object will be @@ -864,7 +864,7 @@ public static ASTNode lt(String variable, ASTNode node) { return lt(new ASTNode(variable, node.getParentSBMLObject()), node); } - + /** * Creates an {@link ASTNode} that performs a not equal comparison between * two {@link ASTNode}s. @@ -993,7 +993,7 @@ } catch (XMLStreamException e) { e.printStackTrace(); } - + return null; } @@ -1160,7 +1160,7 @@ * so we need to store the attribute value. */ private String definitionURL; - + /** * */ @@ -1192,14 +1192,14 @@ * A {@link Logger} for this class. */ private static transient final Logger logger = Logger.getLogger(ASTNode.class); - + /** * The part of a number in scientific format (with an E) that is on the left * side of the E (the prefix of the number). For instance, in the number * 3.5E-2.7 the mantissa is 3.5. */ private double mantissa; - + /** * If no NamedSBase object exists or can be identified when * {@link #setName(String)} is called, the given name is stored in this @@ -1255,28 +1255,28 @@ * the {@link ASTNode} to be copied. */ public ASTNode(ASTNode astNode) { - super(astNode); - this.parentSBMLObject = null; - this.initDefaults(); + super(astNode); + this.parentSBMLObject = null; + this.initDefaults(); - logger.debug("Clone constructor: Origin type = " + astNode.type); + logger.debug("Clone constructor: Origin type = " + astNode.type); - setType(astNode.getType()); - this.denominator = astNode.denominator; - this.exponent = astNode.exponent; - this.mantissa = astNode.mantissa; - this.name = astNode.name == null ? null : new String(astNode.name); - this.variable = null; // the clone is not linked anymore to any model so we cannot have any 'variable' set - this.numerator = astNode.numerator; - this.unitId = astNode.unitId == null ? null : new String(astNode.unitId); + setType(astNode.getType()); + this.denominator = astNode.denominator; + this.exponent = astNode.exponent; + this.mantissa = astNode.mantissa; + this.name = astNode.name == null ? null : new String(astNode.name); + this.variable = null; // the clone is not linked anymore to any model so we cannot have any 'variable' set + this.numerator = astNode.numerator; + this.unitId = astNode.unitId == null ? null : new String(astNode.unitId); - if (astNode.getChildCount() > 0) { - for (ASTNode child : astNode.listOfNodes) { - ASTNode c = child.clone(); - c.parent = this; - this.listOfNodes.add(c); - } - } + if (astNode.getChildCount() > 0) { + for (ASTNode child : astNode.listOfNodes) { + ASTNode c = child.clone(); + c.parent = this; + this.listOfNodes.add(c); + } + } } /** @@ -1331,7 +1331,7 @@ this(Type.REAL); setValue(real); } - + /** * Creates and returns a new {@link ASTNode}. * @@ -1354,7 +1354,7 @@ this(Type.REAL_E, parent); setValue(mantissa, exponent); } - + /** * Creates and returns a new {@link ASTNode}. * @@ -1365,43 +1365,43 @@ this(Type.REAL, parent); setValue(real); } - - /** - * Creates and returns a new {@link ASTNode} with the given integer value. - * - * @param integer - */ + + /** + * Creates and returns a new {@link ASTNode} with the given integer value. + * + * @param integer + */ public ASTNode(int integer) { this(integer, null); } - - /** - * Creates and returns a new {@link ASTNode} with the given integer value for - * the - * given {@link MathContainer} as its parent SBML object. - * - * @param integer - * @param parent - */ + + /** + * Creates and returns a new {@link ASTNode} with the given integer value for + * the + * given {@link MathContainer} as its parent SBML object. + * + * @param integer + * @param parent + */ public ASTNode(int integer, MathContainer parent) { this(integer, null, parent); } - - /** - * Creates and returns a new {@link ASTNode} with the given integer value with - * the given associated {@link #unitId} for the - * given {@link MathContainer} as its parent SBML object. - * - * @param integer - * @param unitsID - * @param parent - */ + + /** + * Creates and returns a new {@link ASTNode} with the given integer value with + * the given associated {@link #unitId} for the + * given {@link MathContainer} as its parent SBML object. + * + * @param integer + * @param unitsID + * @param parent + */ public ASTNode(int integer, String unitsID, MathContainer parent) { - this(Type.INTEGER, parent); - setValue(integer); - if (unitsID != null) { - setUnits(unitsID); - } + this(Type.INTEGER, parent); + setValue(integer); + if (unitsID != null) { + setUnits(unitsID); + } } /** @@ -1418,10 +1418,10 @@ this(); parentSBMLObject = parent; if (parentSBMLObject != null) { - addAllChangeListeners(parent.getListOfTreeNodeChangeListeners()); + addAllChangeListeners(parent.getListOfTreeNodeChangeListeners()); } } - + /** * Creates and returns a new {@link ASTNode} with the given name. * @@ -1454,7 +1454,7 @@ this(); setType(type); } - + /** * Creates and returns a new {@link ASTNode}. * @@ -1481,32 +1481,32 @@ child.fireNodeAddedEvent(); } - - /** - * Creates a new node with the type of this node, moves all children of this - * node to this new node, sets the type of this node to the given operator, - * adds the new node as left child of this node and the given {@link ASTNode} as the - * right child of this node. The parentSBMLObject of the whole resulting - * {@link ASTNode} is then set to the parent of this node. - * - * @param operator - * The new type of this node. This has to be one of the - * following: {@link Type#PLUS}, {@link Type#MINUS}, {@link Type#TIMES}, - * {@link Type#DIVIDE}, {@link Type#POWER}, - * {@link Type#FUNCTION_ROOT}. Otherwise an - * {@link IllegalArgumentException} is thrown. - * @param astnode - * The new right child of this node - * @throws IllegalArgumentException - * if - * <ul> - * <li>this {@link ASTNode} is zero ({@link #isZero()}) and the given - * operator is {@link Type#DIVIDE}</li> - * <li>the operator is not one of the following: {@link Type#PLUS}, - * {@link Type#MINUS}, {@link Type#TIMES}, {@link Type#DIVIDE}, - * {@link Type#POWER}, {@link Type#FUNCTION_ROOT}</li> - * </ul> - */ + + /** + * Creates a new node with the type of this node, moves all children of this + * node to this new node, sets the type of this node to the given operator, + * adds the new node as left child of this node and the given {@link ASTNode} as the + * right child of this node. The parentSBMLObject of the whole resulting + * {@link ASTNode} is then set to the parent of this node. + * + * @param operator + * The new type of this node. This has to be one of the + * following: {@link Type#PLUS}, {@link Type#MINUS}, {@link Type#TIMES}, + * {@link Type#DIVIDE}, {@link Type#POWER}, + * {@link Type#FUNCTION_ROOT}. Otherwise an + * {@link IllegalArgumentException} is thrown. + * @param astnode + * The new right child of this node + * @throws IllegalArgumentException + * if + * <ul> + * <li>this {@link ASTNode} is zero ({@link #isZero()}) and the given + * operator is {@link Type#DIVIDE}</li> + * <li>the operator is not one of the following: {@link Type#PLUS}, + * {@link Type#MINUS}, {@link Type#TIMES}, {@link Type#DIVIDE}, + * {@link Type#POWER}, {@link Type#FUNCTION_ROOT}</li> + * </ul> + */ private void arithmeticOperation(Type operator, ASTNode astnode) { if ((operator == Type.PLUS) || (operator == Type.MINUS) || (operator == Type.TIMES) || (operator == Type.DIVIDE) @@ -1515,24 +1515,24 @@ throw new IllegalArgumentException("Cannot divide by zero."); } if (!(astnode.isOne() && ((operator == Type.TIMES) || (operator == Type.DIVIDE)))) { - /* - * Here we want to restructure the tree by making an equivalent of the current node - * being a child of the current node. This node will then become of some different type. - * - * In order to avoid deep-cloning we save a pointer to the children, remove all - * children, clone this current node, and add all children to the copy. At the end, - * the copied node will become some child of the current node - */ - List<ASTNode> children = listOfNodes; - listOfNodes = null; - ASTNode swap = clone(); // only clones the current node, no children + /* + * Here we want to restructure the tree by making an equivalent of the current node + * being a child of the current node. This node will then become of some different type. + * + * In order to avoid deep-cloning we save a pointer to the children, remove all + * children, clone this current node, and add all children to the copy. At the end, + * the copied node will become some child of the current node + */ + List<ASTNode> children = listOfNodes; + listOfNodes = null; + ASTNode swap = clone(); // only clones the current node, no children listOfNodes = children; - - /* - * TODO: What should be done to userObjects? Actually it can be assumed - * that these apply to the swap node only and maybe all user objects - * should be removed from the current node? - */ + + /* + * TODO: What should be done to userObjects? Actually it can be assumed + * that these apply to the swap node only and maybe all user objects + * should be removed from the current node? + */ swapChildren(swap); setType(operator); if (operator == Type.FUNCTION_ROOT) { @@ -1591,9 +1591,9 @@ case INTEGER: value = compiler.compile(getInteger(), getUnits()); break; - /* - * Operators - */ + /* + * Operators + */ case POWER: value = compiler.pow(getLeftChild(), getRightChild()); break; @@ -1618,8 +1618,8 @@ int childCount = getChildCount(); if (childCount != 2) { throw new SBMLException(MessageFormat.format( - "Fractions must have one numerator and one denominator, here {0,number,integer} elements are given.", - childCount)); + "Fractions must have one numerator and one denominator, here {0,number,integer} elements are given.", + childCount)); } value = compiler.frac(getLeftChild(), getRightChild()); break; @@ -1633,9 +1633,9 @@ value = compiler.delay(getName(), getLeftChild(), getRightChild(), getUnits()); break; - /* - * Names of identifiers: parameters, functions, species etc. - */ + /* + * Names of identifiers: parameters, functions, species etc. + */ case NAME: if (variable == null) { variable = getVariable(); @@ -1651,9 +1651,9 @@ value = compiler.compile(getName()); } break; - /* - * Type: pi, e, true, false, Avogadro - */ + /* + * Type: pi, e, true, false, Avogadro + */ case CONSTANT_PI: value = compiler.getConstantPi(); break; @@ -1673,9 +1673,9 @@ value = compiler.compile(getMantissa(), getExponent(), isSetUnits() ? getUnits() : null); break; - /* - * Basic Functions - */ + /* + * Basic Functions + */ case FUNCTION_LOG: if (getChildCount() == 2) { value = compiler.log(getLeftChild(), getRightChild()); @@ -1812,11 +1812,11 @@ getChildren()); } else { logger - .warn("ASTNode of type FUNCTION but the variable is not a FunctionDefinition! (" - + getName() - + ", " - + getParentSBMLObject().getElementName() - + ")"); + .warn("ASTNode of type FUNCTION but the variable is not a FunctionDefinition! (" + + getName() + + ", " + + getParentSBMLObject().getElementName() + + ")"); throw new SBMLException( "ASTNode of type FUNCTION but the variable is not a FunctionDefinition! (" + getName() + ", " + getParentSBMLObject().getElementName() @@ -1825,8 +1825,8 @@ } } else { logger.warn(MessageFormat.format( - "ASTNode of type FUNCTION but the variable is null: ({0}, {1})! Check that your object is linked to a Model.", - getName(), (getParentSBMLObject() != null ? getParentSBMLObject().getElementName() : null))); + "ASTNode of type FUNCTION but the variable is null: ({0}, {1})! Check that your object is linked to a Model.", + getName(), (getParentSBMLObject() != null ? getParentSBMLObject().getElementName() : null))); value = compiler.function(getName(), getChildren()); } break; @@ -1839,9 +1839,9 @@ value = compiler.lambda(getChildren()); value.setUIFlag(getChildCount() <= 1); break; - /* - * Logical and relational functions - */ + /* + * Logical and relational functions + */ case LOGICAL_AND: value = compiler.and(getChildren()); value.setUIFlag(getChildCount() <= 1); @@ -1907,16 +1907,16 @@ return true; } if (isString()) { - if ((type == Type.NAME_TIME) && (isSetParentSBMLObject())) { - Model model = getParentSBMLObject().getModel(); - if ((model != null) && model.isSetTimeUnits()) { - return false; - } - } else if ((type == Type.NAME_AVOGADRO) || (getVariable() != null) - && (!getVariable().containsUndeclaredUnits())) { - return false; - } - return true; + if ((type == Type.NAME_TIME) && (isSetParentSBMLObject())) { + Model model = getParentSBMLObject().getModel(); + if ((model != null) && model.isSetTimeUnits()) { + return false; + } + } else if ((type == Type.NAME_AVOGADRO) || (getVariable() != null) + && (!getVariable().containsUndeclaredUnits())) { + return false; + } + return true; } } else { for (ASTNode child : getListOfNodes()) { @@ -1928,7 +1928,7 @@ return false; } - /** + /** * Evaluates recursively this ASTNode and creates a new UnitDefinition with * respect of all referenced elements. * @@ -1979,15 +1979,15 @@ if (equal) { ASTNode ast = (ASTNode) object; equal &= ast.getType() == type; - + if (isInteger() && ast.isInteger()) { equal &= ast.getInteger() == getInteger(); } if (isString() && ast.isString()) { - equal &= ast.isSetName() == isSetName(); - if (equal && isSetName()) { - equal &= ast.getName().equals(getName()); - } + equal &= ast.isSetName() == isSetName(); + if (equal && isSetName()) { + equal &= ast.getName().equals(getName()); + } } if (isRational() && ast.isRational()) { equal &= ast.getNumerator() == getNumerator() @@ -1999,7 +1999,7 @@ } else if (isReal() && ast.isReal()) { equal &= ast.getReal() == getReal(); } - + equal &= isSetClassName() == ast.isSetClassName(); if (equal && isSetClassName()) { equal &= getClassName().equals(ast.getClassName()); @@ -2113,7 +2113,7 @@ public int getChildCount() { return listOfNodes == null ? 0 : listOfNodes.size(); } - + /** * Returns the list of children of the current ASTNode. * @@ -2332,8 +2332,8 @@ if (isReal() || (type == Type.CONSTANT_E) || (type == Type.CONSTANT_PI) || (type == Type.NAME_AVOGADRO)) { switch (type) { case NAME_AVOGADRO: - // TODO: in case that there will be different values for this constant in later versions, we will need a LV check here. - return Maths.AVOGADRO_L3V1; + // TODO: in case that there will be different values for this constant in later versions, we will need a LV check here. + return Maths.AVOGADRO_L3V1; case REAL: return mantissa; case REAL_E:{ @@ -2431,28 +2431,28 @@ * @return A {@link UnitDefinition} or {@code null}. */ public UnitDefinition getUnitsInstance() { - MathContainer parent = getParentSBMLObject(); - int level = parent != null ? parent.getLevel() : -1; - int version = parent != null ? parent.getVersion() : -1; - if (!isSetUnits() || (getParentSBMLObject() == null)) { - if (isName()) { - CallableSBase variable = getVariable(); - if (variable != null) { - return variable.getDerivedUnitDefinition(); - } else if (isConstant()) { - UnitDefinition ud = new UnitDefinition(level, level); - ud.addUnit(Unit.Kind.DIMENSIONLESS); - return ud; - } - } - return null; - } - if (Unit.Kind.isValidUnitKindString(getUnits(), level, version)) { - return UnitDefinition.getPredefinedUnit(getUnits(), level, version); - } else if (getParentSBMLObject().getModel() == null) { - return null; - } - return getParentSBMLObject().getModel().getUnitDefinition(getUnits()); + MathContainer parent = getParentSBMLObject(); + int level = parent != null ? parent.getLevel() : -1; + int version = parent != null ? parent.getVersion() : -1; + if (!isSetUnits() || (getParentSBMLObject() == null)) { + if (isName()) { + CallableSBase variable = getVariable(); + if (variable != null) { + return variable.getDerivedUnitDefinition(); + } else if (isConstant()) { + UnitDefinition ud = new UnitDefinition(level, level); + ud.addUnit(Unit.Kind.DIMENSIONLESS); + return ud; + } + } + return null; + } + if (Unit.Kind.isValidUnitKindString(getUnits(), level, version)) { + return UnitDefinition.getPredefinedUnit(getUnits(), level, version); + } else if (getParentSBMLObject().getModel() == null) { + return null; + } + return getParentSBMLObject().getModel().getUnitDefinition(getUnits()); } /** @@ -2465,60 +2465,60 @@ */ public CallableSBase getVariable() { if (isVariable()) { - if (variable == null) { - /* - * Possibly the name is just from the argument list - * of some function definition. Hence, it won't be - * possible to determine an element with the same - * identifier within the model. In this case, this - * warning is kind of senseless. - */ - TreeNode parent = getParent(); - if ((parent != null) && (parent instanceof ASTNode)) { - ASTNode parentNode = (ASTNode) parent; - if ((parentNode.getType() == Type.LAMBDA) && (parentNode.getRightChild() != this)) { - /* - * The second condition is important, because the argument list - * comprises only the first n children. Child n + 1 is the - * expression for the function. - */ - logger.debug(MessageFormat.format( - "The name \"{0}\" represented by this node is an argument in a function call, i.e., a placeholder for some other element. No corresponding CallableSBase exists in the model", - getName())); - return variable; - } - } - if (getParentSBMLObject() != null) { - if (getParentSBMLObject() instanceof KineticLaw) { - variable = ((KineticLaw) getParentSBMLObject()).getLocalParameter(getName()); - } - if (variable == null) { - Model m = getParentSBMLObject().getModel(); - if (m != null) { - variable = m.findCallableSBase(getName()); - if (variable instanceof LocalParameter) { - // in this case the parameter originates from a - // different kinetic law. - variable = null; - } else if (variable == null) { - // Could be any L3 package elements - // that is not a CallableSBase - // TODO: Actually, if something can be addressed in an ASTNode, - // it MUST implement CallableSBase, no matter in which extension - // package. - // variable = m.findNamedSBase(getName()); - logger.debug(MessageFormat.format( - "Cannot find any element with id \"{0}\" in the model.", - getName())); - } - } else { - logger.debug(MessageFormat.format( - "This ASTNode is not yet linked to a model and can therefore not determine its variable \"{0}\".", - getName())); - } - } - } - } + if (variable == null) { + /* + * Possibly the name is just from the argument list + * of some function definition. Hence, it won't be + * possible to determine an element with the same + * identifier within the model. In this case, this + * warning is kind of senseless. + */ + TreeNode parent = getParent(); + if ((parent != null) && (parent instanceof ASTNode)) { + ASTNode parentNode = (ASTNode) parent; + if ((parentNode.getType() == Type.LAMBDA) && (parentNode.getRightChild() != this)) { + /* + * The second condition is important, because the argument list + * comprises only the first n children. Child n + 1 is the + * expression for the function. + */ + logger.debug(MessageFormat.format( + "The name \"{0}\" represented by this node is an argument in a function call, i.e., a placeholder for some other element. No corresponding CallableSBase exists in the model", + getName())); + return variable; + } + } + if (getParentSBMLObject() != null) { + if (getParentSBMLObject() instanceof KineticLaw) { + variable = ((KineticLaw) getParentSBMLObject()).getLocalParameter(getName()); + } + if (variable == null) { + Model m = getParentSBMLObject().getModel(); + if (m != null) { + variable = m.findCallableSBase(getName()); + if (variable instanceof LocalParameter) { + // in this case the parameter originates from a + // different kinetic law. + variable = null; + } else if (variable == null) { + // Could be any L3 package elements + // that is not a CallableSBase + // TODO: Actually, if something can be addressed in an ASTNode, + // it MUST implement CallableSBase, no matter in which extension + // package. + // variable = m.findNamedSBase(getName()); + logger.debug(MessageFormat.format( + "Cannot find any element with id \"{0}\" in the model.", + getName())); + } + } else { + logger.debug(MessageFormat.format( + "This ASTNode is not yet linked to a model and can therefore not determine its variable \"{0}\".", + getName())); + } + } + } + } return variable; } throw new RuntimeException("getVariable() should be called only when isVariable() == true."); @@ -2587,7 +2587,7 @@ private void initDefaults() { ASTNode old = this; logger.debug("initDefaults called !! type was " + (type == null ? Type.UNKNOWN : type)); - + type = Type.UNKNOWN; id = null; @@ -2607,10 +2607,10 @@ listOfNodes = new LinkedList<ASTNode>(); } else { for (int i = listOfNodes.size() - 1; i >= 0; i--) { - // This also removes the pointer from the previous child to this object, i.e., its previous parent node. + // This also removes the pointer from the previous child to this object, i.e., its previous parent node. ASTNode removed = listOfNodes.remove(i); resetParentSBMLObject(removed); - removed.fireNodeRemovedEvent(); + removed.fireNodeRemovedEvent(); } } variable = null; @@ -3071,7 +3071,7 @@ public ASTNode minus(int integer) { return minus(integer, null); } - + /** * * @param integer @@ -3079,8 +3079,8 @@ * @return */ public ASTNode minus(int integer, String unitsID) { - minus(new ASTNode(integer, unitsID, getParentSBMLObject())); - return this; + minus(new ASTNode(integer, unitsID, getParentSBMLObject())); + return this; } /** @@ -3215,33 +3215,43 @@ */ public ASTNode raiseByThePowerOf(double exponent) { if (exponent == 0d) { - // Clear list of nodes first because this won't notify any listeners. - listOfNodes.clear(); - // This will notify listeners that will receive this ASTNode with an empty list of children. - setValue(1); - // The units of this ASTNode must be dimensionless now. + // Clear list of nodes first because this won't notify any listeners. + listOfNodes.clear(); + // This will notify listeners that will receive this ASTNode with an empty list of children. + setValue(1); + // The units of this ASTNode must be dimensionless now. if (isSetParentSBMLObject() && (getParentSBMLObject().getLevel() > 2)) { - setUnits(Unit.Kind.DIMENSIONLESS.toString().toLowerCase()); + setUnits(Unit.Kind.DIMENSIONLESS.toString().toLowerCase()); } } else if (exponent != 1d) { - return raiseByThePowerOf(new ASTNode(exponent, getParentSBMLObject())); + ASTNode exp; + if (Maths.isInt(exponent)) { + exp = new ASTNode((int) exponent, getParentSBMLObject()); + } else { + exp = new ASTNode(exponent, getParentSBMLObject()); + } + if (isSetParentSBMLObject() && (getParentSBMLObject().getLevel() > 2)) { + // Exponents must be dimensionless! + exp.setUnits(Unit.Kind.DIMENSIONLESS.toString().toLowerCase()); + } + return raiseByThePowerOf(exp); } return this; } - /** - * <p> - * Reduces this {@link ASTNode} to a binary tree, e.g., if the formula in this - * {@link ASTNode} is and(x, y, z) then the formula of the reduced node would - * be and(and(x, y), z). - * </p> - * <p> - * This method is not yet completed. Currently, only {@link Type#PLUS}, - * {@link Type#TIMES}, {@link Type#LOGICAL_AND}, {@link Type#LOGICAL_OR} are - * touched by the method. All other nodes are left unchanged, but it traverses - * the entire tree rooted at this node. - * </p> - */ + /** + * <p> + * Reduces this {@link ASTNode} to a binary tree, e.g., if the formula in this + * {@link ASTNode} is and(x, y, z) then the formula of the reduced node would + * be and(and(x, y), z). + * </p> + * <p> + * This method is not yet completed. Currently, only {@link Type#PLUS}, + * {@link Type#TIMES}, {@link Type#LOGICAL_AND}, {@link Type#LOGICAL_OR} are + * touched by the method. All other nodes are left unchanged, but it traverses + * the entire tree rooted at this node. + * </p> + */ private void reduceToBinary() { if (getChildCount() > 2) { int i; @@ -3255,7 +3265,7 @@ break; case MINUS: // TODO - logger.debug(MessageFormat.format("MINUS node with {0,number,integer} children left unchanged", getChildCount())); + logger.debug(MessageFormat.format("MINUS node with {0,number,integer} children left unchanged", getChildCount())); break; case TIMES: ASTNode times = new ASTNode(Type.TIMES, parentSBMLObject); @@ -3270,7 +3280,7 @@ break; case DIVIDE: // TODO - logger.debug(MessageFormat.format("DIVIDE node with {0,number,integer} children left unchanged", getChildCount())); + logger.debug(MessageFormat.format("DIVIDE node with {0,number,integer} children left unchanged", getChildCount())); break; case LOGICAL_AND: ASTNode and = new ASTNode(Type.LOGICAL_AND, parentSBMLObject); @@ -3288,15 +3298,15 @@ break; case LOGICAL_NOT: // TODO - logger.debug(MessageFormat.format("NOT node with {0,number,integer} children left unchanged", getChildCount())); + logger.debug(MessageFormat.format("NOT node with {0,number,integer} children left unchanged", getChildCount())); break; case LOGICAL_XOR: // TODO - logger.debug(MessageFormat.format("XOR node with {0,number,integer} children left unchanged", getChildCount())); + logger.debug(MessageFormat.format("XOR node with {0,number,integer} children left unchanged", getChildCount())); break; default: // TODO - logger.debug(MessageFormat.format("{0} node with {1,number,integer} children left unchanged", getType(), getChildCount())); + logger.debug(MessageFormat.format("{0} node with {1,number,integer} children left unchanged", getType(), getChildCount())); break; } } @@ -3385,7 +3395,7 @@ ASTNode oldChild = listOfNodes.remove(n); resetParentSBMLObject(oldChild); oldChild.fireNodeRemovedEvent(); - + // Adding the new child at position n setParentSBMLObject(newChild, parentSBMLObject, 0); newChild.parent = this; @@ -3575,9 +3585,9 @@ // type); String sType = type.toString(); - + logger.debug("setType called: typeBefore = " + this.type + " typeAfter= " + sType); - + if (sType.startsWith("NAME") || sType.startsWith("CONSTANT")) { // TODO: check, a user might have set some values before calling // the setType() @@ -3613,42 +3623,42 @@ * of a unit definition. */ public void setUnits(String unitId) { - if (!isNumber()) { - throw new IllegalArgumentException(MessageFormat.format( - "Unexpected attribute {0}, only literal numbers can defined a unit.", - unitId)); - } - if (parentSBMLObject != null) { - if (!Unit.isValidUnit(parentSBMLObject.getModel(), unitId)) { - throw new IllegalArgumentException(MessageFormat.format( - "Unexpected attribute {0}, only a valid unit kind or the identifier of a unit definition are allowed here.", - unitId)); - } - if (parentSBMLObject.isSetLevel() && (parentSBMLObject.getLevel() < 3)) { - throw new IllegalArgumentException(MessageFormat.format( - "Cannot set unit {0} for a numbers in an ASTNode before SBML Level 3.", - unitId)); - } - } - String oldValue = this.unitId; - this.unitId = unitId; - this.firePropertyChange(TreeNodeChangeEvent.units, oldValue, unitId); + if (!isNumber()) { + throw new IllegalArgumentException(MessageFormat.format( + "Unexpected attribute {0}, only literal numbers can defined a unit.", + unitId)); + } + if (parentSBMLObject != null) { + if (!Unit.isValidUnit(parentSBMLObject.getModel(), unitId)) { + throw new IllegalArgumentException(MessageFormat.format( + "Unexpected attribute {0}, only a valid unit kind or the identifier of a unit definition are allowed here.", + unitId)); + } + if (parentSBMLObject.isSetLevel() && (parentSBMLObject.getLevel() < 3)) { + throw new IllegalArgumentException(MessageFormat.format( + "Cannot set unit {0} for a numbers in an ASTNode before SBML Level 3.", + unitId)); + } + } + String oldValue = this.unitId; + this.unitId = unitId; + this.firePropertyChange(TreeNodeChangeEvent.units, oldValue, unitId); } - + /** * * @param unit */ public void setUnits(Unit.Kind unit) { - setUnits(unit.toString().toLowerCase()); + setUnits(unit.toString().toLowerCase()); } - + /** * * @param ud */ public void setUnits(UnitDefinition ud) { - setUnits(ud.getId()); + setUnits(ud.getId()); } /** @@ -3736,17 +3746,17 @@ this.denominator = denominator; this.firePropertyChange(TreeNodeChangeEvent.denominator, oldDenominator, denominator); } - - /** - * Allows you to directly set an instance of {@link CallableSBase} as the - * variable of this {@link ASTNode}. Note that if the given variable - * does not have a declared {@code id} field, the pointer to this variable - * will get lost when cloning this node. Only references to identifiers are - * permanently stored. The pointer can also not be written to an SBML file - * without a valid identifier. - * - * @param variable a pointer to a {@link CallableSBase}. - */ + + /** + * Allows you to directly set an instance of {@link CallableSBase} as the + * variable of this {@link ASTNode}. Note that if the given variable + * does not have a declared {@code id} field, the pointer to this variable + * will get lost when cloning this node. Only references to identifiers are + * permanently stored. The pointer can also not be written to an SBML file + * without a valid identifier. + * + * @param variable a pointer to a {@link CallableSBase}. + */ public void setVariable(CallableSBase variable) { CallableSBase oldValue = this.variable; if (variable instanceof FunctionDefinition) { @@ -3755,12 +3765,12 @@ type = Type.NAME; } if (variable.isSetId()) { - /* - * Although we memorize a direct pointer to the variable, we also have to - * store its id. Otherwise, this knowledge will got lost when cloning this - * node. - */ - this.name = variable.getId(); + /* + * Although we memorize a direct pointer to the variable, we also have to + * store its id. Otherwise, this knowledge will got lost when cloning this + * node. + */ + this.name = variable.getId(); } this.variable = variable; this.firePropertyChange(TreeNodeChangeEvent.variable, oldValue, variable); @@ -3777,53 +3787,53 @@ return this; } - /** - * <p> - * Swaps the children of this {@link ASTNode} with the children of that - * {@link ASTNode}. - * </p> - * <p> - * Unfortunately, when swapping child nodes, we have to recursively traverse - * the entire subtrees in order to make sure that all pointers to the parent - * SBML object are correct. However, this must only be done if the parent SBML - * object of that differs from the one surrounding this node. - * </p> - * <p> - * In any case, the pointer from each sub-node to its parent must be changed. - * In contrast to other SBML elements, {@link ASTNode}s have sub-nodes as - * direct children, i.e., there is no child called 'ListOfNodes'. The - * {@code setParent} method is also not recursive. - * </p> - * <p> - * However, this might cause many calls to listeners. - * </p> - * - * @param that - * the other node whose children should be used to replace this - * node's children - */ + /** + * <p> + * Swaps the children of this {@link ASTNode} with the children of that + * {@link ASTNode}. + * </p> + * <p> + * Unfortunately, when swapping child nodes, we have to recursively traverse + * the entire subtrees in order to make sure that all pointers to the parent + * SBML object are correct. However, this must only be done if the parent SBML + * object of that differs from the one surrounding this node. + * </p> + * <p> + * In any case, the pointer from each sub-node to its parent must be changed. + * In contrast to other SBML elements, {@link ASTNode}s have sub-nodes as + * direct children, i.e., there is no child called 'ListOfNodes'. The + * {@code setParent} method is also not recursive. + * </p> + * <p> + * However, this might cause many calls to listeners. + * </p> + * + * @param that + * the other node whose children should be used to replace this + * node's children + */ public void swapChildren(ASTNode that) { - List<ASTNode> swap = that.listOfNodes; - that.listOfNodes = listOfNodes; - listOfNodes = swap; - for (ASTNode child : that.listOfNodes) { - if (that.getParentSBMLObject() != getParentSBMLObject()) { - setParentSBMLObject(child, that.getParentSBMLObject(), 0); - } - child.fireNodeRemovedEvent(); - child.getListOfTreeNodeChangeListeners().removeAll(that.getListOfTreeNodeChangeListeners()); - child.setParent(that); - child.fireNodeAddedEvent(); - } - for (ASTNode child : listOfNodes) { - if (that.getParentSBMLObject() != getParentSBMLObject()) { - setParentSBMLObject(child, getParentSBMLObject(), 0); - } - child.fireNodeRemovedEvent(); - child.getListOfTreeNodeChangeListeners().removeAll(getListOfTreeNodeChangeListeners()); - child.setParent(this); - child.fireNodeAddedEvent(); - } + List<ASTNode> swap = that.listOfNodes; + that.listOfNodes = listOfNodes; + listOfNodes = swap; + for (ASTNode child : that.listOfNodes) { + if (that.getParentSBMLObject() != getParentSBMLObject()) { + setParentSBMLObject(child, that.getParentSBMLObject(), 0); + } + child.fireNodeRemovedEvent(); + child.getListOfTreeNodeChangeListeners().removeAll(that.getListOfTreeNodeChangeListeners()); + child.setParent(that); + child.fireNodeAddedEvent(); + } + for (ASTNode child : listOfNodes) { + if (that.getParentSBMLObject() != getParentSBMLObject()) { + setParentSBMLObject(child, getParentSBMLObject(), 0); + } + child.fireNodeRemovedEvent(); + child.getListOfTreeNodeChangeListeners().removeAll(getListOfTreeNodeChangeListeners()); + child.setParent(this); + child.fireNodeAddedEvent(); + } } /** @@ -3893,7 +3903,7 @@ } catch (SBMLException e) { // log the exception e.printStackTrace(); - + if (logger.isDebugEnabled()) { logger.error(errorMsg, e); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nik...@us...> - 2014-05-23 13:56:09
|
Revision: 1755 http://sourceforge.net/p/jsbml/code/1755 Author: niko-rodrigue Date: 2014-05-23 13:56:06 +0000 (Fri, 23 May 2014) Log Message: ----------- added a small test to ASTNode.setType to avoid a debug output being calculated when not in debug mode Modified Paths: -------------- trunk/core/src/org/sbml/jsbml/ASTNode.java Modified: trunk/core/src/org/sbml/jsbml/ASTNode.java =================================================================== --- trunk/core/src/org/sbml/jsbml/ASTNode.java 2014-05-23 11:01:08 UTC (rev 1754) +++ trunk/core/src/org/sbml/jsbml/ASTNode.java 2014-05-23 13:56:06 UTC (rev 1755) @@ -3634,7 +3634,9 @@ String sType = type.toString(); - logger.debug("setType called: typeBefore = " + this.type + " typeAfter= " + sType); + if (logger.isDebugEnabled()) { + logger.debug("setType called: typeBefore = " + this.type + " typeAfter= " + sType); + } if (sType.startsWith("NAME") || sType.startsWith("CONSTANT")) { // TODO: check, a user might have set some values before calling This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nik...@us...> - 2014-08-27 15:32:11
|
Revision: 1958 http://sourceforge.net/p/jsbml/code/1958 Author: niko-rodrigue Date: 2014-08-27 15:32:07 +0000 (Wed, 27 Aug 2014) Log Message: ----------- Put the FormulaParserLL3 as the default parser used when transforming an infix formula into an ASTNode. Modified Paths: -------------- trunk/core/src/org/sbml/jsbml/ASTNode.java Modified: trunk/core/src/org/sbml/jsbml/ASTNode.java =================================================================== --- trunk/core/src/org/sbml/jsbml/ASTNode.java 2014-08-27 15:30:44 UTC (rev 1957) +++ trunk/core/src/org/sbml/jsbml/ASTNode.java 2014-08-27 15:32:07 UTC (rev 1958) @@ -33,7 +33,7 @@ import org.apache.log4j.Logger; import org.sbml.jsbml.Unit.Kind; -import org.sbml.jsbml.text.parser.FormulaParser; +import org.sbml.jsbml.text.parser.FormulaParserLL3; import org.sbml.jsbml.text.parser.IFormulaParser; import org.sbml.jsbml.text.parser.ParseException; import org.sbml.jsbml.util.Maths; @@ -938,7 +938,7 @@ * parsed for other reasons. */ public static ASTNode parseFormula(String formula) throws ParseException { - FormulaParser parser = new FormulaParser(new StringReader(formula)); + FormulaParserLL3 parser = new FormulaParserLL3(new StringReader(formula)); ASTNode result = null; try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nik...@us...> - 2015-04-30 14:16:52
|
Revision: 2264 http://sourceforge.net/p/jsbml/code/2264 Author: niko-rodrigue Date: 2015-04-30 14:16:49 +0000 (Thu, 30 Apr 2015) Log Message: ----------- added the new ASTNode.Types added while designing the ASTNode2 classes. This is in order to be able to use the old ASTNode class within the new branch, instead of using ASTNode2. So that we can produce two jars, one using the old unchanged ASTNode class, one using the ASTNode facade to ASTNode2 Modified Paths: -------------- trunk/core/src/org/sbml/jsbml/ASTNode.java Modified: trunk/core/src/org/sbml/jsbml/ASTNode.java =================================================================== --- trunk/core/src/org/sbml/jsbml/ASTNode.java 2015-04-30 14:01:37 UTC (rev 2263) +++ trunk/core/src/org/sbml/jsbml/ASTNode.java 2015-04-30 14:16:49 UTC (rev 2264) @@ -84,6 +84,14 @@ */ CONSTANT_PI, /** + * + */ + CONSTRUCTOR_PIECE, + /** + * + */ + CONSTRUCTOR_OTHERWISE, + /** * */ CONSTANT_TRUE, @@ -298,6 +306,22 @@ */ POWER, /** + * + */ + PRODUCT, + /** + * + */ + QUALIFIER_BVAR, + /** + * + */ + QUALIFIER_DEGREE, + /** + * + */ + QUALIFIER_LOGBASE, + /** * An {@link ASTNode} of this {@link Type} contains two integer values: * a numerator and a denominator. */ @@ -339,6 +363,10 @@ */ RELATIONAL_NEQ, /** + * + */ + SUM, + /** * */ TIMES, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <and...@us...> - 2015-08-03 20:22:14
|
Revision: 2354 http://sourceforge.net/p/jsbml/code/2354 Author: andreas-draeger Date: 2015-08-03 20:22:11 +0000 (Mon, 03 Aug 2015) Log Message: ----------- Added another static method to create a piecewise function. Thanks to Ally Hume for pointing this out. Modified Paths: -------------- trunk/core/src/org/sbml/jsbml/ASTNode.java Modified: trunk/core/src/org/sbml/jsbml/ASTNode.java =================================================================== --- trunk/core/src/org/sbml/jsbml/ASTNode.java 2015-08-03 16:18:22 UTC (rev 2353) +++ trunk/core/src/org/sbml/jsbml/ASTNode.java 2015-08-03 20:22:11 UTC (rev 2354) @@ -1076,8 +1076,22 @@ * @return a piecewise {@link ASTNode}. */ public static ASTNode piecewise(ASTNode node, ASTNode... nodes) { - ASTNode piecewise = new ASTNode(Type.FUNCTION_PIECEWISE, node - .getParentSBMLObject()); + return piecewise(node.getParentSBMLObject(), nodes); + } + + /** + * @param parentSBMLObject + * a link to the container in which this {@link ASTNode} will be + * inserted. This can be useful if complex operations on units, + * species, etc. are necessary when creating this formula. + * Can be {@code null}. + * @param nodes + * @return + * @see #piecewise(ASTNode, ASTNode...) + */ + public static ASTNode piecewise(MathContainer parentSBMLObject, + ASTNode[] nodes) { + ASTNode piecewise = new ASTNode(Type.FUNCTION_PIECEWISE, parentSBMLObject); for (ASTNode n : nodes) { piecewise.addChild(n); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nik...@us...> - 2015-12-06 12:54:23
|
Revision: 2437 http://sourceforge.net/p/jsbml/code/2437 Author: niko-rodrigue Date: 2015-12-06 12:54:21 +0000 (Sun, 06 Dec 2015) Log Message: ----------- corrected the clone constructor of ASTNode that did not copy all attributes Modified Paths: -------------- trunk/core/src/org/sbml/jsbml/ASTNode.java Modified: trunk/core/src/org/sbml/jsbml/ASTNode.java =================================================================== --- trunk/core/src/org/sbml/jsbml/ASTNode.java 2015-12-04 16:59:45 UTC (rev 2436) +++ trunk/core/src/org/sbml/jsbml/ASTNode.java 2015-12-06 12:54:21 UTC (rev 2437) @@ -1485,7 +1485,12 @@ variable = null; // the clone is not linked anymore to any model so we cannot have any 'variable' set numerator = astNode.numerator; unitId = astNode.unitId == null ? null : new String(astNode.unitId); - + definitionURL = astNode.definitionURL; + id = astNode.id; + className = astNode.className; + encoding = astNode.encoding; + style = astNode.style; + if (astNode.getChildCount() > 0) { for (ASTNode child : astNode.listOfNodes) { ASTNode c = child.clone(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nik...@us...> - 2015-12-11 13:38:51
|
Revision: 2447 http://sourceforge.net/p/jsbml/code/2447 Author: niko-rodrigue Date: 2015-12-11 13:38:49 +0000 (Fri, 11 Dec 2015) Log Message: ----------- the ASTNode.equals method was failing when one of the double values was set to NaN. We should probably check all other equals methods for this problem Modified Paths: -------------- trunk/core/src/org/sbml/jsbml/ASTNode.java Modified: trunk/core/src/org/sbml/jsbml/ASTNode.java =================================================================== --- trunk/core/src/org/sbml/jsbml/ASTNode.java 2015-12-11 13:10:22 UTC (rev 2446) +++ trunk/core/src/org/sbml/jsbml/ASTNode.java 2015-12-11 13:38:49 UTC (rev 2447) @@ -2242,10 +2242,10 @@ && ast.getDenominator() == getDenominator(); } if ((ast.getType() == Type.REAL_E) && (type == Type.REAL_E)) { - equal &= ast.getMantissa() == getMantissa() + equal &= Double.isNaN(getMantissa()) ? Double.isNaN(ast.getMantissa()) : ast.getMantissa() == getMantissa() && ast.getExponent() == getExponent(); } else if (isReal() && ast.isReal()) { - equal &= ast.getReal() == getReal(); + equal &= Double.isNaN(getReal()) ? Double.isNaN(ast.getReal()) : ast.getReal() == getReal(); } equal &= isSetClassName() == ast.isSetClassName(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nik...@us...> - 2015-12-15 11:58:09
|
Revision: 2456 http://sourceforge.net/p/jsbml/code/2456 Author: niko-rodrigue Date: 2015-12-15 11:58:07 +0000 (Tue, 15 Dec 2015) Log Message: ----------- added a field and some methods in ASTNode to handle the semantics annotations Modified Paths: -------------- trunk/core/src/org/sbml/jsbml/ASTNode.java Modified: trunk/core/src/org/sbml/jsbml/ASTNode.java =================================================================== --- trunk/core/src/org/sbml/jsbml/ASTNode.java 2015-12-15 11:56:29 UTC (rev 2455) +++ trunk/core/src/org/sbml/jsbml/ASTNode.java 2015-12-15 11:58:07 UTC (rev 2456) @@ -48,6 +48,7 @@ import org.sbml.jsbml.util.compilers.MathMLXMLStreamCompiler; import org.sbml.jsbml.util.compilers.UnitsCompiler; import org.sbml.jsbml.util.filters.Filter; +import org.sbml.jsbml.xml.XMLNode; import org.sbml.jsbml.xml.stax.SBMLReader; /** @@ -1391,6 +1392,12 @@ private String encoding; /** + * XMLNode that will hold the content of the 'semantics' mathML element. + */ + private List<XMLNode> semanticsAnnotationList; + + + /** * Tells if the type attribute of the cn element was set and we need to * write it back or if it is set to the default (REAL). * @@ -1498,6 +1505,14 @@ listOfNodes.add(c); } } + + if (astNode.semanticsAnnotationList != null) { + semanticsAnnotationList = new ArrayList<XMLNode>(); + + for (XMLNode semanticsAnnotation : astNode.semanticsAnnotationList) { + semanticsAnnotationList.add(semanticsAnnotation.clone()); + } + } } /** @@ -2272,6 +2287,8 @@ if (equal && isSetUnits()) { equal &= getUnits().equals(ast.getUnits()); } + + // TODO - semanticsAnnotationList not part of equals or hashcode ? } return equal; } @@ -2355,6 +2372,8 @@ @Override public TreeNode getChildAt(int i) { return getChild(i); + + // TODO - add semantics XMLNode ?? } /* (non-Javadoc) @@ -2363,6 +2382,8 @@ @Override public int getChildCount() { return listOfNodes == null ? 0 : listOfNodes.size(); + + // TODO - add semantics XMLNode ?? } /** @@ -2803,6 +2824,12 @@ if (isSetClassName()) { hashCode += prime * getClassName().hashCode(); } + if (isSetUnits()) { + hashCode += prime * getUnits().hashCode(); + } + // TODO - semanticsAnnotationList not part of equals or hashcode ? + + return hashCode; } @@ -4356,4 +4383,102 @@ return tree; } + /** + * Adds the given {@link XMLNode} as a MathML <code><semantics></code> element to this {@link ASTNode}. + * + * <p> + * The {@code <semantics>} element is a MathML 2.0 construct + * that can be used to associate additional information with a MathML + * construct. The construct can be used to decorate a MathML expressions with + * a sequence of one or more {@code <annotation>} or + * {@code <annotation-xml>} elements. Each such element contains a + * pair of items; the first is a symbol that acts as an attribute or key, and + * the second is the value associated with the attribute or key. Please refer + * to the MathML 2.0 documentation, particularly the <a target="_blank" + * href="http://www.w3.org/TR/2007/WD-MathML3-20071005/chapter5.html#mixing.semantic.annotations">Section + * 5.2, Semantic Annotations</a> for more information about these constructs. + * + * @param semanticsAnnotation the annotation to add. + * @return the added {@link XMLNode}. + */ + public XMLNode addSemanticsAnnotation(XMLNode semanticsAnnotation) { + if (semanticsAnnotation == null) { + return null; + } + if (semanticsAnnotationList == null) { + semanticsAnnotationList = new ArrayList<XMLNode>(); + } + + semanticsAnnotationList.add(semanticsAnnotation); + + return semanticsAnnotation; + } + + /** + * Gets the number of <em>semantic annotation</em> elements inside this node. + * + * <p> + * The <code><semantics></code> element is a MathML 2.0 construct + * that can be used to associate additional information with a MathML + * construct. The construct can be used to decorate a MathML expressions with + * a sequence of one or more <code><annotation></code> or + * <code><annotation-xml></code> elements. Each such element contains a + * pair of items; the first is a symbol that acts as an attribute or key, and + * the second is the value associated with the attribute or key. Please refer + * to the MathML 2.0 documentation, particularly the <a target="_blank" + * href="http://www.w3.org/TR/2007/WD-MathML3-20071005/chapter5.html#mixing.semantic.annotations">Section + * 5.2, Semantic Annotations</a> for more information about these constructs. + * + * @return the number of annotations of this {@link ASTNode}. + * @see ASTNode#addSemanticsAnnotation(XMLNode semanticsAnnotation) + */ + public int getNumSemanticsAnnotations() { + if (semanticsAnnotationList == null) { + return 0; + } + + return semanticsAnnotationList.size(); + } + + /** + * Gets the nth <code><semantics></code> annotation of this node. + * + * <p> + * The <code><semantics></code> element is a MathML 2.0 construct + * that can be used to associate additional information with a MathML + * construct. The construct can be used to decorate a MathML expressions with + * a sequence of one or more <code><annotation></code> or + * <code><annotation-xml></code> elements. Each such element contains a + * pair of items; the first is a symbol that acts as an attribute or key, and + * the second is the value associated with the attribute or key. Please refer + * to the MathML 2.0 documentation, particularly the <a target="_blank" + * href="http://www.w3.org/TR/2007/WD-MathML3-20071005/chapter5.html#mixing.semantic.annotations">Section + * 5.2, Semantic Annotations</a> for more information about these constructs. + * + * @return the nth annotation of this {@link ASTNode}, or <code>null</code> if this node has + * no nth annotation (<code>n ></code> + * {@link ASTNode#getNumSemanticsAnnotations()} + * <code>- 1</code> or n < 0). + * @see ASTNode#addSemanticsAnnotation(XMLNode sAnnotation) + */ + public XMLNode getSemanticsAnnotation(int n) { + if (semanticsAnnotationList == null || n < 0 || (n > (getNumSemanticsAnnotations() -1))) { + return null; + } + + return semanticsAnnotationList.get(n); + } + + /** + * Returns the list of semantics annotations of this node. + * + * @return the list of semantics annotations of this node or null if no semantics annotation are present. + */ + public List<XMLNode> getListOfSemanticsAnnotations() { + return semanticsAnnotationList; + } + + // TODO - removeSemanticsAnnotation + // TODO - unsetsemanticsAnnotation + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |