\n\n\n\nAmount\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\n\n\n\n\n
\n
\n
\n\n\n\n
\n
org.jscience.physics.amount
\n

## Class Amount<Q extends Quantity>

\n
\n
\n
\n
\n
\n
• \n
\n
All Implemented Interfaces:
\n
Serializable, Comparable<Measurable<Q>>, Measurable<Q>, javolution.lang.Immutable, javolution.lang.ValueType, Field<Amount<?>>, GroupAdditive<Amount<?>>, GroupMultiplicative<Amount<?>>, Ring<Amount<?>>, Structure<Amount<?>>
\n
\n
\n
\n
`public final class Amount<Q extends Quantity>\nextends Object\nimplements Measurable<Q>, Field<Amount<?>>, Serializable, javolution.lang.Immutable`
\n

This class represents a determinate or estimated amount for which \n operations such as addition, subtraction, multiplication and division\n can be performed (it implements the `Field` interface).

\n \n

The nature of an amount can be deduced from its parameterization \n (compile time) or its `unit` (run time).\n Its precision is given by its `error`.

\n \n

Amounts can be `exact`, in which case they can be\n expressed as an exact `long` integer in the amount unit.\n The framework tries to keep amount exact as much as possible.\n For example:

``\n        Amount<Length> m = Amount.valueOf(33, FOOT).divide(11).times(2);\n        System.out.println(m);\n        System.out.println(m.isExact() ? "exact" : "inexact");\n        System.out.println(m.getExactValue());\n        > 6 ft\n        > exact\n        > 6``
\n

\n \n

Errors (including numeric errors) are calculated using numeric intervals.\n It is possible to resolve systems of linear equations involving \n `matrices`, even if the \n system is close to singularity; in which case the error associated with\n some (or all) components of the solution may be large.

\n \n

