Add some unit groups

This commit is contained in:
Willem 2015-10-24 14:28:37 +02:00
parent 9ac4acae7b
commit 7e521b18d9
10 changed files with 304 additions and 46 deletions

View file

@ -30,14 +30,20 @@ import java.util.List;
import net.forwardfire.unitxc.config.UnitXCConfig; import net.forwardfire.unitxc.config.UnitXCConfig;
import net.forwardfire.unitxc.config.UnitXCConfigManager; import net.forwardfire.unitxc.config.UnitXCConfigManager;
import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.UnitXCConfigModule;
import net.forwardfire.unitxc.module.UnitXCElectricCurrentModule; import net.forwardfire.unitxc.module.UnitXCModuleAmountOfSubstance;
import net.forwardfire.unitxc.module.UnitXCTemperatureModule; 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 { public final class UnitXCFactory {
private static final List<UnitXCConfigModule> DEFAULT_CONFIG_MODULES = Collections.unmodifiableList(Arrays.asList( private static final List<UnitXCConfigModule> DEFAULT_CONFIG_MODULES = Collections.unmodifiableList(Arrays.asList(
new UnitXCTemperatureModule(), new UnitXCModuleTemperature(),
new UnitXCElectricCurrentModule() new UnitXCModuleElectricCurrent(),
new UnitXCModuleLuminousIntensity(),
new UnitXCModuleAmountOfSubstance(),
new UnitXCModuleLength()
)); ));

View file

@ -78,7 +78,7 @@ public abstract class AbstractUnitXCTypeBuilder<P,B> extends AbstractUnitXCBuild
} }
public B addToBaseConverterStep(UnitXConverterStep unitTypeConverter) { public B addToBaseConverterStep(UnitXConverterStep unitTypeConverter) {
return make((v) -> v.addFromBaseConverterStep(unitTypeConverter)); return make((v) -> v.addToBaseConverterStep(unitTypeConverter));
} }
public B addToBaseConverterSteps(List<UnitXConverterStep> unitTypeConverters) { public B addToBaseConverterSteps(List<UnitXConverterStep> unitTypeConverters) {

View file

@ -30,6 +30,7 @@ import java.util.function.BiConsumer;
import org.apache.commons.lang3.math.Fraction; import org.apache.commons.lang3.math.Fraction;
import net.forwardfire.unitxc.converter.step.UnitXCTypeDevideConverterStep; 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.UnitXCTypeMultiplyConverterStep;
import net.forwardfire.unitxc.converter.step.UnitXCTypeMultiplyFractionConverterStep; import net.forwardfire.unitxc.converter.step.UnitXCTypeMultiplyFractionConverterStep;
import net.forwardfire.unitxc.converter.step.UnitXCTypeOffsetConverterStep; import net.forwardfire.unitxc.converter.step.UnitXCTypeOffsetConverterStep;
@ -46,22 +47,20 @@ public class UnitXConverterStepBuilder<P> extends AbstractUnitXCBuilder<P,List<U
return this; return this;
} }
public UnitXConverterStepBuilder<P> add(double offset) { public UnitXConverterStepBuilder<P> offsetUp(double offset) {
return offset(offset,true); return offset(offset,true);
} }
public UnitXConverterStepBuilder<P> sub(double offset) { public UnitXConverterStepBuilder<P> offsetDown(double offset) {
return offset(offset,false); return offset(offset,false);
} }
public UnitXConverterStepBuilder<P> substract(double offset) { private UnitXConverterStepBuilder<P> offset(double offset,boolean offsetPositive) {
return offset(offset,false);
}
public UnitXConverterStepBuilder<P> offset(double offset,boolean offsetPositive) {
return make(v -> v.add(new UnitXCTypeOffsetConverterStep(offset,offsetPositive))); return make(v -> v.add(new UnitXCTypeOffsetConverterStep(offset,offsetPositive)));
} }
public UnitXConverterStepBuilder<P> multiplyFraction(Fraction fraction) {
public UnitXConverterStepBuilder<P> multiply(Fraction fraction) {
return make(v -> v.add(new UnitXCTypeMultiplyFractionConverterStep(fraction))); return make(v -> v.add(new UnitXCTypeMultiplyFractionConverterStep(fraction)));
} }
public UnitXConverterStepBuilder<P> multiplyFraction(int numerator,int denominator) { public UnitXConverterStepBuilder<P> multiply(int numerator,int denominator) {
return make(v -> v.add(new UnitXCTypeMultiplyFractionConverterStep(numerator,denominator))); return make(v -> v.add(new UnitXCTypeMultiplyFractionConverterStep(numerator,denominator)));
} }
public UnitXConverterStepBuilder<P> multiply(double factor) { public UnitXConverterStepBuilder<P> multiply(double factor) {
@ -70,4 +69,14 @@ public class UnitXConverterStepBuilder<P> extends AbstractUnitXCBuilder<P,List<U
public UnitXConverterStepBuilder<P> divide(double factor) { public UnitXConverterStepBuilder<P> divide(double factor) {
return make(v -> v.add(new UnitXCTypeDevideConverterStep(factor))); return make(v -> v.add(new UnitXCTypeDevideConverterStep(factor)));
} }
private UnitXConverterStepBuilder<P> exponent(int exponent,boolean rev) {
return make(v -> v.add(new UnitXCTypeExponentConverterStep(exponent,rev)));
}
public UnitXConverterStepBuilder<P> exponentUp(UnitXCTypeSIPrefix exponent) {
return exponent(exponent.getExponent(), false);
}
public UnitXConverterStepBuilder<P> exponentDown(UnitXCTypeSIPrefix exponent) {
return exponent(exponent.getExponent(), true);
}
} }

