Package org.ka2ddo.yaac.osm
Class Weight
java.lang.Object
org.ka2ddo.yaac.osm.Weight
- All Implemented Interfaces:
QuantityUnitMeasure<WeightUnit>
This class defines a compound object containing a weight value and the unit of weight.
- Author:
- Andrew Pavlin, KA2DDO
-
Constructor Summary
ConstructorDescriptionWeight
(float weight) Create a Weight in short tons.Weight
(float weight, WeightUnit unit) Create a Weight of the specified magnitude and units.Create a Weight from a String encoding, which may include a weight unit name. -
Method Summary
Modifier and TypeMethodDescriptionfloat
Get the magnitude of this value in its unit.float
getMagnitude
(WeightUnit otherUnit) Get this length in the specified units.float
Get the magnitude of this value in the default unit for the value class, scaling it if stored in a different unit.getUnit()
Get the unit in which the magnitude is measured.toString()
Returns a string representation of the object.
-
Constructor Details
-
Weight
Create a Weight from a String encoding, which may include a weight unit name.- Parameters:
value
- String value to decode- Throws:
IllegalArgumentException
- if weight cannot be decoded
-
Weight
Create a Weight of the specified magnitude and units.- Parameters:
weight
- magnitude of weightunit
- WeightUnit of the value
-
Weight
public Weight(float weight) Create a Weight in short tons.- Parameters:
weight
- quantity of tons in the weight
-
-
Method Details
-
getMagnitude
public float getMagnitude()Get the magnitude of this value in its unit.- Specified by:
getMagnitude
in interfaceQuantityUnitMeasure<WeightUnit>
- Returns:
- float value
-
getMagnitude
Get this length in the specified units.- Specified by:
getMagnitude
in interfaceQuantityUnitMeasure<WeightUnit>
- Parameters:
otherUnit
-UnitEnum
for scaling the value- Returns:
- float value converted to the specified units
-
getMagnitudeInDefaultUnit
public float getMagnitudeInDefaultUnit()Get the magnitude of this value in the default unit for the value class, scaling it if stored in a different unit.- Specified by:
getMagnitudeInDefaultUnit
in interfaceQuantityUnitMeasure<WeightUnit>
- Returns:
- float value
-
getUnit
Get the unit in which the magnitude is measured.- Specified by:
getUnit
in interfaceQuantityUnitMeasure<WeightUnit>
- Returns:
UnitEnum
of the unit
-
toString
Returns a string representation of the object.
-