Provides static methods working on
Quantity
instances.
Apache SIS implementation of quantities has the following characteristics:
- Values are stored with
double
precision. - All quantities implement the specific subtype (e.g.
Length
instead ofQuantity<Length>
). - Quantities are immutable,
Comparable
andSerializable
.
- Since:
- 0.8
-
Method Summary
Modifier and TypeMethodDescriptionstatic <Q extends Quantity<Q>>
QcastOrCopy
(Quantity<Q> quantity) Returns the given quantity as an instance of the specificQuantity
subtype.static Quantity
<?> Creates a quantity for the given value and unit of measurement symbol.static <Q extends Quantity<Q>>
QCreates a quantity for the given value and unit of measurement.Returns the largest of two quantities.Returns the smallest of two quantities.
-
Method Details
-
create
Creates a quantity for the given value and unit of measurement symbol. This is a convenience method that combines a call toUnits.valueOf(String)
withcreate(double, Unit)
.- Parameters:
value
- the quantity magnitude.unit
- symbol of the unit of measurement associated to the given value.- Returns:
- a quantity of the given type for the given value and unit of measurement.
- Throws:
MeasurementParseException
- if the given symbol cannot be parsed.
-
create
Creates a quantity for the given value and unit of measurement.- Type Parameters:
Q
- the quantity type (e.g.Length
,Angle
,Time
, etc.).- Parameters:
value
- the quantity magnitude.unit
- the unit of measurement associated to the given value.- Returns:
- a quantity of the given type for the given value and unit of measurement.
- Throws:
IllegalArgumentException
- if the given unit class is not a supported implementation.- See Also:
-
castOrCopy
Returns the given quantity as an instance of the specificQuantity
subtype. For example, this method can be used for converting aQuantity<Length>
to aLength
. If the given quantity already implements the specific interface, then it is returned as-is.- Type Parameters:
Q
- the quantity type (e.g.Length
,Angle
,Time
, etc.), ornull
.- Parameters:
quantity
- the quantity to convert to the specific subtype.- Returns:
- the given quantity as a specific subtype (may be
quantity
itself), ornull
if the given quantity was null. - Throws:
IllegalArgumentException
- if the unit class associated to the given quantity is not a supported implementation.
-
min
Returns the smallest of two quantities. Values are converted to system unit before to be compared. If one of the two quantities isnull
or has NaN value, then the other quantity is returned. If the two quantities have equal converted values, then the first quantity is returned.- Type Parameters:
Q
- type of quantities.- Parameters:
q1
- the first quantity (can benull
).q2
- the second quantity (can benull
).- Returns:
- the smallest of the two given quantities.
- Since:
- 1.1
-
max
Returns the largest of two quantities. Values are converted to system unit before to be compared. If one of the two quantities isnull
or has NaN value, then the other quantity is returned. If the two quantities have equal converted values, then the first quantity is returned.- Type Parameters:
Q
- type of quantities.- Parameters:
q1
- the first quantity (can benull
).q2
- the second quantity (can benull
).- Returns:
- the largest of the two given quantities.
- Since:
- 1.1
-