Interface Quantity<Q extends Quantity<Q>>
- All Known Subinterfaces:
Acceleration, Action, AmountOfSubstance, Angle, Area, Dimensionless, ElectricCapacitance, ElectricCharge, ElectricConductance, ElectricConductivity, ElectricCurrent, ElectricPermittivity, ElectricPotential, ElectricResistance, Energy, Entropy, Force, Frequency, Inductance, Length, LuminousIntensity, MagneticFlux, MagneticFluxDensity, MagneticPermeability, Mass, MassDensity, Power, Pressure, SpecificHeatCapacity, Temperature, ThermalConductivity, Time, Velocity, Volume, VolumetricFlowRate, WaveNumber
- All Known Implementing Classes:
Money
public interface Quantity<Q extends Quantity<Q>>
A physical quantity combining a numerical value with a unit of measurement.
This interface provides type-safe dimensional analysis using parameterized types. Quantities are immutable - all operations return new instances.
Example Usage:
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Method Summary
Modifier and TypeMethodDescriptionabs()Returns the absolute value of this quantity.Adds another quantity to this one.Casts this quantity to the specified type.intCompares this quantity with another for order.divide(double scalar) Divides this quantity by a scalar value.Divides this quantity by a scalar value.Divides this quantity by another quantity.booleanChecks if this quantity equals another within tolerance.getUnit()Returns the unit of measurement for this quantity.getValue()Returns the numerical value of this quantity in its current unit.default RealReturns the value of this quantity in the specified unit.default booleanisGreaterThan(Quantity<Q> other) Checks if this quantity is strictly greater than another quantity.default booleanisGreaterThanOrEqualTo(Quantity<Q> other) Checks if this quantity is greater than or equal to another quantity.default booleanisLessThan(Quantity<Q> other) Checks if this quantity is strictly less than another quantity.default booleanisLessThanOrEqualTo(Quantity<Q> other) Checks if this quantity is less than or equal to another quantity.default booleanisZero()Checks if this quantity is zero within tolerance.multiply(double scalar) Multiplies this quantity by a scalar value.Multiplies this quantity by a scalar value.Multiplies this quantity by another quantity.negate()Returns the negation of this quantity.Quantity<?> pow(int exponent) Returns this quantity raised to the specified exponent.Quantity<?> sqrt()Returns the square root of this quantity.Subtracts another quantity from this one.Converts this quantity to the specified unit.
-
Method Details
-
getValue
Real getValue()Returns the numerical value of this quantity in its current unit.- Returns:
- the quantity value
-
getUnit
-
to
Converts this quantity to the specified unit.Returns a new quantity with the same physical magnitude but expressed in the target unit.
- Parameters:
targetUnit- the unit to convert to- Returns:
- a new quantity in the target unit
- Throws:
IllegalArgumentException- if units are incompatible
-
getValue
-
add
-
subtract
-
multiply
-
multiply
-
multiply
Multiplies this quantity by another quantity.The result's unit is the product of the two units. For example, multiplying Length by Length gives Area.
- Type Parameters:
R- the other quantity type- Parameters:
other- the quantity to multiply by- Returns:
- a new quantity representing the product
-
divide
-
divide
-
divide
Divides this quantity by another quantity.The result's unit is the quotient of the two units. For example, dividing Length by Time gives Velocity.
- Type Parameters:
R- the other quantity type- Parameters:
other- the quantity to divide by- Returns:
- a new quantity representing the quotient
-
abs
-
negate
-
asType
Casts this quantity to the specified type.This is an unchecked cast that allows reinterpreting the quantity type. Use with caution - the caller must ensure dimensional consistency.
- Type Parameters:
R- the target quantity type- Parameters:
type- the target quantity class- Returns:
- this quantity cast to the specified type
-
isZero
default boolean isZero()Checks if this quantity is zero within tolerance.- Returns:
- true if the value is approximately zero
-
compareTo
-
isGreaterThan
-
isLessThan
-
isGreaterThanOrEqualTo
-
isLessThanOrEqualTo
-
equals
-
pow
Returns this quantity raised to the specified exponent.- Parameters:
exponent- the exponent- Returns:
- this quantity raised to the exponent
-
sqrt
Quantity<?> sqrt()Returns the square root of this quantity.- Returns:
- the square root of this quantity
-