diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/UnitXCFactory.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/UnitXCFactory.java index 8b7479d..9b8299f 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/UnitXCFactory.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/UnitXCFactory.java @@ -30,14 +30,20 @@ import java.util.List; import net.forwardfire.unitxc.config.UnitXCConfig; import net.forwardfire.unitxc.config.UnitXCConfigManager; import net.forwardfire.unitxc.config.UnitXCConfigModule; -import net.forwardfire.unitxc.module.UnitXCElectricCurrentModule; -import net.forwardfire.unitxc.module.UnitXCTemperatureModule; +import net.forwardfire.unitxc.module.UnitXCModuleAmountOfSubstance; +import net.forwardfire.unitxc.module.UnitXCModuleElectricCurrent; +import net.forwardfire.unitxc.module.UnitXCModuleLength; +import net.forwardfire.unitxc.module.UnitXCModuleLuminousIntensity; +import net.forwardfire.unitxc.module.UnitXCModuleTemperature; public final class UnitXCFactory { private static final List DEFAULT_CONFIG_MODULES = Collections.unmodifiableList(Arrays.asList( - new UnitXCTemperatureModule(), - new UnitXCElectricCurrentModule() + new UnitXCModuleTemperature(), + new UnitXCModuleElectricCurrent(), + new UnitXCModuleLuminousIntensity(), + new UnitXCModuleAmountOfSubstance(), + new UnitXCModuleLength() )); diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCTypeBuilder.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCTypeBuilder.java index fb2db08..7ba74ee 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCTypeBuilder.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCTypeBuilder.java @@ -78,7 +78,7 @@ public abstract class AbstractUnitXCTypeBuilder extends AbstractUnitXCBuild } public B addToBaseConverterStep(UnitXConverterStep unitTypeConverter) { - return make((v) -> v.addFromBaseConverterStep(unitTypeConverter)); + return make((v) -> v.addToBaseConverterStep(unitTypeConverter)); } public B addToBaseConverterSteps(List unitTypeConverters) { diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXConverterStepBuilder.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXConverterStepBuilder.java index 14192c9..e90b41e 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXConverterStepBuilder.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXConverterStepBuilder.java @@ -30,6 +30,7 @@ import java.util.function.BiConsumer; import org.apache.commons.lang3.math.Fraction; import net.forwardfire.unitxc.converter.step.UnitXCTypeDevideConverterStep; +import net.forwardfire.unitxc.converter.step.UnitXCTypeExponentConverterStep; import net.forwardfire.unitxc.converter.step.UnitXCTypeMultiplyConverterStep; import net.forwardfire.unitxc.converter.step.UnitXCTypeMultiplyFractionConverterStep; import net.forwardfire.unitxc.converter.step.UnitXCTypeOffsetConverterStep; @@ -46,22 +47,20 @@ public class UnitXConverterStepBuilder

extends AbstractUnitXCBuilder add(double offset) { + public UnitXConverterStepBuilder

offsetUp(double offset) { return offset(offset,true); } - public UnitXConverterStepBuilder

sub(double offset) { + public UnitXConverterStepBuilder

offsetDown(double offset) { return offset(offset,false); } - public UnitXConverterStepBuilder

substract(double offset) { - return offset(offset,false); - } - public UnitXConverterStepBuilder

offset(double offset,boolean offsetPositive) { + private UnitXConverterStepBuilder

offset(double offset,boolean offsetPositive) { return make(v -> v.add(new UnitXCTypeOffsetConverterStep(offset,offsetPositive))); } - public UnitXConverterStepBuilder

multiplyFraction(Fraction fraction) { + + public UnitXConverterStepBuilder

multiply(Fraction fraction) { return make(v -> v.add(new UnitXCTypeMultiplyFractionConverterStep(fraction))); } - public UnitXConverterStepBuilder

multiplyFraction(int numerator,int denominator) { + public UnitXConverterStepBuilder

multiply(int numerator,int denominator) { return make(v -> v.add(new UnitXCTypeMultiplyFractionConverterStep(numerator,denominator))); } public UnitXConverterStepBuilder

multiply(double factor) { @@ -70,4 +69,14 @@ public class UnitXConverterStepBuilder

extends AbstractUnitXCBuilder divide(double factor) { return make(v -> v.add(new UnitXCTypeDevideConverterStep(factor))); } + + private UnitXConverterStepBuilder

exponent(int exponent,boolean rev) { + return make(v -> v.add(new UnitXCTypeExponentConverterStep(exponent,rev))); + } + public UnitXConverterStepBuilder

exponentUp(UnitXCTypeSIPrefix exponent) { + return exponent(exponent.getExponent(), false); + } + public UnitXConverterStepBuilder

exponentDown(UnitXCTypeSIPrefix exponent) { + return exponent(exponent.getExponent(), true); + } } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleAmountOfSubstance.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleAmountOfSubstance.java new file mode 100644 index 0000000..e49a168 --- /dev/null +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleAmountOfSubstance.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix; + +public class UnitXCModuleAmountOfSubstance implements UnitXCConfigModule { + + public static final String GROUP_ID = "substance"; + public static final String GROUP_DESCRIPTION = "The mole is the amount of substance of a system which contains as many elementary entities as there are atoms in 0.012 kilogram of carbon 12."; + public static final String TYPE_MOLE_ID = "mol"; + public static final String TYPE_MOLE_NAME = "mole"; + public static final String TYPE_MOLE_FLAG = (GROUP_ID+"_"+TYPE_MOLE_NAME).toUpperCase(); + + public static final String TYPE_POUND_MOLE_ID = "lbmol"; + public static final String TYPE_POUND_MOLE_NAME = "pound-mole"; + public static final String TYPE_POUND_MOLE_FLAG = (GROUP_ID+"_"+TYPE_POUND_MOLE_NAME).toUpperCase(); + private static final double TYPE_POUND_MOLE_FACTOR = 453.59237; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitTypeGroup() + .setId( GROUP_ID) + .setName( TYPE_MOLE_NAME) + .setDescription ( GROUP_DESCRIPTION) + .setBaseTypeId( TYPE_MOLE_ID) + .createSIUnitTypes() + .setId( TYPE_MOLE_ID) + .setName( TYPE_MOLE_NAME) + .addTypeFlag( TYPE_MOLE_FLAG) + .addCommonPrefix(UnitXCTypeSIPrefix.MILLI) + .addCommonPrefix(UnitXCTypeSIPrefix.MICRO) + .addCommonPrefix(UnitXCTypeSIPrefix.NANO) + .addCommonPrefix(UnitXCTypeSIPrefix.PICO) + .addCommonPrefix(UnitXCTypeSIPrefix.FEMTO) + .build() + .createUnitType() + .setId( TYPE_POUND_MOLE_ID) + .setName( TYPE_POUND_MOLE_NAME) + .createToBaseConverterSteps().multiply(TYPE_POUND_MOLE_FACTOR).build() + .createFromBaseConverterSteps().divide(TYPE_POUND_MOLE_FACTOR).build() + .build() + .build() + ; + } +} diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCElectricCurrentModule.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleElectricCurrent.java similarity index 97% rename from ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCElectricCurrentModule.java rename to ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleElectricCurrent.java index 02d57ce..58bb2a0 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCElectricCurrentModule.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleElectricCurrent.java @@ -27,7 +27,7 @@ import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix; -public class UnitXCElectricCurrentModule implements UnitXCConfigModule { +public class UnitXCModuleElectricCurrent implements UnitXCConfigModule { public static final String GROUP_ID = "current"; public static final String GROUP_DESCRIPTION = "The ampere is a measure of the amount of electric charge passing a point in an electric circuit per unit time, with 6.241×1018 electrons (or one coulomb) per second constituting one ampere."; diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleLength.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleLength.java new file mode 100644 index 0000000..f7515f5 --- /dev/null +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleLength.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; +import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix; + +public class UnitXCModuleLength implements UnitXCConfigModule { + + public static final String GROUP_ID = "length"; + public static final String GROUP_DESCRIPTION = "The metre is the length of the path travelled by light in vacuum during a time interval of 1/299792458 of a second."; + public static final String TYPE_METER_ID = "m"; + public static final String TYPE_METER_NAME = "meter"; + public static final String TYPE_METER_FLAG = (GROUP_ID+"_"+TYPE_METER_NAME).toUpperCase(); + //public static final String TYPE_METER_ALIAS = "metre"; + + public static final String TYPE_INCH_ID = "in"; + public static final String TYPE_INCH_NAME = "inch"; + public static final String TYPE_INCH_FLAG = (GROUP_ID+"_"+TYPE_INCH_NAME).toUpperCase(); + private static final double TYPE_INCH_FACTOR = 25.4; + + public static final String TYPE_LINK_ID = "li"; + public static final String TYPE_LINK_NAME = "link"; + public static final String TYPE_LINK_FLAG = (GROUP_ID+"_"+TYPE_LINK_NAME).toUpperCase(); + private static final double TYPE_LINK_FACTOR = 201.1; + + public static final String TYPE_FOOT_ID = "ft"; + public static final String TYPE_FOOT_NAME = "foot"; + public static final String TYPE_FOOT_FLAG = (GROUP_ID+"_"+TYPE_FOOT_NAME).toUpperCase(); + private static final double TYPE_FOOT_FACTOR = 304.8; + + public static final String TYPE_YARD_ID = "yd"; + public static final String TYPE_YARD_NAME = "yard"; + public static final String TYPE_YARD_FLAG = (GROUP_ID+"_"+TYPE_YARD_NAME).toUpperCase(); + private static final double TYPE_YARD_FACTOR = 0.9144; + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitTypeGroup() + .setId( GROUP_ID) + .setName( TYPE_METER_NAME) + .setDescription ( GROUP_DESCRIPTION) + .setBaseTypeId( TYPE_METER_ID) + .createSIUnitTypes() + .setId( TYPE_METER_ID) + .setName( TYPE_METER_NAME) + .addTypeFlag( TYPE_METER_FLAG) + .build() + .createSIUnitTypes() + .setId( TYPE_INCH_ID) + .setName( TYPE_INCH_NAME) + .addTypeFlag( TYPE_INCH_FLAG) + .createToBaseConverterSteps().multiply(TYPE_INCH_FACTOR).exponentDown(UnitXCTypeSIPrefix.MILLI).build() + .createFromBaseConverterSteps().exponentUp(UnitXCTypeSIPrefix.MILLI).divide(TYPE_INCH_FACTOR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_LINK_ID) + .setName( TYPE_LINK_NAME) + .addTypeFlag( TYPE_LINK_FLAG) + .createToBaseConverterSteps().multiply(TYPE_LINK_FACTOR).exponentDown(UnitXCTypeSIPrefix.MILLI).build() + .createFromBaseConverterSteps().exponentUp(UnitXCTypeSIPrefix.MILLI).divide(TYPE_LINK_FACTOR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_FOOT_ID) + .setName( TYPE_FOOT_NAME) + .addTypeFlag( TYPE_FOOT_FLAG) + .createToBaseConverterSteps().multiply(TYPE_FOOT_FACTOR).exponentDown(UnitXCTypeSIPrefix.MILLI).build() + .createFromBaseConverterSteps().exponentUp(UnitXCTypeSIPrefix.MILLI).divide(TYPE_FOOT_FACTOR).build() + .build() + .createSIUnitTypes() + .setId( TYPE_YARD_ID) + .setName( TYPE_YARD_NAME) + .addTypeFlag( TYPE_YARD_FLAG) + .createToBaseConverterSteps().multiply(TYPE_YARD_FACTOR).build() + .createFromBaseConverterSteps().divide(TYPE_YARD_FACTOR).build() + .build() + .build() + ; + + +// um.addUnitType(createType(UNIT_GROUP_LENGTH,"in", -3, 25.4 , "inch", OPT_TYPE_IMPERIAL)); +// um.addUnitType(createType(UNIT_GROUP_LENGTH,"li", -3, 201.1 , "link", OPT_TYPE_IMPERIAL_EXTRA)); +// um.addUnitType(createType(UNIT_GROUP_LENGTH,"ft", -3, 304.8 , "foot", OPT_TYPE_IMPERIAL)); +// um.addUnitType(createType(UNIT_GROUP_LENGTH,"yd", 0, 0.9144 , "yard", OPT_TYPE_IMPERIAL)); +// um.addUnitType(createType(UNIT_GROUP_LENGTH,"rd", 0, 5.029 , "rod", OPT_TYPE_IMPERIAL_EXTRA)); +// um.addUnitType(createType(UNIT_GROUP_LENGTH,"ch", 0, 20.117 , "chain", OPT_TYPE_IMPERIAL_EXTRA)); +// um.addUnitType(createType(UNIT_GROUP_LENGTH,"fur", 0, 201.17 , "furlong", OPT_TYPE_IMPERIAL_EXTRA)); +// um.addUnitType(createType(UNIT_GROUP_LENGTH,"mi", 0, 1609.3 , "mile", OPT_TYPE_IMPERIAL)); + } +} diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleLuminousIntensity.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleLuminousIntensity.java new file mode 100644 index 0000000..c786b40 --- /dev/null +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleLuminousIntensity.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013-2015, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.forwardfire.unitxc.module; + +import net.forwardfire.unitxc.config.UnitXCConfigModule; +import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; + +public class UnitXCModuleLuminousIntensity implements UnitXCConfigModule { + + public static final String GROUP_ID = "light"; + public static final String GROUP_DESCRIPTION = "The candela is the luminous intensity, in a given direction, of a source that emits monochromatic radiation of frequency 540×1012 hertz and that has a radiant intensity in that direction of 1/683 watt per steradian."; + public static final String TYPE_CANDELA_ID = "cd"; + public static final String TYPE_CANDELA_NAME = "candela"; + public static final String TYPE_CANDELA_FLAG = (GROUP_ID+"_"+TYPE_CANDELA_NAME).toUpperCase(); + + @Override + public void configModule(UnitXCConfigBuilder builder) { + builder.createUnitTypeGroup() + .setId( GROUP_ID) + .setName( TYPE_CANDELA_NAME) + .setDescription ( GROUP_DESCRIPTION) + .setBaseTypeId( TYPE_CANDELA_ID) + .createSIUnitTypes() + .setId( TYPE_CANDELA_ID) + .setName( TYPE_CANDELA_NAME) + .addTypeFlag( TYPE_CANDELA_FLAG) + .build() + .build() + ; + } +} diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCTemperatureModule.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleTemperature.java similarity index 84% rename from ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCTemperatureModule.java rename to ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleTemperature.java index 4361445..953913f 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCTemperatureModule.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleTemperature.java @@ -28,7 +28,7 @@ import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; import org.apache.commons.lang3.math.Fraction; -public class UnitXCTemperatureModule implements UnitXCConfigModule { +public class UnitXCModuleTemperature implements UnitXCConfigModule { public static final String GROUP_ID = "temperature"; public static final String GROUP_DESCRIPTION = "The kelvin, unit of thermodynamic temperature, is the fraction 1/273.16 of the thermodynamic temperature of the triple point of water."; @@ -74,42 +74,42 @@ public class UnitXCTemperatureModule implements UnitXCConfigModule { .setId( TYPE_CELSIUS_ID) .setName( TYPE_CELSIUS_NAME) .addTypeFlag( TYPE_CELSIUS_FLAG) - .createToBaseConverterSteps().add(TYPE_CELSIUS_OFFSET).build() - .createFromBaseConverterSteps().sub(TYPE_CELSIUS_OFFSET).build() + .createToBaseConverterSteps().offsetUp(TYPE_CELSIUS_OFFSET).build() + .createFromBaseConverterSteps().offsetDown(TYPE_CELSIUS_OFFSET).build() .build() .createSIUnitTypes() .setId( TYPE_FAHRENHEIT_ID) .setName( TYPE_FAHRENHEIT_NAME) .addTypeFlag( TYPE_FAHRENHEIT_FLAG) .createToBaseConverterSteps() - .add(TYPE_FAHRENHEIT_OFFSET) - .multiplyFraction(TYPE_FAHRENHEIT_FRACTION) + .offsetUp(TYPE_FAHRENHEIT_OFFSET) + .multiply(TYPE_FAHRENHEIT_FRACTION) .build() .createFromBaseConverterSteps() - .multiplyFraction(TYPE_FAHRENHEIT_FRACTION.invert()) - .substract(TYPE_FAHRENHEIT_OFFSET) + .multiply(TYPE_FAHRENHEIT_FRACTION.invert()) + .offsetDown(TYPE_FAHRENHEIT_OFFSET) .build() .build() .createSIUnitTypes() .setId( TYPE_RANKINE_ID) .setName( TYPE_RANKINE_NAME) .addTypeFlag( TYPE_RANKINE_FLAG) - .createToBaseConverterSteps().multiplyFraction(TYPE_FAHRENHEIT_FRACTION).build() - .createFromBaseConverterSteps().multiplyFraction(TYPE_FAHRENHEIT_FRACTION.invert()).build() + .createToBaseConverterSteps().multiply(TYPE_FAHRENHEIT_FRACTION).build() + .createFromBaseConverterSteps().multiply(TYPE_FAHRENHEIT_FRACTION.invert()).build() .build() .createSIUnitTypes() .setId( TYPE_ROMER_ID) .setName( TYPE_ROMER_NAME) .addTypeFlag( TYPE_ROMER_FLAG) .createToBaseConverterSteps() - .add(TYPE_CELSIUS_OFFSET) - .multiplyFraction(TYPE_ROMER_FRACTION) - .add(TYPE_ROMER_FRACTION_OFFSET) + .offsetUp(TYPE_CELSIUS_OFFSET) + .multiply(TYPE_ROMER_FRACTION) + .offsetUp(TYPE_ROMER_FRACTION_OFFSET) .build() .createFromBaseConverterSteps() - .sub(TYPE_ROMER_FRACTION_OFFSET) - .multiplyFraction(TYPE_ROMER_FRACTION.invert()) - .substract(TYPE_CELSIUS_OFFSET) + .offsetDown(TYPE_ROMER_FRACTION_OFFSET) + .multiply(TYPE_ROMER_FRACTION.invert()) + .offsetDown(TYPE_CELSIUS_OFFSET) .build() .build() .build() diff --git a/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/UnitXCManagerTest.java b/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/UnitXCManagerTest.java index c7d9844..90157b6 100644 --- a/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/UnitXCManagerTest.java +++ b/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/UnitXCManagerTest.java @@ -6,7 +6,7 @@ import static org.junit.Assert.assertFalse; import org.junit.Test; -import net.forwardfire.unitxc.module.UnitXCTemperatureModule; +import net.forwardfire.unitxc.module.UnitXCModuleTemperature; public class UnitXCManagerTest { @@ -19,7 +19,7 @@ public class UnitXCManagerTest { @Test public void testGetUnitType() { - assertNotNull(test.getUnitType(UnitXCTemperatureModule.TYPE_KELVIN_ID)); + assertNotNull(test.getUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID)); } @Test(expected=NullPointerException.class) @@ -34,27 +34,27 @@ public class UnitXCManagerTest { @Test public void testGetUnitTypeResultId() { - assertNotNull(test.getUnitType(UnitXCTemperatureModule.TYPE_KELVIN_ID).getId()); + assertNotNull(test.getUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID).getId()); } @Test public void testGetUnitTypeResultName() { - assertNotNull(test.getUnitType(UnitXCTemperatureModule.TYPE_KELVIN_ID).getName()); + assertNotNull(test.getUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID).getName()); } @Test public void testGetUnitTypeResultTypeFlags() { - assertNotNull(test.getUnitType(UnitXCTemperatureModule.TYPE_KELVIN_ID).getTypeFlags()); + assertNotNull(test.getUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID).getTypeFlags()); } @Test public void testGetUnitTypeResultTypeGroupId() { - assertNotNull(test.getUnitType(UnitXCTemperatureModule.TYPE_KELVIN_ID).getTypeGroupId()); + assertNotNull(test.getUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID).getTypeGroupId()); } @Test public void testGetUnitTypeGroup() { - assertNotNull(test.getUnitTypeGroup(UnitXCTemperatureModule.GROUP_ID)); + assertNotNull(test.getUnitTypeGroup(UnitXCModuleTemperature.GROUP_ID)); } @Test(expected=NullPointerException.class) @@ -69,27 +69,27 @@ public class UnitXCManagerTest { @Test public void testGetUnitTypeGroupResultId() { - assertNotNull(test.getUnitTypeGroup(UnitXCTemperatureModule.GROUP_ID).getId()); + assertNotNull(test.getUnitTypeGroup(UnitXCModuleTemperature.GROUP_ID).getId()); } @Test public void testGetUnitTypeGroupResultName() { - assertNotNull(test.getUnitTypeGroup(UnitXCTemperatureModule.GROUP_ID).getName()); + assertNotNull(test.getUnitTypeGroup(UnitXCModuleTemperature.GROUP_ID).getName()); } @Test public void testGetUnitTypeGroupResultDescription() { - assertNotNull(test.getUnitTypeGroup(UnitXCTemperatureModule.GROUP_ID).getDescription()); + assertNotNull(test.getUnitTypeGroup(UnitXCModuleTemperature.GROUP_ID).getDescription()); } @Test public void testGetUnitTypeResultTypeBaseTypeID() { - assertNotNull(test.getUnitTypeGroup(UnitXCTemperatureModule.GROUP_ID).getBaseTypeId()); + assertNotNull(test.getUnitTypeGroup(UnitXCModuleTemperature.GROUP_ID).getBaseTypeId()); } @Test public void testIsUnitTypeGroupTrue() { - assertTrue(test.isUnitTypeGroup(UnitXCTemperatureModule.GROUP_ID)); + assertTrue(test.isUnitTypeGroup(UnitXCModuleTemperature.GROUP_ID)); } @Test @@ -109,7 +109,7 @@ public class UnitXCManagerTest { @Test public void testIsUnitTypeTrue() { - assertTrue(test.isUnitType(UnitXCTemperatureModule.TYPE_KELVIN_ID)); + assertTrue(test.isUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID)); } @Test diff --git a/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/module/UnitXCTemperatureModuleTest.java b/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/module/UnitXCTemperatureModuleTest.java index 433591b..f70f71c 100644 --- a/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/module/UnitXCTemperatureModuleTest.java +++ b/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/module/UnitXCTemperatureModuleTest.java @@ -35,6 +35,7 @@ import static net.forwardfire.unitxc.UnitXCAssert.convertEquals; import net.forwardfire.unitxc.UnitXCFactory; import net.forwardfire.unitxc.UnitXCManager; import net.forwardfire.unitxc.model.UnitXCType; +import net.forwardfire.unitxc.model.UnitXCTypeGroup; import net.forwardfire.unitxc.model.UnitXConverterResult; import net.forwardfire.unitxc.model.UnitXConverterResultStep; @@ -52,11 +53,20 @@ public class UnitXCTemperatureModuleTest { assertNotNull(unitManager.getUnitTypes()); - for (UnitXCType type:unitManager.getUnitTypes()) { - System.out.println("type: "+type.getId()+"\t name: "+type.getName()+"\t\t flags: "+type.getTypeFlags()); + for (UnitXCTypeGroup typeGroup:unitManager.getUnitTypeGroups()) { + System.out.println("TypeGroup: "+typeGroup.getId()+"\t name: "+typeGroup.getName()+"\t\t baseType: "+typeGroup.getBaseTypeId()); + + int total = 0; + for (UnitXCType type:unitManager.getUnitTypes()) { + if (!type.getTypeGroupId().equals(typeGroup.getId())) { + continue; + } + total++; + } + System.out.println("typeInGroup: "+total); } int ts = unitManager.getUnitTypes().size(); - System.out.println("totalTypes: "+ts); + System.out.println("\ntotalTypes: "+ts); System.out.println("totalConv: "+(ts*ts-ts)); UnitXConverterResult result = unitManager.getConverter().convertStepped(211.0, "k°F", "m°C"); @@ -70,7 +80,7 @@ public class UnitXCTemperatureModuleTest { System.out.println(""); - result = unitManager.getConverter().convertStepped(100.0, "K", "°C"); + result = unitManager.getConverter().convertStepped(640.0, "nK", "µK"); System.out.println("Convert from: "+result.getStartType().getName()+" to: "+result.getResultType().getName()); System.out.println("startValue: "+result.getStartValue()); System.out.println("resultValue: "+result.getResultValue());