From 987fd8406d65505aedecd17e51216eb0ce393fbb Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Wed, 22 May 2019 17:32:40 -0400 Subject: Added new default methods to the Unit interface. --- src/org/unitConverter/unit/NonlinearUnits.java | 28 ++++---------------------- 1 file changed, 4 insertions(+), 24 deletions(-) (limited to 'src/org/unitConverter/unit/NonlinearUnits.java') diff --git a/src/org/unitConverter/unit/NonlinearUnits.java b/src/org/unitConverter/unit/NonlinearUnits.java index e47c28f..eda4a74 100755 --- a/src/org/unitConverter/unit/NonlinearUnits.java +++ b/src/org/unitConverter/unit/NonlinearUnits.java @@ -24,31 +24,11 @@ package org.unitConverter.unit; * @since v0.1.0 */ public final class NonlinearUnits { - public static final Unit CELSIUS = new AbstractUnit(SI.KELVIN) { + public static final Unit CELSIUS = Unit.fromConversionFunctions(SI.KELVIN, tempK -> tempK - 273.15, + tempC -> tempC + 273.15); - @Override - public double convertFromBase(final double value) { - return value - 273.15; - } - - @Override - public double convertToBase(final double value) { - return value + 273.15; - } - }; - - public static final Unit FAHRENHEIT = new AbstractUnit(SI.KELVIN) { - - @Override - public double convertFromBase(final double value) { - return 1.8 * value - 459.67; - } - - @Override - public double convertToBase(final double value) { - return (value + 459.67) / 1.8; - } - }; + public static final Unit FAHRENHEIT = Unit.fromConversionFunctions(SI.KELVIN, tempK -> tempK * 1.8 - 459.67, + tempF -> (tempF + 459.67) / 1.8); // You may NOT get a NonlinearUnits instance. private NonlinearUnits() { -- cgit v1.2.3