Package com.irurueta.units
Class TemperatureConverter
java.lang.Object
com.irurueta.units.TemperatureConverter
Does temperature conversions to different units.
To prevent loss of accuracy, conversion should only be done as a final step
before displaying temperature measurements.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleAbsolute zero temperature expressed in Kelvins (K).private static final doubleDenominator of the Fahrenheit to Celsius scale factor.private static final doubleOffset of the Fahrenheit scale with respect to the Celsius scale.private static final doubleNumerator of the Fahrenheit to Celsius scale factor. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublecelsiusToFahrenheit(double celsius) Converts provided Celsius value to Fahrenheit.static doublecelsiusToKelvin(double celsius) Converts provided Celsius value to Kelvin.static doubleconvert(double input, TemperatureUnit inputUnit, TemperatureUnit outputUnit) Converts a temperature value from input unit to provided output unit.static voidconvert(Temperature input, Temperature output) Converts a temperature to provided output temperature unit.static voidconvert(Temperature temperature, TemperatureUnit outputUnit) Converts and updates a temperature to requested output unit.static voidconvert(Temperature input, TemperatureUnit outputUnit, Temperature result) Converts a temperature to requested output unit.static Numberconvert(Number input, TemperatureUnit inputUnit, TemperatureUnit outputUnit) Converts a temperature value from input unit to provided output unit.static TemperatureconvertAndReturnNew(Temperature input, TemperatureUnit outputUnit) Converts a temperature to requested output unit.static doublefahrenheitToCelsius(double fahrenheit) Converts provided Fahrenheit value to Celsius.static doublekelvinToCelsius(double kelvin) Converts provided Kelvin value to Celsius.
-
Field Details
-
ABSOLUTE_ZERO
public static final double ABSOLUTE_ZEROAbsolute zero temperature expressed in Kelvins (K).- See Also:
-
FAHRENHEIT_OFFSET
private static final double FAHRENHEIT_OFFSETOffset of the Fahrenheit scale with respect to the Celsius scale.- See Also:
-
FAHRENHEIT_RANGE
private static final double FAHRENHEIT_RANGENumerator of the Fahrenheit to Celsius scale factor.- See Also:
-
CELSIUS_RANGE
private static final double CELSIUS_RANGEDenominator of the Fahrenheit to Celsius scale factor.- See Also:
-
-
Constructor Details
-
TemperatureConverter
private TemperatureConverter()Constructor. Prevents instantiation of helper class.
-
-
Method Details
-
convert
Converts a temperature to provided output temperature unit.- Parameters:
input- input temperature to be converted.output- output temperature where result will be stored and containing output unit.
-
convertAndReturnNew
Converts a temperature to requested output unit.- Parameters:
input- input temperature to be converted.outputUnit- requested output unit.- Returns:
- converted temperature.
-
convert
Converts and updates a temperature to requested output unit.- Parameters:
temperature- input temperature to be converted and updated.outputUnit- requested output unit.
-
convert
Converts a temperature to requested output unit.- Parameters:
input- input temperature to be converted.outputUnit- requested output unit.result- temperature unit where result will be stored.
-
convert
Converts a temperature value from input unit to provided output unit.- Parameters:
input- temperature value.inputUnit- input temperature unit.outputUnit- output temperature unit.- Returns:
- converted temperature value.
-
convert
Converts a temperature value from input unit to provided output unit.- Parameters:
input- temperature value.inputUnit- input temperature unit.outputUnit- output temperature unit.- Returns:
- converted temperature value.
-
kelvinToCelsius
public static double kelvinToCelsius(double kelvin) Converts provided Kelvin value to Celsius.- Parameters:
kelvin- kelvin value.- Returns:
- some amount of temperature converted to Celsius.
-
celsiusToKelvin
public static double celsiusToKelvin(double celsius) Converts provided Celsius value to Kelvin.- Parameters:
celsius- celsius value.- Returns:
- some amount of temperature converted to Kelvin.
-
celsiusToFahrenheit
public static double celsiusToFahrenheit(double celsius) Converts provided Celsius value to Fahrenheit.- Parameters:
celsius- celsius value.- Returns:
- some amount of temperature converted to Fahrenheit.
-
fahrenheitToCelsius
public static double fahrenheitToCelsius(double fahrenheit) Converts provided Fahrenheit value to Celsius.- Parameters:
fahrenheit- fahrenheit value.- Returns:
- some amount of temperature converted to Celsius.
-