java.lang.Object
de.turnertech.measures.Unit
A Unit is a single instance of a Measurement, such as a Metre or a Degree Celsius.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Unit
cmstatic final Unit
degstatic final Unit
Celstatic final Unit
degFstatic final Unit
ft_istatic final Unit
gstatic final Unit
in_istatic final Unit
Kstatic final Unit
kmstatic final Unit
mstatic final Unit
mi_istatic final Unit
'static final Unit
nmi_istatic final Unit
lb_avstatic final Unit
radstatic final Unit
sstatic final Unit
"static final Unit
yd_i -
Constructor Summary
ConstructorDescriptionUnit()
Constructs a "Base Unit", where its own base unit is iteself, and conversions to and from its base unit will alway return the same value as input (DoubleUnaryOperator.identity()
).Constructs a "Base Unit", where its own base unit is iteself, and conversions to and from its base unit will alway return the same value as input (DoubleUnaryOperator.identity()
).Unit
(String symbol, Unit baseUnit, DoubleUnaryOperator toBaseUnitFunction, DoubleUnaryOperator fromBaseUnitFunction) Constructs a Unit with the supplied base unit and conversion functions too and from said Unit. -
Method Summary
Modifier and TypeMethodDescriptionconvertFromBaseUnit
(double quantity) Converts a supplied quantity of this Units base unit to a quantity of itself.convertToBaseUnit
(double quantity) Converts a supplied quantity of this Unit to a quantity of its base unit.createMeasure
(double quantity) Helper function for creating measures with a Unit.Gets the common base unit for the family of units to which this Unit belongs.toString()
-
Field Details
-
KELVIN
K -
DEGREES_CELSIUS
Cel -
DEGREES_FAHRENHEIT
degF -
METRE
m -
CENTIMETRE
cm -
INCH
in_i -
FOOT
ft_i -
YARD
yd_i -
MILE
mi_i -
KILOMETRE
km -
NAUTICAL_MILE
nmi_i -
SECOND
s -
GRAM
g -
POUND
lb_av -
DEGREE
deg -
MINUTE_ANGLE
' -
SECOND_ANGLE
" -
RADIAN
rad
-
-
Constructor Details
-
Unit
public Unit()Constructs a "Base Unit", where its own base unit is iteself, and conversions to and from its base unit will alway return the same value as input (DoubleUnaryOperator.identity()
). -
Unit
Constructs a "Base Unit", where its own base unit is iteself, and conversions to and from its base unit will alway return the same value as input (DoubleUnaryOperator.identity()
).- Parameters:
symbol
- may not be null.
-
Unit
public Unit(String symbol, Unit baseUnit, DoubleUnaryOperator toBaseUnitFunction, DoubleUnaryOperator fromBaseUnitFunction) Constructs a Unit with the supplied base unit and conversion functions too and from said Unit.- Parameters:
baseUnit
- the unit to which the conversion functions will convert. Supplying null will make the base unit the unit itself (this).symbol
- may not be null.toBaseUnitFunction
- may not be null.fromBaseUnitFunction
- may not be null.
-
-
Method Details
-
createMeasure
Helper function for creating measures with a Unit.- Parameters:
quantity
- the quantity of this unit which should be in the Measure.- Returns:
- a new Measure instance.
-
getBaseUnit
Gets the common base unit for the family of units to which this Unit belongs. For example, Metres are the base Unit for all distance Units. Even Feet, Inches and Nautical Miles will share the same base unit of a Metre.- Returns:
- the base unit for this Unit.
-
convertToBaseUnit
Converts a supplied quantity of this Unit to a quantity of its base unit. For example supplying a quantity of 1 to this function on an instance ofKILOMETRE
will return 1000 (metres).- Parameters:
quantity
- of this Unit to convert to the base unit.- Returns:
- the quantity of the Base Unit which the supplied quantity represents.
-
convertFromBaseUnit
Converts a supplied quantity of this Units base unit to a quantity of itself.- Parameters:
quantity
- of this Unit base unit to convert to this unit.- Returns:
- a measure with this Unit.
-
toString
-