|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Number
com.dautelle.math.numbers.RealtimeNumber
com.dautelle.physics.Quantity
This class represents a measurable amount. The nature of the amount is deduced from the quantity's unit. The quality of the measurement is given by the measurement error.
Errors (including numeric errors) are calculated using numeric intervals.
It is possible to resolve systems of linear equations involving physical
quantities (e.g. using Matrix
), even if the
system is close to singularity. In this latter case the error associated
with some (or all) components of the solution is potentially large.
The decimal representations of quantities instances are indicative of
their precision as only digits guaranteed to be exact are written out.
For example, the string "2.000 km/s"
represents a
Velocity
of (2.0 ± 0.001) km/s
.
Finally, operations between quantities may or may not be authorized
based upon the current PhysicalModel
(e.g. adding a length
to a duration
is not allowed by the StandardModel
, but is authorized with the RelativisticModel
).
Nested Class Summary | |
static class |
Quantity.Factory
This inner-class represents the ObjectFactory producing
Quantity instances. |
static class |
Quantity.Value
This inner class represents a mutable image of an imutable Quantity . |
Constructor Summary | |
protected |
Quantity()
Default constructor. |
Method Summary | |
Quantity |
abs()
Returns the absolute value of this quantity. |
Quantity |
add(Quantity that)
Returns the sum of this quantity with the one specified. |
java.lang.StringBuffer |
appendTo(java.lang.StringBuffer sb,
Unit outputUnit)
Appends the text representation of this quantity stated in the specified unit to the StringBuffer argument. |
static boolean |
approxEquals(Matrix left,
Matrix right)
Indicates if the Quantity elements of the specified
matrices are approximately equals. |
boolean |
approxEquals(Quantity that)
Indicates if this quantity is approximately equals to the specified quantity. |
int |
compareTo(java.lang.Object obj)
Compares this object with the specified object for order. |
Quantity |
divide(double divisor)
Returns this quantity divided by the specified divisor. |
Quantity |
divide(Quantity that)
Returns the division of this quantity by the one specified. |
double |
doubleValue()
Returns the estimated value stated in this quantity's system unit as a double . |
double |
doubleValue(Unit unit)
Returns the estimated value of this quantity stated in the specified unit as a double . |
boolean |
equals(java.lang.Object obj)
Indicates if this quantity is strictly equals to the object specified. |
float |
floatValue()
Returns the estimated value stated in this quantity's system unit as a float . |
float |
floatValue(Unit unit)
Returns the estimated value of this quantity stated in the specified unit as a float . |
double |
getAbsoluteError()
Returns the value by which the estimated amount may differ from the true amount. |
double |
getMaximum()
Returns the maximum amount for this quantity. |
double |
getMinimum()
Returns the minimum amount for this quantity. |
Unit |
getOutputUnit()
Returns the unit that this quantity is showed as. |
double |
getRelativeError()
Returns the percentage by which the estimated amount may differ from the true amount. |
Unit |
getSystemUnit()
Returns the system unit for this quantity. |
int |
hashCode()
Returns a hash code value for this quantity. |
int |
intValue()
Returns the estimated value stated in this quantity's system unit as a int . |
int |
intValue(Unit unit)
Returns the estimated value of this quantity stated in the specified unit as a int . |
Quantity |
inverse()
Returns the inverse of this quantity. |
boolean |
isPossiblyZero()
Indicates if this quantity is possibly amounting to nothing. |
long |
longValue()
Returns the estimated value stated in this quantity's system unit as a long . |
long |
longValue(Unit unit)
Returns the estimated value of this quantity stated in the specified unit as a long . |
Quantity |
multiply(double factor)
Returns this quantity multiplied by the specified factor. |
Quantity |
multiply(Quantity that)
Returns the product of this quantity with the one specified. |
Quantity |
negate()
Returns the negation of this quantity. |
Operable |
opposite()
Returns the additive inverse of this object. |
Operable |
plus(Operable that)
Returns the sum of this object with the one specified. |
Quantity |
pow(double exp)
Returns the quantity equals to this quantity raised to an exponent. |
double |
random()
Returns a random but possible value for this quantity. |
Operable |
reciprocal()
Returns the multiplicative inverse of this object. |
Quantity |
root(int n)
Returns the given root of this quantity. |
Quantity |
subtract(Quantity that)
Returns the difference of this quantity with the one specified. |
Operable |
times(Operable that)
Returns the product of this object with the one specified. |
java.lang.String |
toString()
Returns the text representation of this quantity using the local quantity format. |
java.lang.String |
toString(Unit outputUnit)
Returns the text representation of this quantity stated in the specified unit. |
void |
toXml(XmlElement xml)
Sets the attributes and content of the XML element corresponding to this object. |
static Quantity |
valueOf(java.lang.CharSequence chars)
Returns the Quantity from the specified character sequence. |
static Quantity |
valueOf(double amount,
double error,
Unit unit)
Returns the Quantity of specified amount and measurement error. |
static Quantity |
valueOf(double amount,
Unit unit)
Returns the Quantity of specified amount. |
static Quantity |
valueOf(XmlElement xml)
XML factory method. |
Methods inherited from class com.dautelle.math.numbers.RealtimeNumber |
clone, export, isLocalObject, isPoolObject, pow, recycle, toHeap |
Methods inherited from class java.lang.Number |
byteValue, shortValue |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
protected Quantity()
Method Detail |
public static Quantity valueOf(java.lang.CharSequence chars)
Quantity
from the specified character sequence.
The system unit of the specified quantity determinates
the class of the quantity being returned. For example:Quantity.valueOf("1.2 GeV")returns an
Energy
instance.
chars
- the character sequence.
QuantityFormat.getInstance().parse(chars)
java.lang.IllegalArgumentException
- if the specified character sequence
cannot be parsed.public static Quantity valueOf(double amount, Unit unit)
Quantity
of specified amount.
The system unit of the specified unit determinates the class of the
quantity being returned. For example:Quantity.valueOf(30, NonSI.FOOT)returns a
Length
instance.
amount
- the estimated amount (± 1/2 LSB).unit
- the amount's unit.
Quantity
.public static Quantity valueOf(double amount, double error, Unit unit)
Quantity
of specified amount and measurement error.
The system unit of the specified unit determinates the class of the
quantity being returned. For example:Quantity.valueOf(20, 0.1, SI.KILO(SI.HERTZ))returns a
Frequency
instance.
amount
- the estimated amount (± error).error
- the measurement error (absolute).unit
- the amount's unit.
Quantity
.public static Quantity valueOf(XmlElement xml)
<Quantity amount="12.3" error="1.0E-4" unit="µA"/>returns an
ElectricCurrent
instance.
Note: In the future, the tag name (class) will identify the quantity to return (to support model-dependent conversion). For example:
<Mass amount="12" error="0.01" unit="GeV"/>which is valid input in a relativistic context, should produce a
Mass
instance (and not an Energy
)
when deserialized. It is assumed that the same relativistic model is
selected during deserialization (to avoid conversion errors).
xml
- the XML element describing the Quantity
to return.
Quantity
.public final Unit getSystemUnit()
public Unit getOutputUnit()
showAs(Unit)
static method.
getModel().unitFor(this)
toString()
,
toXml(com.dautelle.xml.XmlElement)
public final double getAbsoluteError()
public final double getRelativeError()
public final double getMinimum()
public final double getMaximum()
public final boolean isPossiblyZero()
true
if this quantity can be zero;
false
otherwise.public final Quantity negate()
-this
.public final Quantity add(Quantity that) throws ConversionException
that
- the quantity to be added.
this + that
.
ConversionException
- if the current model does not allows for
these quantities to be added.public final Quantity subtract(Quantity that) throws ConversionException
that
- the quantity to be subtracted.
this - that
.
ConversionException
- if the current model does not allows for
these quantities to be subtracted.public final Quantity multiply(double factor)
factor
- the multiplier.
this * factor
.public final Quantity multiply(Quantity that)
that
- the quantity multiplier.
this * that
.public final Quantity inverse()
1 / this
.isPossiblyZero()
public final Quantity divide(double divisor)
divisor
- the divisor.
this / divisor
.public final Quantity divide(Quantity that)
that
- the quantity divisor.
this / that
.public final Quantity root(int n)
n
- the root's order (n >= 0).
java.lang.ArithmeticException
- if n == 0
.public final Quantity pow(double exp)
exp
- the exponent.
thisexp
java.lang.ArithmeticException
- if the exponent is a non-integer value and
this quantity is not dimensionless.public final Quantity abs()
abs(this)
.public final double random()
this.getMinimum{} < r > this.getMaximum()
.public final boolean equals(java.lang.Object obj)
Note: Unlike approxEquals(com.dautelle.physics.Quantity)
, this method does not take into
account possible errors (e.g. numeric errors).
obj
- the object to compare with.
true
if this quantity and the specified object
represent the exact same quantity; false
otherwise.public final int hashCode()
equals(java.lang.Object)
public final boolean approxEquals(Quantity that)
that
- the quantity to compare with.
this ≊ that
.public static final boolean approxEquals(Matrix left, Matrix right)
Quantity
elements of the specified
matrices are approximately equals.
left
- the first matrix to compare.right
- the second matrix to compare.
true
if both matrices have same dimension and
their quantity elements are approximately equals;
false
otherwise.
java.lang.ClassCastException
- if the specified matrices are not composed of
Quantity
elements.approxEquals(com.dautelle.physics.Quantity)
public final int compareTo(java.lang.Object obj)
Note: This comparator imposes orderings that are inconsistent
with equals. In particular, this.compareTo(that) == 0
does not imply this.equals(that)
(but the reverse
is true).
compareTo
in interface java.lang.Comparable
obj
- the object to be compared.
java.lang.ClassCastException
- if the specified object's type prevents it
from being compared to this object.
ConversionException
- if the current model does not allows for
these quantities to be compared.Unit.isCompatible(javax.units.Unit)
public final java.lang.String toString()
toString(getOutputUnit())
toString(Unit)
public final java.lang.String toString(Unit outputUnit)
outputUnit
- the unit this quantity is showed as.
appendTo(new StringBuffer(), outputUnit).toString()
appendTo(StringBuffer, Unit)
public java.lang.StringBuffer appendTo(java.lang.StringBuffer sb, Unit outputUnit)
StringBuffer
argument.
Only the digits guaranteed to be exact are written out.
In other words, the error is always on the last digit and less than
the last digit weight. For example, if "1.33" is appended then the
quantity is guaranteed to be in the range ]1.32, 1.34[
.
Note: Sub-classes with custom formatting should override this method.
sb
- the StrinBuffer
to append.outputUnit
- the unit this quantity is showed as.
StringBuffer
object.
ConversionException
- if the current model does not allow this
quantity to be stated in the specified unit.public final int intValue()
int
. This may involve rounding or truncation.
int
.public final long longValue()
long
. This may involve rounding or truncation.
long
.public final float floatValue()
float
. This may involve rounding.
float
.public final double doubleValue()
double
.
double
.public final int intValue(Unit unit)
int
. This may involve rounding or truncation.
unit
- the unit for the returned value.
int
.
ConversionException
- if the current model does not allow this
quantity to be stated in the specified unit.public final long longValue(Unit unit)
long
. This may involve rounding or truncation.
unit
- the unit for the returned value.
long
.
ConversionException
- if the current model does not allow this
quantity to be stated in the specified unit.public final float floatValue(Unit unit)
float
. This may involve rounding.
unit
- the unit for the returned value.
float
.
ConversionException
- if the current model does not allow this
quantity to be stated in the specified unit.public final double doubleValue(Unit unit)
double
.
unit
- the unit for the returned value.
double
.
ConversionException
- if the current model does not allow this
quantity to be stated in the specified unit.public final Operable plus(Operable that)
Operable
plus
in interface Operable
that
- the object to be added.
this + that
.public final Operable opposite()
Operable
this.plus(this.opposite()) == ZERO
,
with ZERO
being the additive identity.
opposite
in interface Operable
-this
.public final Operable times(Operable that)
Operable
times
in interface Operable
that
- the object multiplier.
this * that
.public final Operable reciprocal()
Operable
this.times(this.reciprocal()) == ONE
,
with ONE
being the multiplicative identity.
reciprocal
in interface Operable
ONE / this
.public void toXml(XmlElement xml)
Representable
toXml
in interface Representable
xml
- the XML element to set according to this object's desired XML
representation.
|
JADE v6.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |