Class Quantities

java.lang.Object
org.episteme.core.measure.Quantities

public final class Quantities extends Object
Factory for creating Quantity instances.

Provides convenient factory methods for creating physical quantities.

Example Usage:

import static org.episteme.core.measure.Units.*;

// Create quantities
Quantity<Length> distance = Quantities.create(100, METER);
Quantity<Time> time = Quantities.create(10, SECOND);

// Perform calculations
Quantity<Velocity> speed = distance.divide(time);  // 10 m/s

// Convert units
Quantity<Velocity> kmh = speed.to(KILOMETER_PER_HOUR);  // 36 km/h

* @author Silvere Martin-Michiellot
Since:
1.0
Author:
Gemini AI (Google DeepMind)
  • Method Details

    • create

      public static <Q extends Quantity<Q>> Quantity<Q> create(Real value, Unit<Q> unit)
      Creates a quantity from a Real value and unit.
      Type Parameters:
      Q - the quantity type
      Parameters:
      value - the numerical value
      unit - the unit of measurement
      Returns:
      the quantity
    • create

      public static <Q extends Quantity<Q>> Quantity<Q> create(double value, Unit<Q> unit)
      Creates a quantity from a double value and unit.
      Type Parameters:
      Q - the quantity type
      Parameters:
      value - the numerical value
      unit - the unit of measurement
      Returns:
      the quantity
    • create

      public static <Q extends Quantity<Q>> Quantity<Q> create(long value, Unit<Q> unit)
      Creates a quantity from a long value and unit.
      Type Parameters:
      Q - the quantity type
      Parameters:
      value - the numerical value
      unit - the unit of measurement
      Returns:
      the quantity
    • create

      public static <Q extends Quantity<Q>> Quantity<Q> create(int value, Unit<Q> unit)
      Creates a quantity from an int value and unit.
      Type Parameters:
      Q - the quantity type
      Parameters:
      value - the numerical value
      unit - the unit of measurement
      Returns:
      the quantity
    • parse

      public static <Q extends Quantity<Q>> Quantity<Q> parse(String text, Unit<Q> expectedUnit)
      Parses a quantity from a string representation.

      Expected format: "value unit" (e.g., "100 m", "10.5 kg", "50 km/h")

      Type Parameters:
      Q - the quantity type
      Parameters:
      text - the string to parse
      expectedUnit - the expected unit (for validation)
      Returns:
      the parsed quantity
      Throws:
      IllegalArgumentException - if parsing fails
    • parse

      public static Quantity<?> parse(String text)
      Parses a quantity from a string representation without specifying unit type.

      Expected format: "value unit" (e.g., "100 m", "10.5 kg", "50 km/h")

      This overload returns Quantityinvalid input: '<'?> since the unit type is not known at compile time.

      Parameters:
      text - the string to parse
      Returns:
      the parsed quantity with unknown type
      Throws:
      IllegalArgumentException - if parsing fails