org.sbml.jsbml
public class Unit extends AbstractSBase
Modifier and Type | Class and Description |
---|---|
static class |
Unit.Kind
This enumeration contains an exhaustive list of all available unit kinds
within all Levels and Versions of SBML.
|
Modifier and Type | Field and Description |
---|---|
private java.lang.Double |
exponent
Represents the 'exponent' XML attribute of an unit element.
|
private boolean |
isSetExponent |
private boolean |
isSetMultiplier |
private boolean |
isSetOffset |
private boolean |
isSetScale |
private Unit.Kind |
kind
Represents the 'kind' XML attribute of an unit element.
|
private static org.apache.log4j.Logger |
logger
A
Logger for this class. |
private java.lang.Double |
multiplier
Represents the 'multiplier' XML attribute of an unit element.
|
private java.lang.Double |
offset
Deprecated.
the offset attribute should no longer be used.
|
private java.lang.Integer |
scale
Represents the 'scale' XML attribute of an unit element.
|
private static long |
serialVersionUID
Generated serial version identifier.
|
ignoredExtensions, ignoredXMLElements, lv
listOfListeners, parent, UNKNOWN_ATTRIBUTES, UNKNOWN_ELEMENTS
Constructor and Description |
---|
Unit()
Creates a Unit instance.
|
Unit(double multiplier,
int scale,
Unit.Kind kind,
double exponent,
int level,
int version)
Creates a
Unit instance from a multiplier, scale, kind and exponent. |
Unit(int level,
int version)
Creates a
Unit instance from a level and version. |
Unit(int scale,
Unit.Kind kind,
double exponent,
int level,
int version)
Creates a Unit instance from a scale, kind, exponent, level and version.
|
Unit(int scale,
Unit.Kind kind,
int level,
int version)
Creates a Unit instance from a scale, kind, level and version.
|
Unit(java.lang.String units,
int level,
int version) |
Unit(Unit.Kind kind,
double exponent,
int level,
int version)
Creates a Unit instance from a kind, exponent, level and version.
|
Unit(Unit.Kind kind,
int level,
int version)
Creates a Unit instance from a kind, level and version.
|
Unit(Unit unit)
Creates a Unit instance from a given Unit.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
areEquivalent(Unit unit,
java.lang.String units)
|
static boolean |
areEquivalent(Unit unit1,
Unit unit2)
Predicate returning true or false depending on whether Unit objects are
equivalent.
|
static boolean |
areIdentical(Unit unit1,
Unit unit2)
Predicate returning true or false depending on whether two Unit objects
are identical.
|
Unit |
clone()
Creates a deep copy of this object, i.e., a new
SBase with the same properties
like this one. |
static UnitDefinition |
convertToSI(Unit unit)
Returns a UnitDefinition object which contains the argument Unit
converted to the appropriate SI unit.
|
boolean |
equals(java.lang.Object object)
|
double |
getExponent() |
double |
getExponentAsDouble()
Deprecated.
use
getExponent() |
Unit.Kind |
getKind() |
double |
getMultiplier() |
double |
getOffset()
Deprecated.
|
ListOf<Unit> |
getParent()
This is equivalent to calling
AbstractSBase.getParentSBMLObject() , but this
method is needed for TreeNode . |
java.lang.String |
getPrefix() |
java.lang.String |
getPrefixAsWord() |
int |
getScale() |
int |
hashCode() |
boolean |
hasRequiredAttributes()
Predicate returning true or false depending on whether all the required
attributes for this Unit object have been set.
|
void |
initDefaults()
Initializes the default values using the current Level/Version configuration.
|
void |
initDefaults(int level,
int version)
Initializes the attributes of this Unit (except for 'kind') to their
defaults values.
|
boolean |
isAmpere()
Predicate for testing whether this Unit is of the kind ampere.
|
boolean |
isAvogadro()
Predicate for testing whether this Unit is of the kind avogadro.
|
boolean |
isBecquerel()
Predicate for testing whether this Unit is of the kind becquerel.
|
static boolean |
isBuiltIn(java.lang.String name,
int level)
Deprecated.
|
boolean |
isCandela()
Predicate for testing whether this Unit is of the kind candela
|
boolean |
isCelsius()
Deprecated.
Unit.Kind.CELSIUS should no longer be used. |
boolean |
isCoulomb()
Predicate for testing whether this Unit is of the kind coulomb.
|
boolean |
isDimensionless()
Predicate for testing whether this Unit is of the
Unit.Kind
DIMENSIONLESS . |
boolean |
isFarad()
Predicate for testing whether this Unit is of the kind farad
|
boolean |
isGram()
Predicate for testing whether this Unit is of the kind gram
|
boolean |
isGray()
Predicate for testing whether this Unit is of the kind gray
|
boolean |
isHenry()
Predicate for testing whether this Unit is of the kind henry
|
boolean |
isHertz()
Predicate for testing whether this Unit is of the kind hertz
|
boolean |
isInvalid()
Predicate for testing whether this Unit is of the kind invalid.
|
boolean |
isItem()
Predicate for testing whether this Unit is of the kind item
|
boolean |
isJoule()
Predicate for testing whether this Unit is of the kind Joule
|
boolean |
isKatal()
Predicate for testing whether this Unit is of the kind katal
|
boolean |
isKelvin()
Predicate for testing whether this Unit is of the kind kelvin
|
boolean |
isKilogram()
Predicate for testing whether this Unit is of the kind kilogram
|
boolean |
isLitre()
Predicate for testing whether this Unit is of the kind litre.
|
boolean |
isLumen()
Predicate for testing whether this Unit is of the kind lumen
|
boolean |
isLux()
Predicate for testing whether this Unit is of the kind lux
|
boolean |
isMetre()
Predicate for testing whether this Unit is of the kind metre
|
boolean |
isMole()
Predicate for testing whether this Unit is of the kind mole.
|
boolean |
isNewton()
Predicate for testing whether this Unit is of the kind newton
|
boolean |
isOhm()
Predicate for testing whether this Unit is of the kind ohm
|
boolean |
isPascal()
Predicate for testing whether this Unit is of the kind pascal
|
static boolean |
isPredefined(java.lang.String name,
int level)
Predicate to test whether a given string is the name of a predefined SBML
unit.
|
static boolean |
isPredefined(UnitDefinition ud)
Tests whether the given
UnitDefinition belongs to the predefined
SBML units. |
boolean |
isRadian()
Predicate for testing whether this Unit is of the kind radian
|
boolean |
isSecond()
Predicate for testing whether this Unit is of the kind second
|
boolean |
isSetExponent() |
boolean |
isSetKind()
Predicate to test whether the 'kind' attribute of this
Unit has been set. |
boolean |
isSetMultiplier() |
boolean |
isSetOffset()
Deprecated.
the offset attribute should no longer be used.
|
boolean |
isSetScale() |
boolean |
isSiemens()
Predicate for testing whether this Unit is of the kind siemens
|
boolean |
isSievert()
Predicate for testing whether this Unit is of the kind sievert
|
boolean |
isSteradian()
Predicate for testing whether this Unit is of the kind steradian
|
boolean |
isTesla()
Predicate for testing whether this Unit is of the kind tesla
|
static boolean |
isUnitKind(java.lang.String name,
int level,
int version)
Predicate to test whether a given string is the name of a valid base unit
in SBML (such as 'gram' or 'mole').
|
static boolean |
isUnitKind(Unit.Kind kind,
int level,
int version) |
static boolean |
isValidUnit(Model model,
java.lang.String unit)
|
boolean |
isVariantOfArea() |
boolean |
isVariantOfLength() |
boolean |
isVariantOfSubstance() |
boolean |
isVariantOfTime() |
boolean |
isVariantOfVolume() |
boolean |
isVolt()
Predicate for testing whether this Unit is of the kind volt
|
boolean |
isWatt()
Predicate for testing whether this Unit is of the kind watt
|
boolean |
isWeber()
Predicate for testing whether this Unit is of the kind weber
|
static void |
merge(Unit unit1,
Unit unit2)
|
boolean |
readAttribute(java.lang.String attributeName,
java.lang.String prefix,
java.lang.String value)
If the attribute is an id or name attribute, it will set the id or name
of this object with the value of the XML attribute ('value').
|
Unit |
removeMultiplier()
This method tries to remove the
multiplier of this unit. |
Unit |
removeOffset()
We remove the offset by expressing it within a new
multiplier ,
m': |
Unit |
removeScale()
Manipulates the attributes of the Unit to express the unit with the value
of the scale attribute reduced to zero.
|
static void |
removeScale(Unit unit)
Manipulates the attributes of the Unit to express the unit with the value
of the scale attribute reduced to zero.
|
void |
setExponent(double exponent)
Sets the exponent of this
Unit |
void |
setExponent(int exponent)
Deprecated.
|
void |
setKind(Unit.Kind kind)
|
void |
setMultiplier(double multiplier)
Sets the multiplier of this
Unit |
void |
setOffset(double offset)
Deprecated.
Only defined for SBML Level 2 Version 1.
|
void |
setScale(int scale)
Sets the scale of this Unit
|
java.lang.String |
toString()
Produces a text formula representation of this unit.
|
void |
unsetExponent() |
void |
unsetKind() |
void |
unsetMultiplier() |
void |
unsetOffset()
Deprecated.
the offset attribute should no longer be used.
|
void |
unsetScale() |
java.util.Map<java.lang.String,java.lang.String> |
writeXMLAttributes() |
addCVTerm, addDeclaredNamespace, addExtension, appendNotes, appendNotes, checkLevelAndVersionCompatibility, createHistory, createPlugin, disablePackage, enablePackage, enablePackage, filterCVTerms, filterCVTerms, filterCVTerms, fireNodeRemovedEvent, getAllowsChildren, getAnnotation, getAnnotationString, getChildAt, getChildCount, getCVTerm, getCVTermCount, getCVTerms, getDeclaredNamespaces, getElementName, getExtension, getExtensionPackages, getHistory, getLevel, getLevelAndVersion, getMetaId, getModel, getNamespace, getNotes, getNotesString, getNumCVTerms, getNumPlugins, getParentSBMLObject, getPlugin, getSBMLDocument, getSBOTerm, getSBOTermID, getVersion, hasValidAnnotation, hasValidLevelVersionNamespaceCombination, isExtendedByOtherPackages, isPackageEnabled, isPackageURIEnabled, isPkgEnabled, isPkgURIEnabled, isSetAnnotation, isSetHistory, isSetLevel, isSetLevelAndVersion, isSetMetaId, isSetNotes, isSetParentSBMLObject, isSetPlugin, isSetSBOTerm, isSetVersion, isValidLevelAndVersionCombination, isValidMetaId, notifyChildChange, registerChild, setAnnotation, setHistory, setLevel, setLevelAndVersion, setMetaId, setNamespace, setNotes, setNotes, setParentSBML, setParentSBMLObject, setSBOTerm, setSBOTerm, setThisAsParentSBMLObject, setVersion, unregister, unsetAnnotation, unsetCVTerms, unsetExtension, unsetHistory, unsetMetaId, unsetNamespace, unsetNotes, unsetPlugin, unsetSBOTerm
addAllChangeListeners, addTreeNodeChangeListener, addTreeNodeChangeListener, children, clearUserObjects, containsUserObjectKey, filter, filter, filter, fireNodeAddedEvent, firePropertyChange, getIndex, getListOfTreeNodeChangeListeners, getNumChildren, getRoot, getTreeNodeChangeListenerCount, getUserObject, indexOf, isLeaf, isRoot, isSetParent, isSetUserObjects, putUserObject, removeAllTreeNodeChangeListeners, removeFromParent, removeTreeNodeChangeListener, removeTreeNodeChangeListener, removeUserObject, setParent, userObjectKeySet
finalize, getClass, notify, notifyAll, wait, wait, wait
removeTreeNodeChangeListener
addAllChangeListeners, addTreeNodeChangeListener, addTreeNodeChangeListener, clearUserObjects, containsUserObjectKey, filter, filter, filter, fireNodeAddedEvent, firePropertyChange, getListOfTreeNodeChangeListeners, getRoot, getTreeNodeChangeListenerCount, getUserObject, isRoot, isSetParent, isSetUserObjects, putUserObject, removeAllTreeNodeChangeListeners, removeFromParent, removeTreeNodeChangeListener, removeUserObject, userObjectKeySet
private static final transient org.apache.log4j.Logger logger
Logger
for this class.private static final long serialVersionUID
private java.lang.Double exponent
private boolean isSetExponent
private boolean isSetMultiplier
private boolean isSetOffset
private boolean isSetScale
private Unit.Kind kind
private java.lang.Double multiplier
@Deprecated private java.lang.Double offset
private java.lang.Integer scale
public Unit()
null
.public Unit(double multiplier, int scale, Unit.Kind kind, double exponent, int level, int version)
Unit
instance from a multiplier, scale, kind and exponent. The
offset is null
.multiplier
- scale
- kind
- exponent
- level
- version
- public Unit(int level, int version)
Unit
instance from a level and version. If the level is set and
is superior or equal to 3 the multiplier, scale, kind, offset and
exponent are null
.level
- version
- public Unit(int scale, Unit.Kind kind, double exponent, int level, int version)
scale
- kind
- exponent
- level
- version
- public Unit(int scale, Unit.Kind kind, int level, int version)
scale
- kind
- level
- version
- public Unit(Unit.Kind kind, double exponent, int level, int version)
kind
- exponent
- level
- version
- public Unit(Unit.Kind kind, int level, int version)
null
.kind
- public Unit(java.lang.String units, int level, int version)
units
- level
- version
- public Unit(Unit unit)
unit
- public static boolean areEquivalent(Unit unit, java.lang.String units)
unit
- units
- areEquivalent(Unit, Unit)
public static boolean areEquivalent(Unit unit1, Unit unit2)
Predicate returning true or false depending on whether Unit objects are equivalent.
Two Unit objects are considered to be equivalent if their 'kind' and 'exponent' attributes are equal. (Contrast this to the method areIdentical(Unit unit1, Unit unit2), which compares Unit objects with respect to all attributes, not just the kind and exponent.)
unit1
- the first Unit object to compareunit2
- the second Unit object to comparefalse
otherwise.public static boolean areIdentical(Unit unit1, Unit unit2)
Predicate returning true or false depending on whether two Unit objects are identical.
Two Unit objects are considered to be identical if they match in all attributes. (Contrast this to the method areEquivalent(Unit unit1, Unit unit2), which compares Unit objects only with respect to certain attributes.)
unit1
- the first Unit object to compareunit2
- the second Unit object to comparetrue
if all the attributes of unit1 are identical to the
attributes of unit2, false
otherwise.areEquivalent
public static UnitDefinition convertToSI(Unit unit)
unit
- the Unit object to convert to SI@Deprecated public static boolean isBuiltIn(java.lang.String name, int level)
isPredefined(String, int)
name
- a String
to be tested against the predefined unit
nameslevel
- the Level of SBML for which the determination should be made.
This is necessary because there are a few small differences in
allowed units between SBML Level 1 and Level 2.true
, if name is one of the five SBML predefined
unit identifiers ('substance', 'volume', 'area', 'length' or
'time'), false
otherwise. The predefined unit
identifiers 'length' and 'area' were added in Level 2 Version 1public static boolean isPredefined(java.lang.String name, int level)
name
- a String
to be tested against the predefined unit
nameslevel
- the Level of SBML for which the determination should be made.
This is necessary because there are a few small differences in
allowed units between SBML Level 1 and Level 2.true
, if name is one of the five SBML predefined
unit identifiers ('substance', 'volume', 'area', 'length' or
'time'), false
otherwise. The predefined unit
identifiers 'length' and 'area' were added in Level 2 Version 1public static boolean isPredefined(UnitDefinition ud)
UnitDefinition
belongs to the predefined
SBML units.ud
- the UnitDefinition
to test.true
, if name is one of the five SBML predefined
unit identifiers ('substance', 'volume', 'area', 'length' or
'time'), false
otherwise. The predefined unit
identifiers 'length' and 'area' were added in Level 2 Version 1isPredefined(String, int)
public static boolean isUnitKind(Unit.Kind kind, int level, int version)
kind
- level
- version
- public static boolean isUnitKind(java.lang.String name, int level, int version)
Predicate to test whether a given string is the name of a valid base unit in SBML (such as 'gram' or 'mole').
This method exists because prior to SBML Level 2 Version 3, an enumeration called UnitKind was defined by SBML. This enumeration was removed in SBML Level 2 Version 3 and its values were folded into the space of values of a type called UnitSId. This method therefore has less significance in SBML Level 2 Version 3 and Level 2 Version 4, but remains for backward compatibility and support for reading models in older Versions of Level 2.
name
- a string to be testedlevel
- an integer representing the SBML specification Levelversion
- an integer representing the SBML specification Versiontrue
if name is a valid UnitKind, false
otherwisepublic static boolean isValidUnit(Model model, java.lang.String unit)
true
if the unit
is a valid unit kind name or an
identifier of an existing UnitDefinition
.
If either the unit or model are null, it will return false.unit
- the identifier of a UnitDefinition
or a valid
Unit.Kind
identifier for the current level/version
combination of the model.model
- the model where to look for the unit
.true
if the unit is a valid unit kind name or an identifier of an
existing UnitDefinition
.public static void removeScale(Unit unit)
unit
- the Unit object to manipulate.public Unit clone()
SBase
SBase
with the same properties
like this one.clone
in interface SBase
clone
in class AbstractSBase
public boolean equals(java.lang.Object object)
SBase
true
if and only if the given SBase
has exactly the same
properties like this SBase
instance.equals
in interface SBase
equals
in class AbstractSBase
true
if and only if the given Object
is an instance of
SBase
that has exactly the same properties like this
SBase instance.public double getExponent()
Unit
if it is set, 1 otherwise.@Deprecated public double getExponentAsDouble()
getExponent()
Unit
. This method is provided for
compatibility to libSBML only.public Unit.Kind getKind()
public double getMultiplier()
@Deprecated public double getOffset()
Unit
if it is set, 0 otherwise.public ListOf<Unit> getParent()
AbstractSBase
AbstractSBase.getParentSBMLObject()
, but this
method is needed for TreeNode
.getParent
in interface javax.swing.tree.TreeNode
getParent
in class AbstractSBase
AbstractSBase.getParentSBMLObject()
public java.lang.String getPrefix()
Unit
,
for instance, "m" for milli, i.e., if the scale is -3. In case
that the scale
equals zero, an empty String
is
returned. If no defined prefix exists for the current scale
,
the String
10^(%d)
is returned, where
%d
denotes the scale
.getPrefixAsWord()
public java.lang.String getPrefixAsWord()
public int getScale()
public int hashCode()
hashCode
in interface SBase
hashCode
in class AbstractSBase
Object.hashCode()
public boolean hasRequiredAttributes()
public void initDefaults()
public void initDefaults(int level, int version)
public boolean isAmpere()
public boolean isAvogadro()
true
if the kind of this Unit is avogadro, false
otherwise.public boolean isBecquerel()
public boolean isCandela()
@Deprecated public boolean isCelsius()
Unit.Kind.CELSIUS
should no longer be used.public boolean isCoulomb()
public boolean isDimensionless()
Unit.Kind
DIMENSIONLESS
. A unit is also dimensionless if it does not
declare an offset and at the same time its exponent is zero. In this case
the unit represents a dimensionless quantity.Unit.Kind
is DIMENSIONLESS
or offset = exponent = 0public boolean isFarad()
public boolean isGram()
public boolean isGray()
public boolean isHenry()
public boolean isHertz()
public boolean isInvalid()
public boolean isItem()
public boolean isJoule()
public boolean isKatal()
public boolean isKelvin()
public boolean isKilogram()
public boolean isLitre()
true
if the kind of this Unit is litre or 'liter', false
otherwise.public boolean isLumen()
public boolean isLux()
public boolean isMetre()
public boolean isMole()
true
if the kind of this Unit is mole, false
otherwise.public boolean isNewton()
public boolean isOhm()
public boolean isPascal()
public boolean isRadian()
public boolean isSecond()
public boolean isSetExponent()
true
if the exponent of this Unit is not null
.public boolean isSetKind()
Unit
has been set.public boolean isSetMultiplier()
true
if the multiplier of this Unit is not null
.@Deprecated public boolean isSetOffset()
public boolean isSetScale()
true
if the scale of this Unit is not null
.public boolean isSiemens()
public boolean isSievert()
public boolean isSteradian()
public boolean isTesla()
public boolean isVariantOfArea()
true
if this Unit is a variant of area.public boolean isVariantOfLength()
true
if this Unit is a variant of length.public boolean isVariantOfSubstance()
true
if this Unit is a variant of substance.public boolean isVariantOfTime()
public boolean isVariantOfVolume()
true
if this Unit is a variant of volume.public boolean isVolt()
public boolean isWatt()
public boolean isWeber()
public boolean readAttribute(java.lang.String attributeName, java.lang.String prefix, java.lang.String value)
SBase
readAttribute
in interface SBase
readAttribute
in class AbstractSBase
attributeName
- localName of the XML attributeprefix
- prefix of the XML attributevalue
- value of the XML attributetrue
if the attribute has been successfully read.public Unit removeMultiplier()
multiplier
of this unit.
Nothing will happen in the case that there is no multiplier
.
Otherwise, it first computes the decadic logarithm of the
multiplier
.
If this logarithm is either an integer or nearly an integer (with an
accepted
error of 10-24), it is added to the scale
and the
multiplier
is set to 1.
Note that it is not always possible to remove the multiplier
without loosing information. In order to avoid computational errors,
nothing is done if the rounding error would be too large.Unit
.public Unit removeOffset()
multiplier
,
m':
m' = offset
/ 10^scale
+ multiplier
When inserting this again into the unit formula, the offset vanishes:
((offset
+ multiplier
* 10^scale
) *
kind
)^exponent
then becomes
(0 + (offset
/ 10^scale
+ multiplier
) * 10^scale
* kind
)^exponent
=
(m' * 10^scale
* kind
)^exponent
This is possible because offset and multiplier are real double numbers.
Unit
whose offset
and multiplier
might have been changed in case that there was an offset
defined that was different to zero.public Unit removeScale()
public void setExponent(double exponent)
Unit
exponent
- @Deprecated public void setExponent(int exponent)
setExponent(double)
Unit
exponent
- public void setKind(Unit.Kind kind)
kind
- public void setMultiplier(double multiplier)
Unit
multiplier
- PropertyNotAvailableException
- if Level < 2 and the given multiplier != 1
.@Deprecated public void setOffset(double offset)
Unit
offset
- PropertyNotAvailableException
- if Level/Version combination is not 2.1.public void setScale(int scale)
scale
- public java.lang.String toString()
toString
in class AbstractSBase
public void unsetExponent()
public void unsetKind()
public void unsetMultiplier()
@Deprecated public void unsetOffset()
public void unsetScale()
public java.util.Map<java.lang.String,java.lang.String> writeXMLAttributes()
writeXMLAttributes
in interface SBase
writeXMLAttributes
in class AbstractSBase
Map
containing the XML attributes of this object.