View file

@ -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()
;
}
}

View file

@ -27,7 +27,7 @@ import net.forwardfire.unitxc.config.UnitXCConfigModule;
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix; 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_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."; 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.";

View file

@ -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));
}
}

View file

@ -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()
;
}
}

View file

@ -28,7 +28,7 @@ import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
import org.apache.commons.lang3.math.Fraction; 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_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."; 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) .setId( TYPE_CELSIUS_ID)
.setName( TYPE_CELSIUS_NAME) .setName( TYPE_CELSIUS_NAME)
.addTypeFlag( TYPE_CELSIUS_FLAG) .addTypeFlag( TYPE_CELSIUS_FLAG)
.createToBaseConverterSteps().add(TYPE_CELSIUS_OFFSET).build() .createToBaseConverterSteps().offsetUp(TYPE_CELSIUS_OFFSET).build()
.createFromBaseConverterSteps().sub(TYPE_CELSIUS_OFFSET).build() .createFromBaseConverterSteps().offsetDown(TYPE_CELSIUS_OFFSET).build()
.build() .build()
.createSIUnitTypes() .createSIUnitTypes()
.setId( TYPE_FAHRENHEIT_ID) .setId( TYPE_FAHRENHEIT_ID)
.setName( TYPE_FAHRENHEIT_NAME) .setName( TYPE_FAHRENHEIT_NAME)
.addTypeFlag( TYPE_FAHRENHEIT_FLAG) .addTypeFlag( TYPE_FAHRENHEIT_FLAG)
.createToBaseConverterSteps() .createToBaseConverterSteps()
.add(TYPE_FAHRENHEIT_OFFSET) .offsetUp(TYPE_FAHRENHEIT_OFFSET)
.multiplyFraction(TYPE_FAHRENHEIT_FRACTION) .multiply(TYPE_FAHRENHEIT_FRACTION)
.build() .build()
.createFromBaseConverterSteps() .createFromBaseConverterSteps()
.multiplyFraction(TYPE_FAHRENHEIT_FRACTION.invert()) .multiply(TYPE_FAHRENHEIT_FRACTION.invert())
.substract(TYPE_FAHRENHEIT_OFFSET) .offsetDown(TYPE_FAHRENHEIT_OFFSET)
.build() .build()
.build() .build()
.createSIUnitTypes() .createSIUnitTypes()
.setId( TYPE_RANKINE_ID) .setId( TYPE_RANKINE_ID)
.setName( TYPE_RANKINE_NAME) .setName( TYPE_RANKINE_NAME)
.addTypeFlag( TYPE_RANKINE_FLAG) .addTypeFlag( TYPE_RANKINE_FLAG)
.createToBaseConverterSteps().multiplyFraction(TYPE_FAHRENHEIT_FRACTION).build() .createToBaseConverterSteps().multiply(TYPE_FAHRENHEIT_FRACTION).build()
.createFromBaseConverterSteps().multiplyFraction(TYPE_FAHRENHEIT_FRACTION.invert()).build() .createFromBaseConverterSteps().multiply(TYPE_FAHRENHEIT_FRACTION.invert()).build()
.build() .build()
.createSIUnitTypes() .createSIUnitTypes()
.setId( TYPE_ROMER_ID) .setId( TYPE_ROMER_ID)
.setName( TYPE_ROMER_NAME) .setName( TYPE_ROMER_NAME)
.addTypeFlag( TYPE_ROMER_FLAG) .addTypeFlag( TYPE_ROMER_FLAG)
.createToBaseConverterSteps() .createToBaseConverterSteps()
.add(TYPE_CELSIUS_OFFSET) .offsetUp(TYPE_CELSIUS_OFFSET)
.multiplyFraction(TYPE_ROMER_FRACTION) .multiply(TYPE_ROMER_FRACTION)
.add(TYPE_ROMER_FRACTION_OFFSET) .offsetUp(TYPE_ROMER_FRACTION_OFFSET)
.build() .build()
.createFromBaseConverterSteps() .createFromBaseConverterSteps()
.sub(TYPE_ROMER_FRACTION_OFFSET) .offsetDown(TYPE_ROMER_FRACTION_OFFSET)
.multiplyFraction(TYPE_ROMER_FRACTION.invert()) .multiply(TYPE_ROMER_FRACTION.invert())
.substract(TYPE_CELSIUS_OFFSET) .offsetDown(TYPE_CELSIUS_OFFSET)
.build() .build()
.build() .build()
.build() .build()

