public abstract class Converter
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static double |
KILOMETER_IN_METERS |
Constructor and Description |
---|
Converter() |
Modifier and Type | Method and Description |
---|---|
Measurement |
convert(double in,
MeasurementUnit from,
MeasurementUnit to)
Converts a value in given
MeasurementUnit to another unit. |
protected abstract double |
fromBaseTo(double in,
MeasurementUnit unit)
Converts a value from base unit to unit of the given type.
|
protected static boolean |
isLength(MeasurementUnit unit) |
protected static boolean |
isMetric(MeasurementUnit unit) |
protected static boolean |
isSpeed(MeasurementUnit unit) |
static double |
round(double value,
int places)
Round a given value to the number of decimal places.
|
protected abstract double |
toBaseUnit(double in,
MeasurementUnit unit)
Converts a value of given unit to the base unit.
|
protected static final double KILOMETER_IN_METERS
public Measurement convert(double in, MeasurementUnit from, MeasurementUnit to)
MeasurementUnit
to another unit.in
- a value to be converted.from
- a source MeasurementUnit
.to
- a target MeasurementUnit
.Measurement
.protected abstract double toBaseUnit(double in, MeasurementUnit unit)
in
- a value to be converted.unit
- a MeasurementUnit
to be converted to base.protected abstract double fromBaseTo(double in, MeasurementUnit unit)
in
- a value to be converted.unit
- a target MeasurementUnit
.public static double round(double value, int places)
value
- value to round.places
- number of decimal places.protected static boolean isSpeed(MeasurementUnit unit)
protected static boolean isLength(MeasurementUnit unit)
protected static boolean isMetric(MeasurementUnit unit)