abstract class ScalarQuantity<U extends TypedUnit<U>> extends java.lang.Number implements ITypedQuantity<U>
Note: This class has a natural ordering that is inconsistent with equals.
(This is because different instances may express the same quantity with different precision. This
is inherent to implementations of IQuantity, irrespective of class hierarchies.)
| Modifier and Type | Class and Description |
|---|---|
static class |
ScalarQuantity.DoubleStored<U extends TypedUnit<U>> |
static class |
ScalarQuantity.LongStored<U extends TypedUnit<U>> |
| Modifier and Type | Field and Description |
|---|---|
private static long |
serialVersionUID |
protected U |
unit |
AUTO, EXACT, VERBOSE| Modifier | Constructor and Description |
|---|---|
protected |
ScalarQuantity(U unit) |
| Modifier and Type | Method and Description |
|---|---|
IQuantity |
add(IQuantity addend)
Returns a new quantity that is the arithmetic sum of this quantity and
addend, if
such an operation is defined for this kind of quantity. |
int |
compareTo(IQuantity other) |
java.lang.String |
displayUsing(java.lang.String formatIdentifier)
Format this object for display purposes, preferably using the formatter hinted by
formatHint. |
abstract boolean |
equals(java.lang.Object obj) |
KindOfQuantity<U> |
getType()
Get the kind of this quantity.
|
U |
getUnit() |
abstract int |
hashCode() |
IQuantity |
in(IUnit targetUnit)
Get this quantity expressed in the unit
targetUnit. |
ITypedQuantity<U> |
in(U targetUnit)
Get this quantity expressed in the unit
targetUnit. |
java.lang.String |
interactiveFormat()
An exact string representation taking locale and internationalization into account.
|
java.lang.String |
interactiveFormat(boolean allowCustomUnit) |
boolean |
isLinear()
If this quantity is linear.
|
long |
longValueIn(IUnit targetUnit)
Get the numerical quantity value that this quantity would have if expressed in the unit
targetUnit, rounded to a mathematical integer, if that numerical value can be
represented in a long. |
IQuantity |
subtract(IQuantity subtrahend)
Returns a new quantity that is the arithmetic difference of this quantity and
subtrahend, if such an operation is defined for this kind of quantity. |
protected abstract ITypedQuantity<U> |
subtractLinear(ITypedQuantity<LinearUnit> subtrahend) |
byteValue, doubleValue, floatValue, intValue, longValue, shortValueclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitadd, floorQuantize, localizedFormat, multiply, multiply, subtractclampedFloorIn, clampedIntFloorIn, clampedLongValueIn, doubleValue, doubleValueIn, longValue, longValueIn, numberValue, numberValueIn, persistableString, ratioToprivate static final long serialVersionUID
protected ScalarQuantity(U unit)
public U getUnit()
public KindOfQuantity<U> getType()
IQuantitypublic int compareTo(IQuantity other)
compareTo in interface java.lang.Comparable<IQuantity>public abstract boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic abstract int hashCode()
hashCode in class java.lang.Objectpublic IQuantity in(IUnit targetUnit)
IQuantitytargetUnit. Note that as a result of this
conversion, precision may be lost. Partly due to that fact, this method should generally not
be used. If the ultimate goal is some pure numerical value, there are more suitable methods,
some of which are listed below, which directly provides such values. In either case, the
quantity returned from this method should not be kept alive, as the original quantity
provides better precision.in in interface IQuantitytargetUnitIQuantity.doubleValueIn(IUnit),
IQuantity.numberValueIn(IUnit),
IQuantity.clampedLongValueIn(IUnit),
IQuantity.ratioTo(IQuantity)public ITypedQuantity<U> in(U targetUnit)
ITypedQuantitytargetUnit. Note that as a result of this
conversion, precision may be lost. Note that this method differs from IQuantity.in(IUnit) only
by stricter typing.in in interface ITypedQuantity<U extends TypedUnit<U>>targetUnitpublic long longValueIn(IUnit targetUnit) throws QuantityConversionException
IQuantitytargetUnit, rounded to a mathematical integer, if that numerical value can be
represented in a long. Otherwise, an QuantityConversionException will be
thrown, with the violation encoded. Note that as a result of this conversion, precision may
be lost.
This method is equivalent to longValueIn(IUnit,
Long.MAX_VALUE).
longValueIn in interface IQuantitylongQuantityConversionException - if the result would be out of rangeIQuantity.numberValueIn(IUnit)public final java.lang.String interactiveFormat()
IQuantityKindOfQuantity.parseInteractive(String) (by this quantity's kind of
quantity), in the same locale, yields a value that is equal to
this quantity. That is, the exact representation must be preserved.interactiveFormat in interface IQuantitypublic final java.lang.String interactiveFormat(boolean allowCustomUnit)
interactiveFormat in interface ITypedQuantity<U extends TypedUnit<U>>public java.lang.String displayUsing(java.lang.String formatIdentifier)
IDisplayableformatHint. If no such formatter is defined for this type, the default formatter will
be used.displayUsing in interface IDisplayableformatIdentifier - the format hintpublic boolean isLinear()
IQuantitypublic IQuantity add(IQuantity addend) throws java.lang.IllegalArgumentException
IQuantityaddend, if
such an operation is defined for this kind of quantity. This operation is commutative, so
that a.add(b) produces the same result, or throws the same kind of exception, as
b.add(a).
Note that if this quantity is linear, adding a quantity of the same kind is guaranteed to succeed and produces a quantity of the same kind. Also, the sum of a non-linear quantity and a linear quantity of a specific related (delta) kind of quantity is defined and produces a non-linear quantity. However, two non-linear quantities may never be added.
public IQuantity subtract(IQuantity subtrahend) throws java.lang.IllegalArgumentException
IQuantitysubtrahend, if such an operation is defined for this kind of quantity. This operation
is anti-commutative when this quantity and subtrahend are of the same kind. That is,
when the result is linear.
Quantities of the same kind may be subtracted, giving a linear result. Additionally, a linear quantity may be subtracted from a non-linear quantity, provided their kinds are related.
protected abstract ITypedQuantity<U> subtractLinear(ITypedQuantity<LinearUnit> subtrahend)