View file

@ -6,7 +6,7 @@ import static org.junit.Assert.assertFalse;
import org.junit.Test; import org.junit.Test;
import net.forwardfire.unitxc.module.UnitXCTemperatureModule; import net.forwardfire.unitxc.module.UnitXCModuleTemperature;
public class UnitXCManagerTest { public class UnitXCManagerTest {
@ -19,7 +19,7 @@ public class UnitXCManagerTest {
@Test @Test
public void testGetUnitType() { public void testGetUnitType() {
assertNotNull(test.getUnitType(UnitXCTemperatureModule.TYPE_KELVIN_ID)); assertNotNull(test.getUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID));
} }
@Test(expected=NullPointerException.class) @Test(expected=NullPointerException.class)
@ -34,27 +34,27 @@ public class UnitXCManagerTest {
@Test @Test
public void testGetUnitTypeResultId() { public void testGetUnitTypeResultId() {
assertNotNull(test.getUnitType(UnitXCTemperatureModule.TYPE_KELVIN_ID).getId()); assertNotNull(test.getUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID).getId());
} }
@Test @Test
public void testGetUnitTypeResultName() { public void testGetUnitTypeResultName() {
assertNotNull(test.getUnitType(UnitXCTemperatureModule.TYPE_KELVIN_ID).getName()); assertNotNull(test.getUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID).getName());
} }
@Test @Test
public void testGetUnitTypeResultTypeFlags() { public void testGetUnitTypeResultTypeFlags() {
assertNotNull(test.getUnitType(UnitXCTemperatureModule.TYPE_KELVIN_ID).getTypeFlags()); assertNotNull(test.getUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID).getTypeFlags());
} }
@Test @Test
public void testGetUnitTypeResultTypeGroupId() { public void testGetUnitTypeResultTypeGroupId() {
assertNotNull(test.getUnitType(UnitXCTemperatureModule.TYPE_KELVIN_ID).getTypeGroupId()); assertNotNull(test.getUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID).getTypeGroupId());
} }
@Test @Test
public void testGetUnitTypeGroup() { public void testGetUnitTypeGroup() {
assertNotNull(test.getUnitTypeGroup(UnitXCTemperatureModule.GROUP_ID)); assertNotNull(test.getUnitTypeGroup(UnitXCModuleTemperature.GROUP_ID));
} }
@Test(expected=NullPointerException.class) @Test(expected=NullPointerException.class)
@ -69,27 +69,27 @@ public class UnitXCManagerTest {
@Test @Test
public void testGetUnitTypeGroupResultId() { public void testGetUnitTypeGroupResultId() {
assertNotNull(test.getUnitTypeGroup(UnitXCTemperatureModule.GROUP_ID).getId()); assertNotNull(test.getUnitTypeGroup(UnitXCModuleTemperature.GROUP_ID).getId());
} }
@Test @Test
public void testGetUnitTypeGroupResultName() { public void testGetUnitTypeGroupResultName() {
assertNotNull(test.getUnitTypeGroup(UnitXCTemperatureModule.GROUP_ID).getName()); assertNotNull(test.getUnitTypeGroup(UnitXCModuleTemperature.GROUP_ID).getName());
} }
@Test @Test
public void testGetUnitTypeGroupResultDescription() { public void testGetUnitTypeGroupResultDescription() {
assertNotNull(test.getUnitTypeGroup(UnitXCTemperatureModule.GROUP_ID).getDescription()); assertNotNull(test.getUnitTypeGroup(UnitXCModuleTemperature.GROUP_ID).getDescription());
} }
@Test @Test
public void testGetUnitTypeResultTypeBaseTypeID() { public void testGetUnitTypeResultTypeBaseTypeID() {
assertNotNull(test.getUnitTypeGroup(UnitXCTemperatureModule.GROUP_ID).getBaseTypeId()); assertNotNull(test.getUnitTypeGroup(UnitXCModuleTemperature.GROUP_ID).getBaseTypeId());
} }
@Test @Test
public void testIsUnitTypeGroupTrue() { public void testIsUnitTypeGroupTrue() {
assertTrue(test.isUnitTypeGroup(UnitXCTemperatureModule.GROUP_ID)); assertTrue(test.isUnitTypeGroup(UnitXCModuleTemperature.GROUP_ID));
} }
@Test @Test
@ -109,7 +109,7 @@ public class UnitXCManagerTest {
@Test @Test
public void testIsUnitTypeTrue() { public void testIsUnitTypeTrue() {
assertTrue(test.isUnitType(UnitXCTemperatureModule.TYPE_KELVIN_ID)); assertTrue(test.isUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID));
} }
@Test @Test

View file

@ -35,6 +35,7 @@ import static net.forwardfire.unitxc.UnitXCAssert.convertEquals;
import net.forwardfire.unitxc.UnitXCFactory; import net.forwardfire.unitxc.UnitXCFactory;
import net.forwardfire.unitxc.UnitXCManager; import net.forwardfire.unitxc.UnitXCManager;
import net.forwardfire.unitxc.model.UnitXCType; import net.forwardfire.unitxc.model.UnitXCType;
import net.forwardfire.unitxc.model.UnitXCTypeGroup;
import net.forwardfire.unitxc.model.UnitXConverterResult; import net.forwardfire.unitxc.model.UnitXConverterResult;
import net.forwardfire.unitxc.model.UnitXConverterResultStep; import net.forwardfire.unitxc.model.UnitXConverterResultStep;
@ -52,11 +53,20 @@ public class UnitXCTemperatureModuleTest {
assertNotNull(unitManager.getUnitTypes()); assertNotNull(unitManager.getUnitTypes());
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()) { for (UnitXCType type:unitManager.getUnitTypes()) {
System.out.println("type: "+type.getId()+"\t name: "+type.getName()+"\t\t flags: "+type.getTypeFlags()); if (!type.getTypeGroupId().equals(typeGroup.getId())) {
continue;
}
total++;
}
System.out.println("typeInGroup: "+total);
} }
int ts = unitManager.getUnitTypes().size(); int ts = unitManager.getUnitTypes().size();
System.out.println("totalTypes: "+ts); System.out.println("\ntotalTypes: "+ts);
System.out.println("totalConv: "+(ts*ts-ts)); System.out.println("totalConv: "+(ts*ts-ts));
UnitXConverterResult result = unitManager.getConverter().convertStepped(211.0, "k°F", "m°C"); UnitXConverterResult result = unitManager.getConverter().convertStepped(211.0, "k°F", "m°C");
@ -70,7 +80,7 @@ public class UnitXCTemperatureModuleTest {
System.out.println(""); 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("Convert from: "+result.getStartType().getName()+" to: "+result.getResultType().getName());
System.out.println("startValue: "+result.getStartValue()); System.out.println("startValue: "+result.getStartValue());
System.out.println("resultValue: "+result.getResultValue()); System.out.println("resultValue: "+result.getResultValue());