@Override public void setVariable(String variable) { // checkAndSetVariable(variable); // We cannot use that as the Object might not be defined yet in L3. if (variable != null && variable.trim().length() == 0) { variable = null; } if (!isReadingInProgress() && variable != null) { // This method will throw IllegalArgumentException if the given id does not respect the SId syntax checkIdentifier(variable); } String oldVariable = variableID; variableID = variable; firePropertyChange(TreeNodeChangeEvent.variable, oldVariable, variableID); }
@Override @Deprecated public void setUnits(Kind unitKind) { setUnits(new Unit(1d, 0, unitKind, 1d, getLevel(), getVersion())); }
/** * Creates a new {@link ExplicitRule} * * @param rule */ public ExplicitRule(ExplicitRule rule) { super(rule); initDefaults(); if (rule.isSetVariable()) { setVariable(new String(rule.getVariable())); } if (rule.isSetUnits()) { setUnits(new String(rule.getUnits())); } }
@Override public boolean isSpeciesConcentration() { return isSetVariableInstance() && (getVariableInstance() instanceof Species); }
@Override public boolean isCompartmentVolume() { return isSetVariable() && (getVariableInstance() instanceof Compartment); }
Map<String, String> attributes = super.writeXMLAttributes(); if (isSetVariable()) { if (getLevel() > 1) { attributes.put("variable", getVariable()); } else if (getLevel() == 1) { if (isSpeciesConcentration()) { attributes.put((getVersion() == 1) ? "specie" : "species", getVariable()); } else if (isCompartmentVolume()) { attributes.put("compartment", getVariable()); } else if (isParameter()) { attributes.put("name", getVariable()); if (isSetUnits()) { attributes.put(TreeNodeChangeEvent.units, getUnits());
if ((getLevel() == 1) && (attributeName.equals("name"))) { isAttributeRead = false; unsetName(); unsetId(); if (getLevel() == 1) { if ((attributeName.equals("compartment") || attributeName.equals("name") || attributeName .equals((getVersion() == 1) ? "specie" : "species"))) setVariable(value); return true; } else if (attributeName.equals("units")) { setUnits(value); return true; setVariable(value); return true;
@Override public void setVariable(Variable variable) { if (variable != null) { if (variable.isConstant()) { throw new IllegalArgumentException(MessageFormat.format( resourceBundle.getString("Assignment.ILLEGAL_CONSTANT_VARIABLE_MSG"), variable.getId(), getElementName())); } if (isSetUnits() && !(variable instanceof Parameter)) { throw new IllegalArgumentException(MessageFormat.format( "Variable expected to be an instance of Parameter because a Unit attribute is set already, but given is an instance of {0}.", variable.getElementName())); } if ((getLevel() < 3) && (variable instanceof SpeciesReference)) { throw new IllegalArgumentException(MessageFormat.format( resourceBundle.getString("Assignment.ILLEGAL_VARIABLE_EXCEPTION_MSG"), variable.getId(), getElementName())); } if (variable.isSetId()) { String oldVariable = variableID; variableID = variable.getId(); firePropertyChange(TreeNodeChangeEvent.variable, oldVariable, variableID); } else { unsetVariable(); } } else { unsetVariable(); } }
@Override public boolean equals(Object object) { boolean equals = super.equals(object); if (equals) { ExplicitRule r = (ExplicitRule) object; equals &= isSetVariable() == r.isSetVariable(); if (equals && isSetVariable()) { equals &= getVariable().equals(r.getVariable()); } equals &= isSetUnits() == r.isSetUnits(); if (equals && isSetUnits()) { equals &= getUnits().equals(r.getUnits()); } } return equals; }
@Override public boolean check(ValidationContext ctx, ExplicitRule r) { Model m = r.getModel(); String var = r.getVariable(); if (r.isSetVariable() && m != null) { Compartment c = m.getCompartment(var); if (c != null && c.isSetSpatialDimensions() && c.getSpatialDimensions() == 0) { ValidationConstraint.logError(ctx, CORE_20911, r, r.getElementName(), r.getVariable()); return false; } } return true; } };
/** * Sets the unitsID to 'unitsID'. * * @param unitsID * A valid identifier of a {@link UnitDefinition} in the * {@link Model} or the name of one of the {@link Unit.Kind} base * types. * @deprecated This is a requirement for Level 1 Version 1 and Version 2, * but can only be used in conjunction with {@link Parameter}s. * In this case this {@link AssignmentRule} represents the SBML * element ParameterRule. * @throws PropertyNotAvailableException if Level is not 1. */ @Override @Deprecated public void setUnits(String unitsID) { if (getLevel() != 1) { throw new PropertyNotAvailableException(TreeNodeChangeEvent.units, this); } if (isSetVariable() && !isParameter()) { throw new IllegalArgumentException(MessageFormat.format( "Cannot set unit {0} for a variable other than parameter", unitsID)); } String oldUnitsID = this.unitsID; this.unitsID = unitsID; firePropertyChange(TreeNodeChangeEvent.units, oldUnitsID, unitsID); }
@Override public void writeElement(SBMLObjectForXML xmlObject, Object sbmlElementToWrite) { if (sbmlElementToWrite instanceof SBase) { SBase sbase = (SBase) sbmlElementToWrite; if (logger.isDebugEnabled()) { logger.debug(MessageFormat.format("writeElement: {0}", sbase.getElementName())); } // dealing with level 1 rules if (sbase.getLevel() == 1 && sbase instanceof ExplicitRule) { ExplicitRule rule = (ExplicitRule) sbase; if (rule.isSpeciesConcentration()) { if (rule.getVersion() == 1) { xmlObject.setName("specieConcentrationRule"); } else { xmlObject.setName("speciesConcentrationRule"); } } else if (rule.isCompartmentVolume()) { xmlObject.setName("compartmentVolumeRule"); } else if (rule.isParameter()) { xmlObject.setName("parameterRule"); } } if (!xmlObject.isSetName()) { xmlObject.setName(sbase.getElementName()); } } }
@Override @Deprecated public void setUnits(Unit unit) { UnitDefinition ud = new UnitDefinition(unit.getKind().toString(), getLevel(), getVersion()); ud.addUnit(unit); if ((unit.getExponent() != 1) || (unit.getScale() != 0) || (unit.getMultiplier() != 1d) || (unit.getOffset() != 0d)) { StringBuilder sb = new StringBuilder(); sb.append(unit.getMultiplier()); sb.append('_'); sb.append(unit.getScale()); sb.append('_'); sb.append(unit.getKind().toString()); sb.append('_'); sb.append(unit.getExponent()); ud.setId(sb.toString()); Model m = getModel(); if (m != null) { m.addUnitDefinition(ud); } } setUnits(ud); }
/** * Gets the list element which has the id 'id'. * * <p>The elements of the list have to implement {@link SBase}, if they are not * or if the id is not found, null is returned. * * @param id the id to search for. * @return the list element which has the id 'id'. */ public T get(String id) { T foundElement = null; for (T element : listOf) { if (element instanceof SBase) { if (((SBase) element).getId().equals(id)) { foundElement = element; break; } } if (element instanceof ExplicitRule) { if (((ExplicitRule) element).getVariable().equals(id)) { foundElement = element; break; } } } return foundElement; }
@Override public Variable getVariableInstance() { Model m = getModel(); return m != null ? m.findVariable(variableID) : null; }
/** * Creates a new {@link ExplicitRule} * * @param math * @param level * @param version */ public ExplicitRule(ASTNode math, int level, int version) { super(math, level, version); initDefaults(); }
@Override public void unsetVariable() { String oldVariableID = variableID; variableID = null; firePropertyChange(TreeNodeChangeEvent.variable, oldVariableID, variableID); }
@Override public String getElementName() { if (getLevel() == 1) { if (isSpeciesConcentration()) { switch (getVersion()) { case 1: return "specieConcentrationRule"; case 2: return "speciesConcentrationRule"; default: break; } } else if (isCompartmentVolume()) { return "compartmentVolumeRule"; } else if (isParameter()) { return "parameterRule"; } } return super.getElementName(); }
@Override public int hashCode() { final int prime = 919; int hashCode = super.hashCode(); if (isSetVariable()) { hashCode += prime * getVariable().hashCode(); } if (isSetUnits()) { hashCode += prime * getUnits().hashCode(); } return hashCode; }
@Override public boolean isParameter() { return isSetVariableInstance() && (getVariableInstance() instanceof Parameter); }