org.apache.sis.measure

## Class Quantities

- Object
- - Static
  - - Quantities

-     public final class Quantities
      extends Static

  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 of `Quantity<Length>`).
  - Quantities are immutable, `Comparable` and `Serializable`.
  Since:
    0.8

  Defined in the `sis-utility` module

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <Q extends Quantity<Q>> Q` | `castOrCopy(Quantity<Q> quantity)` Returns the given quantity as an instance of the specific `Quantity` subtype.
    `static Quantity<?>` | `create(double value, String unit)` Creates a quantity for the given value and unit of measurement symbol.
    `static <Q extends Quantity<Q>> Q` | `create(double value, Unit<Q> unit)` Creates a quantity for the given value and unit of measurement.

    - ### Methods inherited from class Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### create

          public static Quantity<?> create(double value,
                                           String unit)

      Creates a quantity for the given value and unit of measurement symbol. This is a convenience method that combines a call to `Units​.valueOf(String)` with `create(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:
        `ParserException` - if the given symbol can not be parsed.

    - #### create

          public static <Q extends Quantity<Q>> Q create(double value,
                                                         Unit<Q> unit)

      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:
        `UnitServices​.getQuantityFactory(Class)`

    - #### castOrCopy

          public static <Q extends Quantity<Q>> Q castOrCopy(Quantity<Q> quantity)

      Returns the given quantity as an instance of the specific `Quantity` subtype. For example this method can be used for converting a `Quantity<Length>` to a `Length`. 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.), or `null`.
      Parameters:
        `quantity` - the quantity to convert to the specific subtype.
      Returns:
        the given quantity as a specific subtype (may be `quantity` itself), or `null` if the given quantity was null.
      Throws:
        `IllegalArgumentException` - if the unit class associated to the given quantity is not a supported implementation.

Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.