@Override public String getPredefinedUnitID() { if (getLevel() < 3) { if (getLevel() < 2) { return UnitDefinition.VOLUME; } // For level below 3, spatialDimensions should have a default value but the iSet method return false so we cannot use the getter if (spatialDimensions != null) { // Additional check in case spatialDimensions has been unset switch (spatialDimensions.shortValue()) { case 3: return UnitDefinition.VOLUME; case 2: return UnitDefinition.AREA; case 1: return UnitDefinition.LENGTH; default: break; } } } return null; }
/** * Returns the {@link #spatialDimensions} of this {@link Compartment}. If it * is not set and the level of this {@link Compartment} is either one or two * it returns the default SBML Level 2 value, which is 3. In all other * cases, {@link Double#NaN} will be returned. * * @return the {@link #spatialDimensions} of this {@link Compartment} or 3 * if {@link #spatialDimensions} is not set and level is 1 or 2. */ public double getSpatialDimensions() { if (isSetSpatialDimensions() && (spatialDimensions != null)) { return spatialDimensions.doubleValue(); } if (getLevel() < 3) { // Although in Level 1, no spatial dimensions are defined, but // these are implicitly 3 due to the volume attribute. return 3d; } return Double.NaN; }
/** * Initializes the default values using the current Level/Version * configuration. */ public void initDefaults() { initDefaults(getLevel(), getVersion()); }
if (getLevel() != 1) { throw new PropertyNotAvailableException(TreeNodeChangeEvent.volume, this);
@Override public Map<String, String> writeXMLAttributes() { Map<String, String> attributes = super.writeXMLAttributes(); int level = getLevel(); Locale en = Locale.ENGLISH;
@Override public String getUnits() { String units = super.getUnits(); if ((units == null) && (getLevel() > 2)) { int dim = (int) getSpatialDimensions(); if (dim - getSpatialDimensions() == 0d) { Model model = getModel(); if (model != null) { switch (dim) { case 1: return model.getLengthUnits(); case 2: return model.getAreaUnits(); case 3: return model.getVolumeUnits(); default: break; } } } } return units; }
@Override public UnitDefinition getUnitsInstance() { UnitDefinition ud = super.getUnitsInstance(); if ((ud == null) && (getLevel() > 2)) { int dim = (int) getSpatialDimensions(); if (dim - getSpatialDimensions() == 0d) { Model model = getModel(); if (model != null) { switch (dim) { case 1: return model.getLengthUnitsInstance(); case 2: return model.getAreaUnitsInstance(); case 3: return model.getVolumeUnitsInstance(); default: break; } } } } return ud; }
@Override public boolean containsUndeclaredUnits() { boolean undeclared = super.containsUndeclaredUnits(); if (undeclared && (getLevel() > 2)) { Model model = getModel(); if (model != null) { if (isSetSpatialDimensions()) { int spatialDim = (int) getSpatialDimensions(); if (getSpatialDimensions() - spatialDim == 0) { // In Level 3 a compartment inherits substance units from its model. // If the model declares the default size units, the units of each // compartment are also declared. switch (spatialDim) { case 0: return false; case 1: return !model.isSetLengthUnits(); case 2: return !model.isSetAreaUnits(); case 3: return !model.isSetVolumeUnits(); default: break; } } } } } return undeclared; }
@Override public UnitDefinition getDerivedUnitDefinition() { if ((getLevel() < 3) || isSetUnitsInstance()) {