/** * Initializes the default values using the current Level/Version configuration. */ public void initDefaults() { initDefaults(getLevel(), getVersion()); }
/** * Sets the offset of this {@link Unit} * * @param offset * @deprecated Only defined for SBML Level 2 Version 1. * @throws PropertyNotAvailableException * if Level/Version combination is not 2.1. */ @Deprecated public void setOffset(double offset) { if ((getLevel() == 2) && (getVersion() == 1)) { Double oldOffset = this.offset; isSetOffset = true; this.offset = Double.valueOf(offset); firePropertyChange(TreeNodeChangeEvent.offset, oldOffset, this.offset); } else { throw new PropertyNotAvailableException(TreeNodeChangeEvent.offset, this); } }
/** * * @return {@code true} if this Unit is a variant of length. */ public boolean isVariantOfLength() { Kind kind = getKind(); // Meter only allowed in Level 1 or -1 (level undefined) return (getLevel() < 2 && (kind == Kind.METER)) || (kind == Kind.METRE) && (getOffset() == 0d) && (getExponent() == 1d); }
/** * Sets the multiplier of this {@link Unit} * * @param multiplier * @throws PropertyNotAvailableException * if Level < 2 and the given {@code multiplier != 1}. */ public void setMultiplier(double multiplier) { if ((getLevel() < 2) && (multiplier != 1d) && !isInvalidSBMLAllowed()) { // added the multiplier test != 1 to prevent error being reported when it is not necessary throw new PropertyNotAvailableException(TreeNodeChangeEvent.multiplier, this); } Double oldMultiplyer = this.multiplier; isSetMultiplier = true; this.multiplier = multiplier; firePropertyChange(TreeNodeChangeEvent.multiplier, oldMultiplyer, this.multiplier); }
/** * Checks whether the given {@link Unit} and the {@link Unit} represented by * the given {@link String} are equivalent. * * @param unit * @param units * @return * @see #areEquivalent(Unit, Unit) */ public static boolean areEquivalent(Unit unit, String units) { return areEquivalent(unit, new Unit(1d, 0, Unit.Kind.valueOf(units), 1d, unit.getLevel(), unit.getVersion())); }
@Override public boolean readAttribute(String attributeName, String prefix, String value) { boolean isAttributeRead = super.readAttribute(attributeName, prefix, value); if (!isAttributeRead) { isAttributeRead = true; if (attributeName.equals("kind")) { try { Kind kind = Kind.valueOf(value.toUpperCase()); setKind(kind); } catch (Exception e) { isAttributeRead = false; } } else if (attributeName.equals("exponent")) { setExponent(getLevel() < 3 ? StringTools.parseSBMLInt(value) : StringTools.parseSBMLDouble(value)); } else if (attributeName.equals("scale")) { setScale(StringTools.parseSBMLInt(value)); } else if (attributeName.equals("multiplier")) { setMultiplier(StringTools.parseSBMLDouble(value)); } else if (attributeName.equals("offset")) { setOffset(StringTools.parseSBMLDouble(value)); } else { isAttributeRead = false; } } return isAttributeRead; }
@Override public Map<String, String> writeXMLAttributes() { Map<String, String> attributes = super.writeXMLAttributes(); int level = getLevel(), version = getVersion(); Locale en = Locale.ENGLISH;
double exp = unit.getExponent(); int scale = unit.getScale(); int l = unit.getLevel(); int v = unit.getVersion(); UnitDefinition ud = new UnitDefinition(l, v);