// Convert our Temperature
if (source.getScale() == CELSIUS) { // Celsius to Fahrenheit
// Easter egg for Absolute Zero.
if (source.getTemperature() < Temperature.ABSOLUTE_ZERO_C) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Below Absolute Zero!"));
} else if (source.getTemperature() == Temperature.ABSOLUTE_ZERO_C) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Absolute Zero!"));
}
return new Temperature((source.getTemperature() * 9 / 5) + 32, FAHRENHEIT);
} else if (source.getScale() == FAHRENHEIT) { // Fahrenheit to Celsius
// Easter egg for Absolute Zero.
if (source.getTemperature() < Temperature.ABSOLUTE_ZERO_F) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Below Absolute Zero!"));
} else if (source.getTemperature() == Temperature.ABSOLUTE_ZERO_F) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Absolute Zero!"));
}
return new Temperature((source.getTemperature() - 32) * 5 / 9, CELSIUS);
} else { // Should never get here!
throw new IllegalStateException("This is embarrassing - this error should NOT occur!");
}