/** * @param astNode */ private void compileInteger(ASTNode astNode) { try { writer.writeCharacters(indent); writer.writeStartElement(ASTNode.URI_MATHML_DEFINITION, "cn"); writer.writeAttribute("type", "integer"); // writer.writeAttribute(ASTNode.URI_MATHML_DEFINITION, "type", "integer"); if (astNode.isSetUnits()) { writer.writeAttribute("sbml:units", astNode.getUnits()); } writer.writeCharacters(" "); writer.writeCharacters(Integer.toString(astNode.getInteger())); writer.writeCharacters(" "); writer.writeEndElement(); writer.writeCharacters("\n"); } catch (XMLStreamException e) { e.printStackTrace(); } }
/** * Returns {@code true} if this node represents a log10() function, {@code false} otherwise. * More precisely, this predicate returns {@code true} if the node type is * FUNCTION_LOG with two children, the first of which is an INTEGER equal to * 10. * * @return {@code true} if the given ASTNode represents a log10() function, {@code false} * otherwise. */ public boolean isLog10() { return type == Type.FUNCTION_LOG && listOfNodes.size() == 2 && getLeftChild().isInteger() && getLeftChild().getInteger() == 10; }
/** * Returns {@code true} if this {@link ASTNode} represents the number one (either as * integer or as real value). * * @return {@code true} if this {@link ASTNode} represents the number one. */ public boolean isOne() { return (isReal() && getReal() == 1d) || (isInteger() && getInteger() == 1); }
/** * Returns {@code true} if this node represents a square root function, {@code false} * otherwise. * * More precisely, the node type must be {@link Type#FUNCTION_ROOT} with two * children, the first of which is an {@link Type#INTEGER} node having value * equal to 2. * * @return {@code true} if the given ASTNode represents a sqrt() function, {@code false} * otherwise. */ public boolean isSqrt() { return type == Type.FUNCTION_ROOT && listOfNodes.size() == 2 && getLeftChild().isInteger() && getLeftChild().getInteger() == 2; }
/** * Returns {@code true} if this node represents the number zero (either as integer * or as real value). * * @return {@code true} if this node represents the number zero. */ public boolean isZero() { return (isReal() && getReal() == 0d) || (isInteger() && getInteger() == 0); }
private Integer getInteger(ASTNode node) { if (node.isUMinus()) { if (node.getChild(0).isInteger()) { return - node.getChild(0).getInteger(); } else { return null; } } else { if (node.isInteger()) { return node.getInteger(); } else { return null; } } }
private Integer getInteger(ASTNode node) { if (node.isUMinus()) { if (node.getChild(0).isInteger()) { return - node.getChild(0).getInteger(); } else { return null; } } else { if (node.isInteger()) { return node.getInteger(); } else { return null; } } }
private Integer getInteger(ASTNode node) { if (node.isUMinus()) { if (node.getChild(0).isInteger()) { return - node.getChild(0).getInteger(); } else { return null; } } else { if (node.isInteger()) { return node.getInteger(); } else { return null; } } }
private Integer getInteger(ASTNode node) { if (node.isUMinus()) { if (node.getChild(0).isInteger()) { return - node.getChild(0).getInteger(); } else { return null; } } else { if (node.isInteger()) { return node.getInteger(); } else { return null; } } }
private Integer getInteger(ASTNode node) { if (node.isUMinus()) { if (node.getChild(0).isInteger()) { return - node.getChild(0).getInteger(); } else { return null; } } else { if (node.isInteger()) { return node.getInteger(); } else { return null; } } }
/** * Returns {@code true} if this astnode represents the number minus one (either as * integer or as real value). * * @return {@code true} if this astnode represents the number minus one (either as * integer or as real value). */ public boolean isMinusOne() { return (isReal() && (getReal() == -1d)) || (isInteger() && (getInteger() == -1)) || (isUMinus() && getLeftChild().isOne()); }
if (value.isNumber()) { if (!isResultSet) { result = value.getInteger() == 1; isResultSet = true; } else { result &= value.getInteger() == 1 ? true : false;
if (value.isNumber()) { if (!isResultSet) { result = value.getInteger() == 1; isResultSet = true; } else { result ^= value.getInteger() == 1 ? true : false;
/** * Creates a power {@link ASTNode}. * * @param basis the basis * @param exponent the exponent * @return a power {@link ASTNode}. */ public static ASTNode pow(ASTNode basis, ASTNode exponent) { if (!(exponent.isInteger() && exponent.getInteger() == 1) && !(exponent.getType() == Type.REAL && exponent.getReal() == 1d)) { if ((exponent.isInteger() && exponent.getInteger() == 0) || (exponent.getType() == Type.REAL && exponent.getReal() == 0d)) { basis = new ASTNode(1, basis.getParentSBMLObject()); } else { setParentSBMLObject(exponent, basis.getParentSBMLObject(), 0); basis.raiseByThePowerOf(exponent); } } return basis; }
hashCode += prime * getType().hashCode(); if (isInteger()) { hashCode += prime * getInteger(); } else if (!isNumber() && !isOperator() && (isSetName() || (variable != null))) { hashCode += prime * getName().hashCode();
compiled.setValue(compiled.getInteger() == 1 ? 0 : 1);
double result = Maths.factorial(compiled.getInteger()); compiled.setValue(result);
/** * @param value */ private void notRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { notRecursive(value.getChild(i)); } else if (useId){ ASTNode notValue = new ASTNode(ASTNode.Type.LOGICAL_NOT, child.getParentSBMLObject()); notValue.addChild(child.clone()); value.replaceChild(i, notValue); } else if (child.isBoolean()) { value.getChild(i).setValue(child.getInteger() == 1 ? 0 : 1); } 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 uMinusRecursive(ASTNode value) { for (int i = 0; i < value.getChildCount(); i++) { value.getChild(i).compile(this); ASTNode child = getNode(); if (child.isVector()) { uMinusRecursive(value.getChild(i)); } else if (useId) { value.replaceChild(i, ASTNode.uMinus(child)); } else if (child.isNumber()) { if (child.isInteger()) { value.getChild(i).setValue(-child.getInteger()); } else if (child.isRational()) { value.getChild(i).setValue(-child.getNumerator(), child.getDenominator()); } else if (child.getType().equals(Type.REAL_E)) { value.getChild(i).setValue(-child.getMantissa(), child.getExponent()); } else { value.getChild(i).setValue(-child.getReal()); } } else { throw new SBMLException(); } } }