/** * Gets the value of this node as an integer. This function should be called * only when getType() == INTEGER, otherwise an Exception is thrown. * * @return the value of this ASTNode as an integer. * @throws IllegalArgumentException * if the node is not of type integer. */ public int getInteger() { if (isInteger()) { return numerator; } throw new IllegalArgumentException(resourceBundle.getString("ASTNode.getInteger")); }
/** * Returns {@code true} if this node contains a number, {@code false} otherwise. This is * functionally equivalent to the following code: * * <pre class="brush:java"> * isInteger() || isReal() * </pre> * * @return {@code true} if this ASTNode is a number, {@code false} otherwise. */ public boolean isNumber() { return isInteger() || isReal(); }
/** * 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); }
break; } else if (isInteger()) { return getInteger();
/** * 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()); }
} else if (astNode.isInteger()) { astNode.setValue(StringTools.parseSBMLInt(characters.trim())); } else if (astNode.isRational()) {
/** * 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; }
@Override public ASTNodeValue root(ASTNode rootExponent, ASTNode radiant) throws SBMLException { ASTNodeValue rootExponentValue = rootExponent.compile(this); if (rootExponent.isSetUnits() || !(rootExponent.isInteger() || rootExponent.isRational())) { checkForDimensionlessOrInvalidUnits(rootExponentValue.getUnits()); } if (rootExponentValue.isNumber()) { return root(rootExponentValue.toDouble(), radiant); } return new ASTNodeValue(this); }
int hashCode = super.hashCode(); hashCode += prime * getType().hashCode(); if (isInteger()) { hashCode += prime * getInteger(); } else if (!isNumber() && !isOperator() && (isSetName() || (variable != null))) {
@Override public ASTNodeValue root(ASTNode rootExponent, ASTNode radiant) throws SBMLException { if (rootExponent.isSetUnits()) { checkForDimensionlessOrInvalidUnits(rootExponent.getUnitsInstance()); } if (rootExponent.isNumber()) { if (!(rootExponent.isInteger() || rootExponent.isRational())) { checkForDimensionlessOrInvalidUnits(rootExponent .getUnitsInstance()); } return root(rootExponent.compile(this).toDouble(), radiant); } return invalid(); }
if (compiled.isInteger()) { compiled.setValue(-value.getInteger()); } else if (compiled.isRational()) {
/** * @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(); } } }