Summary Table

Categories Total Count
PII 0
URL 0
DNS 0
EKL 0
IP 0
PORT 0
VsID 0
CF 0
AI 0
VPD 0
PL 0
Other 0

File Content

package gov.va.med.pbm.ampl.utility;

import java.util.Locale;

import gov.va.med.pbm.ampl.constant.AmplConstants;

/**
* The UnitConversion utility class provides calculations for common conversion between Imperial and Metric standards.
*
* @author Ian Meinert
*
*/
public final class UnitConversion {

private static final double CM_IN_FACTOR = 2.54;
private static final double M_IN_FACTOR = 0.0254;
private static final double KG_LB_FACTOR = 2.2;
private static final int TEMP_ADJ_FACTOR = 40;
private static final double TEMP_FACTOR = 1.8;

/**
* The default constructor.
*/
private UnitConversion() {
// Not implemented for utility classes.
}

/**
* This method will convert inches to centimeters.
*
* @param inches the number of inches
* @return centimeters
*/
public static double convertInchesToCentimeters(double inches) {
double centimeters = inches * CM_IN_FACTOR;
return centimeters;
}

/**
* This method will convert inches to meters.
*
* @param inches the number of inches
* @return meters
*/
public static double convertInchesToMeters(double inches) {
double meters = inches * M_IN_FACTOR;

return meters;
}

/**
* This method will convert inches to centimeters.
*
* @param centimeters the number of centimeters
* @return inches
*/
public static double convertCentiMetersToInches(double centimeters) {
double inches = centimeters / CM_IN_FACTOR;
return inches;
}

/**
* This method will convert pounds to kilograms.
*
* @param pounds the weight in pounds
* @return kilograms
*/
public static double convertPoundToKilogram(double pounds) {
double kilograms = pounds / KG_LB_FACTOR;
return kilograms;
}

/**
* This method will convert kilograms to pounds.
*
* @param kilograms the weight in kilograms
* @return pounds
*/
public static double convertKilogramToPound(double kilograms) {
double pounds = kilograms * KG_LB_FACTOR;
return pounds;
}

/**
* This method will convert celsius to fahrenheit.
*
* @param celsius the temperature in celsius
* @return fahrenheit
*/
public static double convertCelsiusToFahrenheit(double celsius) {
double fahrenheit = (celsius + TEMP_ADJ_FACTOR) * TEMP_FACTOR - TEMP_ADJ_FACTOR;
return fahrenheit;
}

/**
* This method will convert fahrenheit to celsius.
*
* @param fahrenheit the temperature in fahrenheit
* @return celsius
*/
public static double convertFahrenheitToCelsius(double fahrenheit) {
double celsius = (fahrenheit + TEMP_ADJ_FACTOR) / TEMP_FACTOR - TEMP_ADJ_FACTOR;
return celsius;
}

/**
* This method converts a measurement from imperial to metric.
*
* @param measurementName the measurement name
* @param value the value to convert
* @return a metric representation of an imperial value
*/
public static double convertMeasurement(String measurementName, double value) {
double retVal = 0.0;

switch (measurementName.toUpperCase(Locale.ENGLISH)) {
case "TEMPERATURE":
retVal = UnitConversion.convertFahrenheitToCelsius(value);
break;
case "HEIGHT":
retVal = UnitConversion.convertInchesToCentimeters(value);
break;
case "WEIGHT":
retVal = UnitConversion.convertPoundToKilogram(value);
break;
default:
break;
}

return (double) Math.round(retVal * AmplConstants.MATH_ROUND_ONE_HUNDRED) / AmplConstants.MATH_ROUND_ONE_HUNDRED;
}
}