Package tech.units.indriya.unit
Class AlternateUnit<Q extends Quantity<Q>>
- java.lang.Object
-
- tech.units.indriya.AbstractUnit<Q>
-
- tech.units.indriya.unit.AlternateUnit<Q>
-
- All Implemented Interfaces:
Serializable,Comparable<Unit<Q>>,Unit<Q>,tech.uom.lib.common.function.Nameable,tech.uom.lib.common.function.PrefixOperator<Q>,tech.uom.lib.common.function.SymbolSupplier
public final class AlternateUnit<Q extends Quantity<Q>> extends AbstractUnit<Q>
This class represents units used in expressions to distinguish between quantities of a different nature but of the same dimensions.
Examples of alternate units:
Unit<Angle> RADIAN = AlternateUnit.of(ONE, "rad").asType(Angle.class);
Unit<Force> NEWTON = AlternateUnit.of(METRE.multiply(KILOGRAM).divide(SECOND.pow(2)), "N").asType(Force.class);
Unit<Pressure> PASCAL = AlternateUnit.of(NEWTON.divide(METRE.pow(2), "Pa").asType(Pressure.class);
- Since:
- 1.0
- Version:
- 2.1, October 3, 2024
- Author:
- Jean-Marie Dautelle, Werner Keil
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class tech.units.indriya.AbstractUnit
AbstractUnit.Equalizer
-
-
Field Summary
-
Fields inherited from class tech.units.indriya.AbstractUnit
ONE, scale, SYMBOL_TO_UNIT
-
-
Constructor Summary
Constructors Constructor Description AlternateUnit(Unit<?> parentUnit, String symbol)Creates an alternate unit for the specified system unit identified by the specified name and symbol.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)Map<? extends Unit<?>,Integer>getBaseUnits()DimensiongetDimension()Unit<?>getParentUnit()Returns the parent unit of this alternate unit, always a system unit and never an alternate unit.UnitConvertergetSystemConverter()Returns the converter from this unit to its unscaledSystem Unitunit.inthashCode()static <Q extends Quantity<Q>>
AlternateUnit<Q>of(Unit<?> parent, String symbol)Creates an alternate unit for the specified system unit identified by the specified name and symbol.static <Q extends Quantity<Q>>
AlternateUnit<Q>of(Unit<?> parent, String symbol, String name)Creates an alternate unit for the specified system unit identified by the specified name and symbol.Unit<Q>toSystemUnit()Returns the unscaledSIunit from which this unit is derived.-
Methods inherited from class tech.units.indriya.AbstractUnit
alternate, annotate, asType, compareTo, divide, divide, divide, getActualType, getConverterTo, getConverterTo, getConverterToAny, getConverterToAny, getName, getSymbol, getSystemUnit, internalGetConverterTo, inverse, isCompatible, isEquivalentTo, isSystemUnit, multiply, multiply, multiply, parse, pow, prefix, root, setName, setSymbol, shift, shift, toString, transform
-
-
-
-
Constructor Detail
-
AlternateUnit
public AlternateUnit(Unit<?> parentUnit, String symbol)
Creates an alternate unit for the specified system unit identified by the specified name and symbol.- Parameters:
parentUnit- the system unit from which this alternate unit is derived.symbol- the symbol for this alternate unit.- Throws:
IllegalArgumentException- if the specified parent unit is not ansystem unit
-
-
Method Detail
-
getParentUnit
public Unit<?> getParentUnit()
Returns the parent unit of this alternate unit, always a system unit and never an alternate unit.- Returns:
- the parent unit.
-
getDimension
public Dimension getDimension()
- Specified by:
getDimensionin interfaceUnit<Q extends Quantity<Q>>- Specified by:
getDimensionin classAbstractUnit<Q extends Quantity<Q>>
-
getSystemConverter
public UnitConverter getSystemConverter()
Description copied from class:AbstractUnitReturns the converter from this unit to its unscaledSystem Unitunit.- Specified by:
getSystemConverterin classAbstractUnit<Q extends Quantity<Q>>- Returns:
getConverterTo(this.toSystemUnit())- See Also:
AbstractUnit.toSystemUnit()
-
toSystemUnit
public Unit<Q> toSystemUnit()
Description copied from class:AbstractUnitReturns the unscaledSIunit from which this unit is derived. The SI unit can be be used to identify a quantity given the unit. For example:static boolean isAngularVelocity(AbstractUnit> unit) { return unit.toSystemUnit().equals(RADIAN.divide(SECOND)); } assert(REVOLUTION.divide(MINUTE).isAngularVelocity()); // Returns true.- Specified by:
toSystemUnitin classAbstractUnit<Q extends Quantity<Q>>- Returns:
- the unscaled metric unit from which this unit is derived.
-
getBaseUnits
public Map<? extends Unit<?>,Integer> getBaseUnits()
- Specified by:
getBaseUnitsin interfaceUnit<Q extends Quantity<Q>>- Specified by:
getBaseUnitsin classAbstractUnit<Q extends Quantity<Q>>
-
equals
public boolean equals(Object obj)
- Specified by:
equalsin classAbstractUnit<Q extends Quantity<Q>>
-
of
public static <Q extends Quantity<Q>> AlternateUnit<Q> of(Unit<?> parent, String symbol)
Creates an alternate unit for the specified system unit identified by the specified name and symbol.- Parameters:
parent- the system unit from which this alternate unit is derived.symbol- the symbol for this alternate unit.- Throws:
IllegalArgumentException- if the specified parent unit is not an unscaled standardsystem unit.MeasurementException- if the specified symbol is not valid or is already associated to a different unit.
-
of
public static <Q extends Quantity<Q>> AlternateUnit<Q> of(Unit<?> parent, String symbol, String name)
Creates an alternate unit for the specified system unit identified by the specified name and symbol.- Parameters:
parent- the system unit from which this alternate unit is derived.symbol- the symbol for this alternate unit.name- the name for this alternate unit.- Throws:
IllegalArgumentException- if the specified parent unit is not an unscaled standardsystem unit.MeasurementException- if the specified symbol is not valid or is already associated to a different unit.- Since:
- 2.0
-
-