By default, non-exact amounts are shown using the plus/minus \n character (\'\xc2\xb1\') (see `AmountFormat`). For example, \n `"(2.0 \xc2\xb1 0.001) km/s"` represents a velocity of \n 2 km/s with an absolute error of \xc2\xb1 1 m/s. Exact amount use an\n integer notation (no decimal point, e.g. `"2000 m"`).

\n \n

Operations between different amounts may or may not be authorized \n based upon the current `PhysicalModel`. For example, adding `Amount<Length> and \n Amount<Duration> is not allowed by the \n StandardModel, \n but is authorized with the RelativisticModel.`

`\nSee Also:\n Wikipedia: Measuring, \nSerialized Form\n`
• `\n`
`\n`
`\n\n\n\n\n\n\n\n\nField Summary\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nFields Modifier and TypeField and Descriptionstatic Amount<Dimensionless>ONE\nHolds a dimensionless measure of one (exact).\nstatic Amount<Dimensionless>ZERO\nHolds a dimensionless measure of zero (exact).\n\n\n\n\n\n\n\n\nMethod Summary\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nMethods Modifier and TypeMethod and DescriptionAmount<Q>abs()\nReturns the absolute value of this measure.\nbooleanapproximates(Amount that)\nIndicates if this measure approximates that measure.\nintcompareTo(Measurable<Q> that)\nCompares this measure with the specified measurable object.\nAmount<Q>copy() Amount<? extends Quantity>divide(Amount that)\nReturns this measure divided by the one specified.\nAmount<Q>divide(double divisor)\nReturns this measure divided by the specified approximate divisor\n (dimensionless).\nAmount<Q>divide(long divisor)\nReturns this measure divided by the specified exact divisor\n (dimensionless).\ndoubledoubleValue(Unit<Q> unit)\nReturns the value of this measurable stated in the specified unit as \n a double.\nbooleanequals(Object that)\nCompares this measure against the specified object for strict \n equality (same value interval and same units).\ndoublegetAbsoluteError()\nReturns the value by which theestimated \n value may differ from the true value (all stated in base units).\ndoublegetEstimatedValue()\nReturns the estimated value for this measure stated in this measure\n unit.\nlonggetExactValue()\nReturns the exact value for this measure stated in this measure\n unit.\ndoublegetMaximumValue()\nReturns the upper bound interval value for this measure stated in \n this measure unit.\ndoublegetMinimumValue()\nReturns the lower bound interval value for this measure stated in \n this measure unit.\ndoublegetRelativeError()\nReturns the percentage by which the estimated amount may differ\n from the true amount.\nUnit<Q>getUnit()\nReturns the unit in which the estimated value and absolute error\n are stated.\ninthashCode()\nReturns the hash code for this measure.\nAmount<? extends Quantity>inverse()\nReturns the multiplicative inverse of this measure.\nbooleanisExact()\nIndicates if this measure amount is exact.\nbooleanisGreaterThan(Amount<Q> that)\nIndicates if this measure is ordered after that measure\n (independently of the measure unit).\nbooleanisLargerThan(Amount<Q> that)\nCompares this measure with that measure ignoring the sign.\nbooleanisLessThan(Amount<Q> that)\nIndicates if this measure is ordered before that measure\n (independently of the measure unit).\nlonglongValue(Unit<Q> unit)\nReturns the estimated integral value of this measurable stated in \n the specified unit as a long.\nAmount<Q>minus(Amount that)\nReturns the difference of this measure with the one specified.\nAmount<Q>opposite()\nReturns the opposite of this measure.\nAmount<Q>plus(Amount that)\nReturns the sum of this measure with the one specified.\nAmount<? extends Quantity>pow(int exp)\nReturns this measure raised at the specified exponent.\nstatic <Q extends Quantity> Amount<Q>rangeOf(double minimum,\n double maximum,\n Unit<Q> unit)\nReturns the measure corresponding to the specified interval stated \n in the specified unit.\nAmount<? extends Quantity>root(int n)\nReturns the given root of this measure.\nAmount<? extends Quantity>sqrt()\nReturns the square root of this measure.\nAmount<? extends Quantity>times(Amount that)\nReturns the product of this measure with the one specified.\nAmount<Q>times(double factor)\nReturns this measure scaled by the specified approximate factor\n (dimensionless).\nAmount<Q>times(long factor)\nReturns this measure scaled by the specified exact factor \n (dimensionless).\n<R extends Quantity> Amount<R>to(Unit<R> unit)\nReturns the measure equivalent to this measure but stated in the \n specified unit.\nStringtoString()\nReturns the text representation of this amount as a \n java.lang.String.\njavolution.text.TexttoText()\nReturns the text representation of this measure.\nstatic Amount<?>valueOf(CharSequence csq)\nReturns the measure represented by the specified character sequence.\nstatic <Q extends Quantity> Amount<Q>valueOf(double value,\n double error,\n Unit<Q> unit)\nReturns the measure corresponding to the specified approximate value \n and measurement error, both stated in the specified unit.\nstatic <Q extends Quantity> Amount<Q>valueOf(double value,\n Unit<Q> unit)\nReturns the measure corresponding to an approximate value \n (double) stated in the specified unit; \n the precision of the measure is assumed to be the \n double precision (64 bits IEEE 754 format).\nstatic <Q extends Quantity> Amount<Q>valueOf(long value,\n Unit<Q> unit)\nReturns the exact measure corresponding to the value stated in the \n specified unit.\n\n\n\n\n\nMethods inherited from class java.lang.Object\ngetClass, notify, notifyAll, wait, wait, wait\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nField Detail\n\n\n\n\n\nZERO\npublic static final Amount<Dimensionless> ZERO\nHolds a dimensionless measure of zero (exact).\n\n\n\n\n\n\n\nONE\npublic static final Amount<Dimensionless> ONE\nHolds a dimensionless measure of one (exact).\n\n\n\n\n\n\n\n\n\nMethod Detail\n\n\n\n\n\nvalueOf\npublic static <Q extends Quantity> Amount<Q> valueOf(long value,\n Unit<Q> unit)\nReturns the exact measure corresponding to the value stated in the \n specified unit.\nParameters:value - the exact value stated in the specified unit.unit - the unit in which the value is stated.\nReturns:the corresponding measure object.\n\n\n\n\n\n\n\nvalueOf\npublic static <Q extends Quantity> Amount<Q> valueOf(double value,\n Unit<Q> unit)\nReturns the measure corresponding to an approximate value \n (double) stated in the specified unit; \n the precision of the measure is assumed to be the \n double precision (64 bits IEEE 754 format).\nParameters:value - the estimated value (\xc2\xb1 LSB) stated in the specified unit.unit - the unit in which the value is stated.\nReturns:the corresponding measure object.\n\n\n\n\n\n\n\nvalueOf\npublic static <Q extends Quantity> Amount<Q> valueOf(double value,\n double error,\n Unit<Q> unit)\nReturns the measure corresponding to the specified approximate value \n and measurement error, both stated in the specified unit.\nParameters:value - the estimated amount (\xc2\xb1 error) stated in the specified unit.error - the measurement error (absolute).unit - the unit in which the amount and the error are stated.\nReturns:the corresponding measure object.\nThrows:\nIllegalArgumentException - if error < 0.0\n\n\n\n\n\n\n\nrangeOf\npublic static <Q extends Quantity> Amount<Q> rangeOf(double minimum,\n double maximum,\n Unit<Q> unit)\nReturns the measure corresponding to the specified interval stated \n in the specified unit.\nParameters:minimum - the lower bound for the measure value.maximum - the upper bound for the measure value.unit - the unit for both the minimum and maximum values.\nReturns:the corresponding measure object.\nThrows:\nIllegalArgumentException - if minimum > maximum\n\n\n\n\n\n\n\nvalueOf\npublic static Amount<?> valueOf(CharSequence csq)\nReturns the measure represented by the specified character sequence.\nParameters:csq - the character sequence.\nReturns:AmountFormat.getInstance().parse(csq)\n\n\n\n\n\n\n\nisExact\npublic boolean isExact()\nIndicates if this measure amount is exact. An exact amount is \n guarantee exact only when stated in this measure unit\n (e.g. this.longValue()); stating the amount\n in any other unit may introduce conversion errors.\nReturns:true if this measure is exact;\n false otherwise.\n\n\n\n\n\n\n\ngetUnit\npublic Unit<Q> getUnit()\nReturns the unit in which the estimated value and absolute error\n are stated.\nReturns:the measure unit.\n\n\n\n\n\n\n\ngetExactValue\npublic long getExactValue()\n throws AmountException\nReturns the exact value for this measure stated in this measure\n unit.\nReturns:the exact measure value (long) stated \n in this measure\'s unit\nThrows:\nAmountException - if this measure is not isExact()\n\n\n\n\n\n\n\ngetEstimatedValue\npublic double getEstimatedValue()\nReturns the estimated value for this measure stated in this measure\n unit.\nReturns:the median value of the measure interval.\n\n\n\n\n\n\n\ngetMinimumValue\npublic double getMinimumValue()\nReturns the lower bound interval value for this measure stated in \n this measure unit.\nReturns:the minimum value.\n\n\n\n\n\n\n\ngetMaximumValue\npublic double getMaximumValue()\nReturns the upper bound interval value for this measure stated in \n this measure unit.\nReturns:the maximum value.\n\n\n\n\n\n\n\ngetAbsoluteError\npublic double getAbsoluteError()\nReturns the value by which theestimated \n value may differ from the true value (all stated in base units).\nReturns:the absolute error stated in base units.\n\n\n\n\n\n\n\ngetRelativeError\npublic double getRelativeError()\nReturns the percentage by which the estimated amount may differ\n from the true amount.\nReturns:the relative error.\n\n\n\n\n\n\n\nto\npublic <R extends Quantity> Amount<R> to(Unit<R> unit)\nReturns the measure equivalent to this measure but stated in the \n specified unit. The returned measure may not be exact even if this \n measure is exact due to conversion errors.\nParameters:unit - the unit of the measure to be returned.\nReturns:a measure equivalent to this measure but stated in the \n specified unit.\nThrows:\nConversionException - if the current model does not allows for\n conversion to the specified unit.\n\n\n\n\n\n\n\nopposite\npublic Amount<Q> opposite()\nReturns the opposite of this measure.\n\nSpecified by:\nopposite in interface GroupAdditive<Amount<?>>\nReturns:-this.\n\n\n\n\n\n\n\nplus\npublic Amount<Q> plus(Amount that)\n throws ConversionException\nReturns the sum of this measure with the one specified.\n\nSpecified by:\nplus in interface GroupAdditive<Amount<?>>\nParameters:that - the measure to be added.\nReturns:this + that.\nThrows:\nConversionException - if the current model does not allows for\n these quantities to be added.\n\n\n\n\n\n\n\nminus\npublic Amount<Q> minus(Amount that)\n throws ConversionException\nReturns the difference of this measure with the one specified.\nParameters:that - the measure to be subtracted.\nReturns:this - that.\nThrows:\nConversionException - if the current model does not allows for\n these quantities to be subtracted.\n\n\n\n\n\n\n\ntimes\npublic Amount<Q> times(long factor)\nReturns this measure scaled by the specified exact factor \n (dimensionless).\nParameters:factor - the scaling factor.\nReturns:this \xc2\xb7 factor.\n\n\n\n\n\n\n\ntimes\npublic Amount<Q> times(double factor)\nReturns this measure scaled by the specified approximate factor\n (dimensionless).\nParameters:factor - the scaling factor.\nReturns:this \xc2\xb7 factor.\n\n\n\n\n\n\n\ntimes\npublic Amount<? extends Quantity> times(Amount that)\nReturns the product of this measure with the one specified.\n\nSpecified by:\ntimes in interface GroupMultiplicative<Amount<?>>\nSpecified by:\ntimes in interface Ring<Amount<?>>\nParameters:that - the measure multiplier.\nReturns:this \xc2\xb7 that.\n\n\n\n\n\n\n\ninverse\npublic Amount<? extends Quantity> inverse()\nReturns the multiplicative inverse of this measure.\n If this measure is possibly zero, then the result is unbounded\n (]-infinity, +infinity[).\n\nSpecified by:\ninverse in interface GroupMultiplicative<Amount<?>>\nReturns:1 / this.\n\n\n\n\n\n\n\ndivide\npublic Amount<Q> divide(long divisor)\nReturns this measure divided by the specified exact divisor\n (dimensionless).\nParameters:divisor - the exact divisor.\nReturns:this / divisor.\nThrows:\nArithmeticException - if this measure is exact and the \n specified divisor is zero.\n\n\n\n\n\n\n\ndivide\npublic Amount<Q> divide(double divisor)\nReturns this measure divided by the specified approximate divisor\n (dimensionless).\nParameters:divisor - the approximated divisor.\nReturns:this / divisor.\n\n\n\n\n\n\n\ndivide\npublic Amount<? extends Quantity> divide(Amount that)\nReturns this measure divided by the one specified.\nParameters:that - the measure divisor.\nReturns:this / that.\n\n\n\n\n\n\n\nabs\npublic Amount<Q> abs()\nReturns the absolute value of this measure.\nReturns:|this|.\n\n\n\n\n\n\n\nsqrt\npublic Amount<? extends Quantity> sqrt()\nReturns the square root of this measure.\nReturns:sqrt(this)\n\n\n\n\n\n\n\nroot\npublic Amount<? extends Quantity> root(int n)\nReturns the given root of this measure.\nParameters:n - the root\'s order (n != 0).\nReturns:the result of taking the given root of this quantity.\nThrows:\nArithmeticException - if n == 0.\n\n\n\n\n\n\n\npow\npublic Amount<? extends Quantity> pow(int exp)\nReturns this measure raised at the specified exponent.\nParameters:exp - the exponent.\nReturns:thisexp\n\n\n\n\n\n\n\ncompareTo\npublic int compareTo(Measurable<Q> that)\nCompares this measure with the specified measurable object.\n\nSpecified by:\ncompareTo in interface Comparable<Measurable<Q extends Quantity>>\nParameters:that - the measure to compare with.\nReturns:a negative integer, zero, or a positive integer as this measure\n is less than, equal to, or greater than that measurable.\nThrows:\nConversionException - if the current model does not allows for\n these measure to be compared.\n\n\n\n\n\n\n\nequals\npublic boolean equals(Object that)\nCompares this measure against the specified object for strict \n equality (same value interval and same units).\n\nOverrides:\nequals in class Object\nParameters:that - the object to compare with.\nReturns:true if this measure is identical to that\n measure; false otherwise.\n\n\n\n\n\n\n\nhashCode\npublic int hashCode()\nReturns the hash code for this measure.\n\nOverrides:\nhashCode in class Object\nReturns:the hash code value.\n\n\n\n\n\n\n\napproximates\npublic boolean approximates(Amount that)\nIndicates if this measure approximates that measure.\n Measures are considered approximately equals if their value intervals\n overlaps. It should be noted that less accurate measurements are \n more likely to be approximately equals. It is therefore recommended\n to ensure that the measurement error is not too large before testing\n for approximate equality.\nReturns:this \xe2\x89\x85 that\n\n\n\n\n\n\n\nisLessThan\npublic boolean isLessThan(Amount<Q> that)\nIndicates if this measure is ordered before that measure\n (independently of the measure unit).\nReturns:this.compareTo(that) < 0.\n\n\n\n\n\n\n\nisGreaterThan\npublic boolean isGreaterThan(Amount<Q> that)\nIndicates if this measure is ordered after that measure\n (independently of the measure unit).\nReturns:this.compareTo(that) > 0.\n\n\n\n\n\n\n\nisLargerThan\npublic boolean isLargerThan(Amount<Q> that)\nCompares this measure with that measure ignoring the sign.\nReturns:|this| > |that|\n\n\n\n\n\n\n\ntoText\npublic javolution.text.Text toText()\nReturns the text representation of this measure.\nReturns:AmountFormat.getInstance().format(this)\n\n\n\n\n\n\n\ntoString\npublic final String toString()\nReturns the text representation of this amount as a \n java.lang.String.\n\nOverrides:\ntoString in class Object\nReturns:toText().toString()\n\n\n\n\n\n\n\ndoubleValue\npublic double doubleValue(Unit<Q> unit)\nDescription copied from interface: Measurable\nReturns the value of this measurable stated in the specified unit as \n a double. If the measurable has too great a magnitude to \n be represented as a double, it will be converted to \n Double.NEGATIVE_INFINITY or\n Double.POSITIVE_INFINITY as appropriate.\n\nSpecified by:\ndoubleValue in interface Measurable<Q extends Quantity>\nParameters:unit - the unit in which this measurable value is stated.\nReturns:the numeric value after conversion to type double.\n\n\n\n\n\n\n\nlongValue\npublic final long longValue(Unit<Q> unit)\nDescription copied from interface: Measurable\nReturns the estimated integral value of this measurable stated in \n the specified unit as a long. \n \n Note: This method differs from the Number.longValue()\n in the sense that the closest integer value is returned \n and an ArithmeticException is raised instead\n of a bit truncation in case of overflow (safety critical).\n\nSpecified by:\nlongValue in interface Measurable<Q extends Quantity>\nParameters:unit - the unit in which the measurable value is stated.\nReturns:the numeric value after conversion to type long.\n\n\n\n\n\n\n\ncopy\npublic Amount<Q> copy()\n\nSpecified by:\ncopy in interface javolution.lang.ValueType\n\n\n\n\n\n\n\n\n`
```\n\n\n\n\n\n\n\n\nOverview\nPackage\nClass\nTree\nIndex\nHelp\n\n\n\n\n\nPrev Class\nNext Class\n\n\nFrames\nNo Frames\n\n\nAll Classes\n\n\n<!--\n allClassesLink = document.getElementById("allclasses_navbar_bottom");\n if(window==top) {\n allClassesLink.style.display = "block";\n }\n else {\n allClassesLink.style.display = "none";\n }\n //-->\n\n\n\n\nSummary: \nNested | \nField | \nConstr | \nMethod\n\n\nDetail: \nField | \nConstr | \nMethod\n\n\n\n\n\n\nSCaVis 1.0 © jWork.org\n\n\n ```
``` © 2013 Powered by Doc2SQL Page generated in 0.0968070030212 seconds and 262 kB ```