diff --git a/.gitignore b/.gitignore
index 7e2f935..640b326 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
#
-# Ignore some files in the ff-unit-converter project.
+# Ignore some files in the ff-unitxc project.
#
# Ignore all maven target directories
diff --git a/ff-unitxc-converter/pom.xml b/ff-unitxc-converter/pom.xml
index 5680472..0ff8923 100644
--- a/ff-unitxc-converter/pom.xml
+++ b/ff-unitxc-converter/pom.xml
@@ -6,4 +6,16 @@
0.0.1-SNAPSHOT
ff-unitxc-converter
+
+
+ org.slf4j
+ slf4j-api
+ compile
+
+
+ org.apache.commons
+ commons-lang3
+ compile
+
+
\ No newline at end of file
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
new file mode 100644
index 0000000..fb1c0a8
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/UnitXCFactory.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2014-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;
+
+import java.util.Arrays;
+import java.util.Collections;
+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.converter.step.UnitXCTypeDevideConverterStep;
+import net.forwardfire.unitxc.converter.step.UnitXCTypeMultiplyConverterStep;
+import net.forwardfire.unitxc.converter.step.UnitXCTypeMultiplyFractionConverterStep;
+import net.forwardfire.unitxc.converter.step.UnitXCTypeOffsetConverterStep;
+import net.forwardfire.unitxc.module.UnitXCElectricCurrentModule;
+import net.forwardfire.unitxc.module.UnitXCTemperatureModule;
+
+public final class UnitXCFactory {
+
+ private static final List DEFAULT_CONFIG_MODULES = Collections.unmodifiableList(Arrays.asList(
+ new UnitXCTemperatureModule(),
+ new UnitXCElectricCurrentModule()
+ ));
+
+
+ protected UnitXCFactory() {
+ }
+
+
+ public static UnitXCConfig createConfig() {
+ return createConfig(DEFAULT_CONFIG_MODULES);
+ }
+
+ public static UnitXCConfig createConfig(List configInit) {
+ return UnitXCConfigModule.buildAll(new UnitXCConfig(), configInit);
+ }
+
+ public static UnitXCManager createManager() {
+ return createManager(createConfig());
+ }
+
+ public static UnitXCManager createManager(UnitXCConfig config) {
+ return new UnitXCConfigManager(config);
+ }
+
+ public static class MathStep {
+ public static UnitXCTypeOffsetConverterStep add(double offset) {
+ return offset(offset,true);
+ }
+ public static UnitXCTypeOffsetConverterStep substract(double offset) {
+ return offset(offset,false);
+ }
+ public static UnitXCTypeOffsetConverterStep offset(double offset,boolean offsetPositive) {
+ return new UnitXCTypeOffsetConverterStep(offset,offsetPositive);
+ }
+ public static UnitXCTypeMultiplyFractionConverterStep multiplyFraction(int numerator,int denominator) {
+ return new UnitXCTypeMultiplyFractionConverterStep(numerator,denominator);
+ }
+ public static UnitXCTypeMultiplyConverterStep multiply(double factor) {
+ return new UnitXCTypeMultiplyConverterStep(factor);
+ }
+ public static UnitXCTypeDevideConverterStep divide(double factor) {
+ return new UnitXCTypeDevideConverterStep(factor);
+ }
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/UnitXCManager.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/UnitXCManager.java
new file mode 100644
index 0000000..fcb3cd0
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/UnitXCManager.java
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+import java.util.Collection;
+
+import net.forwardfire.unitxc.converter.UnitXConverter;
+import net.forwardfire.unitxc.model.UnitXCType;
+import net.forwardfire.unitxc.model.UnitXCTypeGroup;
+
+public interface UnitXCManager {
+
+ Collection getUnitTypes();
+
+ UnitXCType getUnitType(String id);
+
+ boolean isUnitType(String id);
+
+ Collection getUnitTypeGroups();
+
+ UnitXCTypeGroup getUnitTypeGroup(String id);
+
+ boolean isUnitTypeGroup(String id);
+
+ UnitXConverter getConverter();
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/UnitXCConfig.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/UnitXCConfig.java
new file mode 100644
index 0000000..b6bd23a
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/UnitXCConfig.java
@@ -0,0 +1,79 @@
+/*
+ * 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.config;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.lang3.Validate;
+
+import net.forwardfire.unitxc.model.UnitXCTypeModel;
+import net.forwardfire.unitxc.model.UnitXCTypeGroupModel;
+
+public final class UnitXCConfig {
+
+ private final Map unitTypes;
+ private final Map unitTypeGroups;
+
+ public UnitXCConfig() {
+ unitTypeGroups = new HashMap<>();
+ unitTypes = new HashMap<>();
+ }
+
+ /**
+ * @return the unitTypes
+ */
+ public Collection getUnitTypes() {
+ return unitTypes.values();
+ }
+
+ public void addUnitType(UnitXCTypeModel unitType) {
+ putUnitType(validateGroupId(Validate.notNull(unitType).validate()));
+ }
+
+ private UnitXCTypeModel validateGroupId(UnitXCTypeModel unitType) {
+ Validate.isTrue(unitTypeGroups.containsKey(unitType.getTypeGroupId()));
+ return unitType;
+ }
+
+ private void putUnitType(UnitXCTypeModel unitType) {
+ unitTypes.put(unitType.getId(), unitType);
+ }
+
+ /**
+ * @return the unitTypeGroups
+ */
+ public Collection getUnitTypeGroups() {
+ return unitTypeGroups.values();
+ }
+
+ public void addUnitTypeGroup(UnitXCTypeGroupModel unitTypeGroup) {
+ putUnitTypeGroup(Validate.notNull(unitTypeGroup).validate());
+ }
+
+ private void putUnitTypeGroup(UnitXCTypeGroupModel unitTypeGroup) {
+ unitTypeGroups.put(unitTypeGroup.getId(),unitTypeGroup);
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigBuildTypeMultiples.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigBuildTypeMultiples.java
new file mode 100644
index 0000000..bffe198
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigBuildTypeMultiples.java
@@ -0,0 +1,84 @@
+/*
+ * 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.config;
+
+import org.apache.commons.lang3.Validate;
+
+import net.forwardfire.unitxc.converter.step.UnitXConverterStep;
+
+public final class UnitXCConfigBuildTypeMultiples {
+
+ private final String type;
+ private final String typeName;
+ private final String flag;
+ private final UnitXConverterStep[] toConverters;
+ private final UnitXConverterStep[] fromConverters;
+
+ public UnitXCConfigBuildTypeMultiples(String type,String typeName,String flag) {
+ this(type,typeName,flag,new UnitXConverterStep[]{},new UnitXConverterStep[]{});
+ }
+
+ public UnitXCConfigBuildTypeMultiples(String type,String typeName,String flag,UnitXConverterStep[] toConverters,UnitXConverterStep[] fromConverters) {
+ this.type = Validate.notNull(type);
+ this.typeName = Validate.notNull(typeName);
+ this.flag = Validate.notNull(flag);
+ this.toConverters = Validate.notNull(toConverters);
+ this.fromConverters = Validate.notNull(fromConverters);
+ }
+
+ /**
+ * @return the type
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * @return the typeName
+ */
+ public String getTypeName() {
+ return typeName;
+ }
+
+ /**
+ * @return the flag
+ */
+ public String getFlag() {
+ return flag;
+ }
+
+ /**
+ * @return the toConverters
+ */
+ public UnitXConverterStep[] getToConverters() {
+ return toConverters;
+ }
+
+ /**
+ * @return the fromConverters
+ */
+ public UnitXConverterStep[] getFromConverters() {
+ return fromConverters;
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigManager.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigManager.java
new file mode 100644
index 0000000..59a8a45
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigManager.java
@@ -0,0 +1,130 @@
+/*
+ * 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.config;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.lang3.Validate;
+
+import net.forwardfire.unitxc.UnitXCManager;
+import net.forwardfire.unitxc.converter.UnitXConverter;
+import net.forwardfire.unitxc.converter.UnitXConverterEngine;
+import net.forwardfire.unitxc.model.UnitXCTypeModel;
+import net.forwardfire.unitxc.model.UnitXCTypeGroupModel;
+import net.forwardfire.unitxc.model.UnitXCType;
+import net.forwardfire.unitxc.model.UnitXCTypeGroup;
+import net.forwardfire.unitxc.model.UnitXConverterResult;
+
+public class UnitXCConfigManager implements UnitXCManager {
+
+ private final UnitXCConfig config;
+ private final Map unitTypes;
+ private final Map unitTypeGroups;
+ private final UnitXConverter converter;
+ private final UnitXConverterEngine convertEngine;
+
+ public UnitXCConfigManager(UnitXCConfig config) {
+ this.config = Validate.notNull(config);
+ this.unitTypes = Collections.unmodifiableMap(createUnitTypes(config.getUnitTypes()));
+ this.unitTypeGroups = Collections.unmodifiableMap(createUnitTypeGroups(config.getUnitTypeGroups()));
+
+ this.convertEngine = new UnitXConverterEngine(this);
+ this.converter = new UnitXConverterImpl();
+ }
+
+ private static Map createUnitTypes(Collection values) {
+ Map result = new HashMap<>();
+ values.forEach((value) -> result.put(value.getId(), value));
+ return result;
+ }
+
+ private static Map createUnitTypeGroups(Collection values) {
+ Map result = new HashMap<>();
+ values.forEach((value) -> result.put(value.getId(), value));
+ return result;
+ }
+
+ @Override
+ public Collection getUnitTypes() {
+ return unitTypes.values();
+ }
+
+ @Override
+ public UnitXCType getUnitType(String id) {
+ return Validate.notNull(unitTypes.get(Validate.notNull(id,"Null is not a validate id.")),"No type for: "+id);
+ }
+
+ @Override
+ public boolean isUnitType(String id) {
+ return unitTypes.containsKey(id);
+ }
+
+ @Override
+ public Collection getUnitTypeGroups() {
+ return unitTypeGroups.values();
+ }
+
+ @Override
+ public UnitXCTypeGroup getUnitTypeGroup(String id) {
+ return Validate.notNull(unitTypeGroups.get(Validate.notNull(id,"Null is not a validate id.")),"No group for: "+id);
+ }
+
+ @Override
+ public boolean isUnitTypeGroup(String id) {
+ return unitTypeGroups.containsKey(id);
+ }
+
+ @Override
+ public UnitXConverter getConverter() {
+ return converter;
+ }
+
+ private class UnitXConverterImpl implements UnitXConverter {
+
+
+ @Override
+ public double convert(double value, String fromTypeId, String toTypeId) {
+ return convert(value, getUnitType(fromTypeId), getUnitType(toTypeId));
+ }
+
+ @Override
+ public double convert(double value, UnitXCType fromType, UnitXCType toType) {
+ return convertStepped(value,fromType,toType).getResultValue();
+ }
+
+ @Override
+ public UnitXConverterResult convertStepped(double value, String fromTypeId, String toTypeId) {
+ return convertStepped(value, getUnitType(fromTypeId), getUnitType(toTypeId));
+ }
+
+ @Override
+ public UnitXConverterResult convertStepped(double value, UnitXCType fromType, UnitXCType toType) {
+ // TODO: rm casting
+ return convertEngine.convertStepped(value, (UnitXCTypeModel)fromType, (UnitXCTypeModel)toType);
+ }
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigModule.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigModule.java
new file mode 100644
index 0000000..5bad728
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigModule.java
@@ -0,0 +1,37 @@
+/*
+ * 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.config;
+
+import java.util.List;
+
+public interface UnitXCConfigModule {
+
+ void configModule(UnitXCConfigModuleBuilder config);
+
+ static UnitXCConfig buildAll(UnitXCConfig config,List configInit) {
+ UnitXCConfigModuleBuilder builder = new UnitXCConfigModuleBuilder(config);
+ configInit.forEach(ci -> ci.configModule(builder));
+ return config;
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigModuleBuilder.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigModuleBuilder.java
new file mode 100644
index 0000000..266695d
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/UnitXCConfigModuleBuilder.java
@@ -0,0 +1,164 @@
+/*
+ * 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.config;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.lang3.Validate;
+
+import net.forwardfire.unitxc.converter.step.UnitXCTypeExponentConverterStep;
+import net.forwardfire.unitxc.converter.step.UnitXConverterStep;
+import net.forwardfire.unitxc.model.UnitXCTypeModel;
+import net.forwardfire.unitxc.model.UnitXCTypeGroupModel;
+
+public class UnitXCConfigModuleBuilder {
+
+ private final UnitXCConfig config;
+
+ public UnitXCConfigModuleBuilder(UnitXCConfig config) {
+ this.config = Validate.notNull(config);
+ }
+
+ public void addUnitTypeGroup(String id,String baseTypeId,String name,String description) {
+ config.addUnitTypeGroup(new UnitXCTypeGroupModel(id,name,description,baseTypeId));
+ }
+
+ //private void addUnitType(String groupId,String id,int factorExp,String name) {
+ // addUnitType(conv,groupId, id, factorExp, name,null);
+ //}
+ private void addUnitType(List toConverters,List fromConverters,String groupId,String id,int factorExp,String name,List typeFlags) {
+ UnitXCTypeModel result = new UnitXCTypeModel();
+ result.setId(id);
+ result.setName(name);
+ if (factorExp != 0) {
+ result.addToBaseConverterStep(new UnitXCTypeExponentConverterStep(factorExp,false));
+ }
+ toConverters.forEach((conv) ->result.addToBaseConverterStep(conv));
+ fromConverters.forEach((conv) ->result.addFromBaseConverterStep(conv));
+ if (factorExp != 0) {
+ result.addFromBaseConverterStep(new UnitXCTypeExponentConverterStep(factorExp,true));
+ }
+ result.setTypeGroupId(groupId);
+ typeFlags.forEach((flag) -> result.addTypeFlag(flag));
+ config.addUnitType(result);
+ }
+
+
+ public enum SiMultiple {
+ YOTTA ("Y", 24),
+ ZETTA ("Z", 21),
+ EXA ("E", 18),
+ PETA ("P", 15),
+ TERA ("T", 12),
+ GIGA ("G", 9),
+ MEGA ("M", 6),
+ KILO ("k", 3),
+ HECTO ("h", 2),
+ DECA ("da",1),
+ DECI ("d", -1),
+ CENTI ("c", -2),
+ MILLI ("m", -3),
+ MICRO ("µ", -6),
+ NANO ("n", -9),
+ PICO ("p", -12),
+ FEMTO ("f", -15),
+ ATTO ("a", -18),
+ ZEPTO ("z", -21),
+ YOCTO ("y", -24),
+ ;
+
+ public static final String TYPE_FLAG_SI_UNIT = "SI_UNIT";
+ public static final String TYPE_FLAG_SI_UNIT_BIGGER = "SI_UNIT_BIGGER";
+ public static final String TYPE_FLAG_SI_UNIT_BIGGEST = "SI_UNIT_BIGGEST";
+
+ private final String id;
+ private final String name;
+ private final int exponent;
+ private final List flags;
+
+ private SiMultiple(String id,int exponent) {
+ this.id=id;
+ this.name = this.name().toLowerCase();
+ this.exponent=exponent;
+ List f = new ArrayList<>(3);
+ f.add(TYPE_FLAG_SI_UNIT);
+ if (exponent > 3 || exponent < -3) {
+ f.add(TYPE_FLAG_SI_UNIT_BIGGER);
+ }
+ if (exponent > 12 || exponent < -12) {
+ f.add(TYPE_FLAG_SI_UNIT_BIGGEST);
+ }
+ this.flags = Collections.unmodifiableList(f);
+ }
+
+ public String getPrefixId() {
+ return id;
+ }
+
+ public String getPrefixName() {
+ return name;
+ }
+
+ public int getExponent() {
+ return exponent;
+ }
+
+ public List getFlags() {
+ return flags;
+ }
+ }
+
+ public static final String TYPE_FLAG_SI_UNIT_SILLY = "SI_UNIT_SILLY";
+
+ public void addSIMultiples(String groupId,String type,String typeName,String flag) {
+ List flags = new ArrayList<>();
+ flags.add(flag);
+ createTypesSIMultiples(groupId,type,typeName,flags,new ArrayList<>(),new ArrayList<>(),false);
+ }
+
+ public void addSIMultiplesSilly(String groupId,UnitXCConfigBuildTypeMultiples builder) {
+ List flags = new ArrayList<>();
+ flags.add(builder.getFlag());
+ createTypesSIMultiples(groupId,builder.getType(),builder.getTypeName(),flags,Arrays.asList(builder.getToConverters()),Arrays.asList(builder.getFromConverters()),true);
+ }
+
+
+ private void createTypesSIMultiples(String groupId,String type,String typeName,List flags,List toConverters,List fromConverters,boolean addSilly) {
+ // Create base unit
+ addUnitType(toConverters,fromConverters,groupId,type,0,typeName,flags);
+ // Create si values
+ for (SiMultiple sim:SiMultiple.values()) {
+ List typeFlags = new ArrayList<>();
+ typeFlags.addAll(flags);
+ typeFlags.addAll(sim.getFlags());
+ if (addSilly) {
+ typeFlags.add(TYPE_FLAG_SI_UNIT_SILLY);
+ }
+ addUnitType(toConverters,fromConverters, groupId, sim.getPrefixId()+type, sim.getExponent(), sim.getPrefixName()+typeName, typeFlags);
+ }
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/package-info.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/package-info.java
new file mode 100644
index 0000000..153fb49
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/package-info.java
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+/**
+ * @author willemc
+ *
+ */
+package net.forwardfire.unitxc.config.builder;
\ No newline at end of file
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/package-info.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/package-info.java
new file mode 100644
index 0000000..9055cbd
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/package-info.java
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+/**
+ * @author willemc
+ *
+ */
+package net.forwardfire.unitxc.config;
\ No newline at end of file
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/UnitXConverter.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/UnitXConverter.java
index e86d05e..51c3b43 100644
--- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/UnitXConverter.java
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/UnitXConverter.java
@@ -1,8 +1,38 @@
+/*
+ * 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.converter;
-public interface UnitXConverter {
+import net.forwardfire.unitxc.model.UnitXCType;
+import net.forwardfire.unitxc.model.UnitXConverterResult;
+public interface UnitXConverter {
+
double convert(double value,String fromTypeId,String toTypeId);
- double convert(double value/*,UnitXType fromType,UnitXType toType*/);
+ double convert(double value,UnitXCType fromType,UnitXCType toType);
+
+ UnitXConverterResult convertStepped(double value,String fromTypeId,String toTypeId);
+
+ UnitXConverterResult convertStepped(double value,UnitXCType fromType,UnitXCType toType);
}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/UnitXConverterEngine.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/UnitXConverterEngine.java
new file mode 100644
index 0000000..b41f546
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/UnitXConverterEngine.java
@@ -0,0 +1,121 @@
+/*
+ * 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.converter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import net.forwardfire.unitxc.UnitXCManager;
+import net.forwardfire.unitxc.config.UnitXCConfig;
+import net.forwardfire.unitxc.converter.step.UnitXConverterStep;
+import net.forwardfire.unitxc.model.UnitXCTypeModel;
+import net.forwardfire.unitxc.model.UnitXCTypeGroup;
+import net.forwardfire.unitxc.model.UnitXConverterResult;
+import net.forwardfire.unitxc.model.UnitXConverterResultModel;
+import net.forwardfire.unitxc.model.UnitXConverterResultStep;
+import net.forwardfire.unitxc.model.UnitXConverterResultStepModel;
+
+public final class UnitXConverterEngine {
+
+ private final static Logger LOG = LoggerFactory.getLogger(UnitXConverterEngine.class);
+ private final UnitXCManager manager;
+
+ public UnitXConverterEngine(UnitXCManager manager) {
+ this.manager = manager;
+ }
+
+ public UnitXConverterResult convertStepped(double value,UnitXCTypeModel fromType,UnitXCTypeModel toType) {
+ long startTime = System.currentTimeMillis();
+ double startValue = value;
+ List resultSteps = new ArrayList<>();
+
+ UnitXCTypeGroup fromTypeGroup = manager.getUnitTypeGroup(fromType.getTypeGroupId());
+ UnitXCTypeGroup toTypeGroup = manager.getUnitTypeGroup(toType.getTypeGroupId());
+
+ boolean fromTypeBase = fromTypeGroup.getBaseTypeId().equals(fromType.getId());
+ if (!fromTypeBase) {
+ value = runConverter(resultSteps,fromType, value, true);
+ }
+ boolean toTypeBase = toTypeGroup.getBaseTypeId().equals(toType.getId());
+ if (!toTypeBase) {
+ value = runConverter(resultSteps, toType, value, false);
+ }
+
+
+ long convertTime = System.currentTimeMillis()-startTime;
+ UnitXConverterResultModel result = new UnitXConverterResultModel(startValue,value,resultSteps,convertTime, fromType, toType);
+ return result;
+ }
+
+ private double runConverter(List resultSteps,UnitXCTypeModel type,double value,boolean toBase) {
+ double valueOld = value;
+ List steps = toBase?type.getToBaseConverterSteps():type.getFromBaseConverterSteps();
+ for (UnitXConverterStep step:steps) {
+ valueOld = value;
+ long startTime = System.currentTimeMillis();
+ value = step.convert(value);
+ value = runRounding(resultSteps,value,valueOld);
+ long convertTime = System.currentTimeMillis()-startTime;
+ resultSteps.add(new UnitXConverterResultStepModel(step.getName()+(toBase?"-toBase":"-fromBase")+" = "+step.getMathExpression(),valueOld,value,convertTime));
+ }
+ return value;
+ }
+
+ private double runRounding(List resultSteps,double value,double valueOrg) {
+ long startTime = System.currentTimeMillis();
+ String valueStr = Double.toString(value);
+ String valueOrgStr = Double.toString(valueOrg);
+ int valueDotIndex = valueStr.indexOf(".");
+ int valueOrgDotIndex = valueOrgStr.indexOf(".");
+ int valueDotSize = valueStr.length() - valueDotIndex;
+ int valueOrgDotSize = valueOrgStr.length() - valueOrgDotIndex;
+
+ if (valueDotSize<10) {
+ return value;
+ }
+ if (valueDotSize<=valueOrgDotSize) {
+ return value;
+ }
+ int valueEIndex = valueStr.indexOf("E");
+ String valueShortStr = null;
+ if (valueEIndex>0) {
+ int sub = valueOrgStr.length();
+ if (sub > valueEIndex) {
+ sub = valueEIndex;
+ }
+ valueShortStr = valueStr.substring(0, sub)+ valueStr.substring(valueEIndex);
+ } else {
+ valueShortStr = valueStr.substring(0, valueOrgStr.length());
+ }
+ Double result = new Double(valueShortStr);
+ long roundTime = System.currentTimeMillis()-startTime;
+
+ resultSteps.add(new UnitXConverterResultStepModel("rouding",value,result,roundTime));
+
+ return result.doubleValue();
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/package-info.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/package-info.java
index 78ad825..e80f2f3 100644
--- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/package-info.java
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/package-info.java
@@ -1,5 +1,24 @@
-/**
- *
+/*
+ * 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.
*/
/**
* @author willemc
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/AbstractUnitXConverterStep.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/AbstractUnitXConverterStep.java
new file mode 100644
index 0000000..9080f24
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/AbstractUnitXConverterStep.java
@@ -0,0 +1,39 @@
+/*
+ * 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.converter.step;
+
+import org.apache.commons.lang3.Validate;
+
+public abstract class AbstractUnitXConverterStep implements UnitXConverterStep {
+
+ private final String name;
+
+ protected AbstractUnitXConverterStep(String name) {
+ this.name = Validate.notBlank(name);
+ }
+
+ public final String getName() {
+ return name;
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXCTypeDevideConverterStep.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXCTypeDevideConverterStep.java
new file mode 100644
index 0000000..6376375
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXCTypeDevideConverterStep.java
@@ -0,0 +1,48 @@
+/*
+ * 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.converter.step;
+
+import org.apache.commons.lang3.Validate;
+
+public class UnitXCTypeDevideConverterStep extends AbstractUnitXConverterStep {
+
+ private final static String STEP_NAME = "Devide";
+ private final double factor;
+
+ public UnitXCTypeDevideConverterStep(double factor) {
+ super(STEP_NAME);
+ this.factor = factor;
+ Validate.isTrue(factor != 0);
+ }
+
+ @Override
+ public double convert(double value) {
+ return value/factor;
+ }
+
+ @Override
+ public String getMathExpression() {
+ return "/"+factor;
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXCTypeExponentConverterStep.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXCTypeExponentConverterStep.java
new file mode 100644
index 0000000..bc4edd4
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXCTypeExponentConverterStep.java
@@ -0,0 +1,68 @@
+/*
+ * 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.converter.step;
+
+public class UnitXCTypeExponentConverterStep extends AbstractUnitXConverterStep {
+
+ private final static String STEP_NAME = "Exponent";
+ private final int factor;
+ private final int factorShift;
+ private final boolean factorReverse;
+
+ public UnitXCTypeExponentConverterStep(int factor,boolean factorReverse) {
+ super(factor+STEP_NAME);
+ this.factor = factor;
+ this.factorReverse = factorReverse;
+ this.factorShift = factor<0?0-factor:factor;
+ }
+
+ @Override
+ public String getMathExpression() {
+ return "*10^"+factor;
+ }
+
+ @Override
+ public double convert(double value) {
+ for (int i=0;i0):factor>0);
+ }
+ return value;
+ }
+
+ private double shiftDotStatic(double value,boolean up) {
+ String valueStr = ""+value;
+ int dotIdx = valueStr.indexOf('.');
+ StringBuilder buf = new StringBuilder();
+ buf.append(valueStr);
+ buf.deleteCharAt(dotIdx);
+ if (up) {
+ buf.insert(dotIdx+1, '.');
+ } else {
+ buf.insert(dotIdx-1, '.');
+ }
+
+ Double result = new Double(buf.toString());
+ return result.doubleValue();
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXCTypeMultiplyConverterStep.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXCTypeMultiplyConverterStep.java
new file mode 100644
index 0000000..1be60be
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXCTypeMultiplyConverterStep.java
@@ -0,0 +1,45 @@
+/*
+ * 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.converter.step;
+
+public class UnitXCTypeMultiplyConverterStep extends AbstractUnitXConverterStep {
+
+ private final static String STEP_NAME = "Factor Converter";
+ private final double factor;
+
+ public UnitXCTypeMultiplyConverterStep(double factor) {
+ super(STEP_NAME);
+ this.factor = factor;
+ }
+
+ @Override
+ public double convert(double value) {
+ return value*factor;
+ }
+
+ @Override
+ public String getMathExpression() {
+ return "*"+factor;
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXCTypeMultiplyFractionConverterStep.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXCTypeMultiplyFractionConverterStep.java
new file mode 100644
index 0000000..3b42c5f
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXCTypeMultiplyFractionConverterStep.java
@@ -0,0 +1,47 @@
+/*
+ * 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.converter.step;
+
+public class UnitXCTypeMultiplyFractionConverterStep extends AbstractUnitXConverterStep {
+
+ private final static String STEP_NAME = "FactorFaction";
+ private final int numerator;
+ private final int denominator;
+
+ public UnitXCTypeMultiplyFractionConverterStep(int numerator,int denominator) {
+ super(STEP_NAME);
+ this.numerator = numerator;
+ this.denominator = denominator;
+ }
+
+ @Override
+ public double convert(double value) {
+ return value*((double)numerator/(double)denominator);
+ }
+
+ @Override
+ public String getMathExpression() {
+ return "*("+numerator+"/"+denominator+")";
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXCTypeOffsetConverterStep.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXCTypeOffsetConverterStep.java
new file mode 100644
index 0000000..f31de73
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXCTypeOffsetConverterStep.java
@@ -0,0 +1,55 @@
+/*
+ * 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.converter.step;
+
+public class UnitXCTypeOffsetConverterStep extends AbstractUnitXConverterStep {
+
+ private final static String STEP_NAME = "Offset";
+ private final double offset;
+ private final boolean offsetPositive;
+
+ public UnitXCTypeOffsetConverterStep(double offset,boolean offsetPositive) {
+ super(STEP_NAME);
+ this.offset = offset;
+ this.offsetPositive = offsetPositive;
+ }
+
+ @Override
+ public double convert(double value) {
+ if (offsetPositive) {
+ return value+offset;
+ } else {
+ return value-offset;
+ }
+ }
+
+ @Override
+ public String getMathExpression() {
+ if (offsetPositive) {
+ return "+"+offset;
+ } else {
+ return "-"+offset;
+ }
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXConverterStep.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXConverterStep.java
new file mode 100644
index 0000000..40f5acb
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/UnitXConverterStep.java
@@ -0,0 +1,33 @@
+/*
+ * 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.converter.step;
+
+public interface UnitXConverterStep {
+
+ String getName();
+
+ String getMathExpression();
+
+ double convert(double value);
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/package-info.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/package-info.java
new file mode 100644
index 0000000..e4ac9d8
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/converter/step/package-info.java
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+/**
+ * @author willemc
+ *
+ */
+package net.forwardfire.unitxc.converter.step;
\ No newline at end of file
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCType.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCType.java
new file mode 100644
index 0000000..a21e96b
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCType.java
@@ -0,0 +1,37 @@
+/*
+ * 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.model;
+
+import java.util.Collection;
+
+public interface UnitXCType {
+
+ String getId();
+
+ String getName();
+
+ String getTypeGroupId();
+
+ Collection getTypeFlags();
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCTypeGroup.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCTypeGroup.java
new file mode 100644
index 0000000..aa00418
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCTypeGroup.java
@@ -0,0 +1,35 @@
+/*
+ * 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.model;
+
+public interface UnitXCTypeGroup {
+
+ String getId();
+
+ String getName();
+
+ String getDescription();
+
+ String getBaseTypeId();
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCTypeGroupModel.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCTypeGroupModel.java
new file mode 100644
index 0000000..53d9660
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCTypeGroupModel.java
@@ -0,0 +1,108 @@
+/*
+ * 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.model;
+
+import org.apache.commons.lang3.Validate;
+
+public class UnitXCTypeGroupModel implements UnitXCTypeGroup {
+
+ private String id;
+ private String name;
+ private String description;
+ private String baseTypeId;
+
+ public UnitXCTypeGroupModel() {
+ }
+
+ public UnitXCTypeGroupModel(String id,String name,String description,String baseTypeId) {
+ setId(id);
+ setName(name);
+ setDescription(description);
+ setBaseTypeId(baseTypeId);
+ }
+
+ public UnitXCTypeGroupModel validate() {
+ Validate.notBlank(id);
+ Validate.notBlank(name);
+ Validate.notBlank(description);
+ Validate.notBlank(baseTypeId);
+ return this;
+ }
+
+ /**
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @param description the description to set
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * @return the baseTypeId
+ */
+ public String getBaseTypeId() {
+ return baseTypeId;
+ }
+
+ /**
+ * @param baseTypeId the baseTypeId to set
+ */
+ public void setBaseTypeId(String baseTypeId) {
+ this.baseTypeId = baseTypeId;
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCTypeModel.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCTypeModel.java
new file mode 100644
index 0000000..d5fbf31
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCTypeModel.java
@@ -0,0 +1,122 @@
+/*
+ * 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.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.lang3.Validate;
+
+import net.forwardfire.unitxc.converter.step.UnitXConverterStep;
+
+public class UnitXCTypeModel implements UnitXCType {
+
+ private String id;
+ private String name;
+ private String typeGroupId;
+ private final List toBaseConverterSteps;
+ private final List fromBaseConverterSteps;
+ private final List typeFlags;
+
+ public UnitXCTypeModel() {
+ typeFlags = new ArrayList<>();
+ toBaseConverterSteps = new ArrayList<>();
+ fromBaseConverterSteps = new ArrayList<>();
+ }
+
+ public UnitXCTypeModel validate() {
+ Validate.notBlank(id);
+ Validate.notBlank(name);
+ Validate.notBlank(typeGroupId);
+ return this;
+ }
+
+ /**
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the typeGroupId
+ */
+ public String getTypeGroupId() {
+ return typeGroupId;
+ }
+
+ /**
+ * @param typeGroupId the typeGroupId to set
+ */
+ public void setTypeGroupId(String typeGroupId) {
+ this.typeGroupId = typeGroupId;
+ }
+
+ public List getToBaseConverterSteps() {
+ return toBaseConverterSteps;
+ }
+
+ public void addToBaseConverterStep(UnitXConverterStep unitTypeConverter) {
+ toBaseConverterSteps.add(Validate.notNull(unitTypeConverter));
+ }
+
+ public List getFromBaseConverterSteps() {
+ return fromBaseConverterSteps;
+ }
+
+ public void addFromBaseConverterStep(UnitXConverterStep unitTypeConverter) {
+ fromBaseConverterSteps.add(Validate.notNull(unitTypeConverter));
+ }
+
+ @Override
+ public Collection getTypeFlags() {
+ return typeFlags;
+ }
+
+ public void addTypeFlag(String flag) {
+ typeFlags.add(flag);
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResult.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResult.java
new file mode 100644
index 0000000..7134852
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResult.java
@@ -0,0 +1,41 @@
+/*
+ * 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.model;
+
+import java.util.List;
+
+public interface UnitXConverterResult {
+
+ Double getStartValue();
+
+ UnitXCType getStartType();
+
+ Double getResultValue();
+
+ UnitXCType getResultType();
+
+ List getSteps();
+
+ Long getConvertTime();
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResultModel.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResultModel.java
new file mode 100644
index 0000000..0427f07
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResultModel.java
@@ -0,0 +1,77 @@
+/*
+ * 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.model;
+
+import java.util.List;
+
+import org.apache.commons.lang3.Validate;
+
+public class UnitXConverterResultModel implements UnitXConverterResult {
+
+ private final Double startValue;
+ private final List resultSteps;
+ private final Double resultValue;
+ private final Long convertTime;
+ private final UnitXCType startType;
+ private final UnitXCType resultType;
+
+ public UnitXConverterResultModel(Double startValue,Double resultValue,List resultSteps,Long convertTime,UnitXCType startType,UnitXCType resultType) {
+ this.startValue = Validate.notNull(startValue);
+ this.resultSteps = Validate.noNullElements(resultSteps);
+ this.resultValue = Validate.notNull(resultValue);
+ this.convertTime = convertTime;
+ this.startType = Validate.notNull(startType);
+ this.resultType = Validate.notNull(resultType);
+ }
+
+ @Override
+ public Double getStartValue() {
+ return startValue;
+ }
+
+ @Override
+ public Double getResultValue() {
+ return resultValue;
+ }
+
+ @Override
+ public List getSteps() {
+ return resultSteps;
+ }
+
+ @Override
+ public Long getConvertTime() {
+ return convertTime;
+ }
+
+ @Override
+ public UnitXCType getStartType() {
+ return startType;
+ }
+
+ @Override
+ public UnitXCType getResultType() {
+ return resultType;
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResultStep.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResultStep.java
new file mode 100644
index 0000000..40b3806
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResultStep.java
@@ -0,0 +1,35 @@
+/*
+ * 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.model;
+
+public interface UnitXConverterResultStep {
+
+ String getName();
+
+ Double getInputValue();
+
+ Double getOutputValue();
+
+ Long getConvertTime();
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResultStepModel.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResultStepModel.java
new file mode 100644
index 0000000..abd4b57
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXConverterResultStepModel.java
@@ -0,0 +1,61 @@
+/*
+ * 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.model;
+
+import org.apache.commons.lang3.Validate;
+
+public class UnitXConverterResultStepModel implements UnitXConverterResultStep {
+
+ private final String name;
+ private final Double inputValue;
+ private final Double outputValue;
+ private final Long convertTime;
+
+ public UnitXConverterResultStepModel(String name,Double inputValue,Double outputValue,Long convertTime) {
+ this.name = Validate.notBlank(name);
+ this.inputValue = Validate.notNull(inputValue);
+ this.outputValue = Validate.notNull(outputValue);
+ this.convertTime = Validate.notNull(convertTime);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Double getInputValue() {
+ return inputValue;
+ }
+
+ @Override
+ public Double getOutputValue() {
+ return outputValue;
+ }
+
+ @Override
+ public Long getConvertTime() {
+ return convertTime;
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/package-info.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/package-info.java
new file mode 100644
index 0000000..08dc542
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/package-info.java
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+/**
+ * @author willemc
+ *
+ */
+package net.forwardfire.unitxc.model;
\ No newline at end of file
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/UnitXCElectricCurrentModule.java
new file mode 100644
index 0000000..da04f45
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCElectricCurrentModule.java
@@ -0,0 +1,42 @@
+/*
+ * 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.UnitXCConfigModuleBuilder;
+
+public class UnitXCElectricCurrentModule 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.";
+ public static final String TYPE_AMPERE_ID = "A";
+ public static final String TYPE_AMPERE_NAME = "ampere";
+ public static final String TYPE_AMPERE_FLAG = (GROUP_ID+"_"+TYPE_AMPERE_NAME).toUpperCase();
+
+ @Override
+ public void configModule(UnitXCConfigModuleBuilder builder) {
+ builder.addUnitTypeGroup( GROUP_ID, TYPE_AMPERE_ID, TYPE_AMPERE_NAME, GROUP_DESCRIPTION );
+ builder.addSIMultiples( GROUP_ID, TYPE_AMPERE_ID, TYPE_AMPERE_NAME, TYPE_AMPERE_FLAG );
+ }
+}
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/UnitXCTemperatureModule.java
new file mode 100644
index 0000000..918c684
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCTemperatureModule.java
@@ -0,0 +1,88 @@
+/*
+ * 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.UnitXCConfigBuildTypeMultiples;
+import net.forwardfire.unitxc.config.UnitXCConfigModule;
+import net.forwardfire.unitxc.config.UnitXCConfigModuleBuilder;
+import net.forwardfire.unitxc.converter.step.UnitXConverterStep;
+import static net.forwardfire.unitxc.UnitXCFactory.MathStep.add;
+import static net.forwardfire.unitxc.UnitXCFactory.MathStep.substract;
+import static net.forwardfire.unitxc.UnitXCFactory.MathStep.multiplyFraction;
+
+public class UnitXCTemperatureModule 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.";
+
+ public static final String TYPE_KELVIN_ID = "K";
+ public static final String TYPE_KELVIN_NAME = "kelvin";
+ public static final String TYPE_KELVIN_FLAG = (GROUP_ID+"_"+TYPE_KELVIN_NAME).toUpperCase();
+
+ public static final String TYPE_CELSIUS_ID = "°C";
+ public static final String TYPE_CELSIUS_NAME = "celsius";
+ public static final String TYPE_CELSIUS_FLAG = (GROUP_ID+"_"+TYPE_CELSIUS_NAME).toUpperCase();
+ private static final UnitXCConfigBuildTypeMultiples TYPE_CELSIUS_CONFIG = new UnitXCConfigBuildTypeMultiples(
+ TYPE_CELSIUS_ID,TYPE_CELSIUS_NAME,TYPE_CELSIUS_FLAG,
+ new UnitXConverterStep[]{add(273.15)},
+ new UnitXConverterStep[]{substract(273.15)}
+ );
+
+ public static final String TYPE_FAHRENHEIT_ID = "°F";
+ public static final String TYPE_FAHRENHEIT_NAME = "fahrenheit";
+ public static final String TYPE_FAHRENHEIT_FLAG = (GROUP_ID+"_"+TYPE_FAHRENHEIT_NAME).toUpperCase();
+ private static final UnitXCConfigBuildTypeMultiples TYPE_FAHRENHEIT_CONFIG = new UnitXCConfigBuildTypeMultiples(
+ TYPE_FAHRENHEIT_ID,TYPE_FAHRENHEIT_NAME,TYPE_FAHRENHEIT_FLAG,
+ new UnitXConverterStep[]{add(459.67),multiplyFraction(5,9)},
+ new UnitXConverterStep[]{multiplyFraction(9,5),substract(459.67)}
+ );
+
+ public static final String TYPE_RANKINE_ID = "°R";
+ public static final String TYPE_RANKINE_NAME = "rankine";
+ public static final String TYPE_RANKINE_FLAG = (GROUP_ID+"_"+TYPE_RANKINE_NAME).toUpperCase();
+ private static final UnitXCConfigBuildTypeMultiples TYPE_RANKINE_CONFIG = new UnitXCConfigBuildTypeMultiples(
+ TYPE_RANKINE_ID,TYPE_RANKINE_NAME,TYPE_RANKINE_FLAG,
+ new UnitXConverterStep[]{multiplyFraction(5,9)},
+ new UnitXConverterStep[]{multiplyFraction(9,5)}
+ );
+
+ public static final String TYPE_ROMER_ID = "Rø";
+ public static final String TYPE_ROMER_NAME = "rømer";
+ public static final String TYPE_ROMER_FLAG = GROUP_ID.toUpperCase()+"_ROMER";
+ private static final UnitXCConfigBuildTypeMultiples TYPE_ROMER_CONFIG = new UnitXCConfigBuildTypeMultiples(
+ TYPE_ROMER_ID,TYPE_ROMER_NAME,TYPE_ROMER_FLAG,
+ new UnitXConverterStep[]{add(273.15),multiplyFraction(40,21),add(7.5)},
+ new UnitXConverterStep[]{substract(7.5),multiplyFraction(21,40),substract(273.15)}
+ );
+
+ @Override
+ public void configModule(UnitXCConfigModuleBuilder builder) {
+ builder.addUnitTypeGroup( GROUP_ID, TYPE_KELVIN_ID, TYPE_KELVIN_NAME, GROUP_DESCRIPTION);
+ builder.addSIMultiples( GROUP_ID, TYPE_KELVIN_ID, TYPE_KELVIN_NAME, TYPE_KELVIN_FLAG);
+ builder.addSIMultiplesSilly(GROUP_ID, TYPE_CELSIUS_CONFIG);
+ builder.addSIMultiplesSilly(GROUP_ID, TYPE_FAHRENHEIT_CONFIG);
+ builder.addSIMultiplesSilly(GROUP_ID, TYPE_RANKINE_CONFIG);
+ builder.addSIMultiplesSilly(GROUP_ID, TYPE_ROMER_CONFIG);
+ }
+}
diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/package-info.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/package-info.java
new file mode 100644
index 0000000..f4ea756
--- /dev/null
+++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/package-info.java
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+/**
+ * @author willemc
+ *
+ */
+package net.forwardfire.unitxc.module;
\ No newline at end of file
diff --git a/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/UnitXCAssert.java b/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/UnitXCAssert.java
new file mode 100644
index 0000000..2d83385
--- /dev/null
+++ b/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/UnitXCAssert.java
@@ -0,0 +1,49 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
+
+import net.forwardfire.unitxc.UnitXCFactory;
+import net.forwardfire.unitxc.converter.UnitXConverter;
+
+public class UnitXCAssert {
+
+ private static final UnitXConverter DEFAULT_CONVERTER = UnitXCFactory.createManager().getConverter();
+ private static final double DEFAULT_VALUE_DELTA = 0;
+
+ public static void convertEquals(double expected,String toType,double fromValue,String fromType) {
+ convertEquals(DEFAULT_CONVERTER,expected, toType, fromValue, fromType);
+ }
+
+ public static void convertEquals(UnitXConverter converter,double expected,String toType,double fromValue,String fromType) {
+ convertEquals(converter, expected, toType, fromValue, fromType, DEFAULT_VALUE_DELTA);
+ }
+
+ public static void convertEquals(UnitXConverter converter,double expected,String toType,double fromValue,String fromType,double valueDelta) {
+ assertNotNull(converter);
+ assertEquals(expected,converter.convert(fromValue, fromType, toType),valueDelta);
+ }
+}
diff --git a/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/UnitXCFactoryTest.java b/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/UnitXCFactoryTest.java
new file mode 100644
index 0000000..b100347
--- /dev/null
+++ b/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/UnitXCFactoryTest.java
@@ -0,0 +1,42 @@
+package net.forwardfire.unitxc;
+
+import org.junit.Test;
+
+import net.forwardfire.unitxc.config.UnitXCConfig;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+
+public class UnitXCFactoryTest {
+
+ @Test
+ public void testCreateConfig() {
+ assertNotNull(UnitXCFactory.createConfig());
+ }
+
+ @Test
+ public void testCreateConfigList() {
+ assertNotNull(UnitXCFactory.createConfig(new ArrayList<>()));
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void testCreateConfigListNull() {
+ assertNotNull(UnitXCFactory.createConfig(null));
+ }
+
+ @Test
+ public void testCreateManager() {
+ assertNotNull(UnitXCFactory.createManager());
+ }
+
+ @Test
+ public void testCreateManagerConfig() {
+ assertNotNull(UnitXCFactory.createManager(new UnitXCConfig()));
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void testCreateManagerConfigNull() {
+ assertNotNull(UnitXCFactory.createManager(null));
+ }
+}
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
new file mode 100644
index 0000000..999bfb3
--- /dev/null
+++ b/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/module/UnitXCTemperatureModuleTest.java
@@ -0,0 +1,116 @@
+/*
+ * 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 static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertEquals;
+
+import static net.forwardfire.unitxc.UnitXCAssert.convertEquals;
+
+import net.forwardfire.unitxc.UnitXCFactory;
+import net.forwardfire.unitxc.UnitXCManager;
+import net.forwardfire.unitxc.converter.UnitXConverter;
+import net.forwardfire.unitxc.model.UnitXCType;
+import net.forwardfire.unitxc.model.UnitXConverterResult;
+import net.forwardfire.unitxc.model.UnitXConverterResultStep;
+
+public class UnitXCTemperatureModuleTest {
+
+ private final UnitXConverter um;
+ private final double VALUE_DELTA = 0;
+
+ public UnitXCTemperatureModuleTest() {
+ um = UnitXCFactory.createManager().getConverter();
+ }
+
+ @Test
+ public void testFac() {
+ UnitXCManager unitManager = UnitXCFactory.createManager();
+
+ assertNotNull(unitManager);
+ assertNotNull(unitManager.getUnitTypes());
+ assertNotNull(unitManager.getUnitTypeGroups());
+ assertFalse(unitManager.getUnitTypes().isEmpty());
+ assertFalse(unitManager.getUnitTypeGroups().isEmpty());
+
+ assertNotNull(unitManager.getUnitTypes());
+
+ for (UnitXCType type:unitManager.getUnitTypes()) {
+ System.out.println("type: "+type.getId()+"\t name: "+type.getName()+"\t\t flags: "+type.getTypeFlags());
+ }
+ System.out.println("totalTypes: "+unitManager.getUnitTypes().size());
+
+ UnitXConverterResult result = um.convertStepped(211.0, "k°F", "m°C");
+ System.out.println("Convert from: "+result.getStartType().getName()+" to: "+result.getResultType().getName());
+ System.out.println("startValue: "+result.getStartValue());
+ System.out.println("resultValue: "+result.getResultValue());
+ System.out.println("convertTime: "+result.getConvertTime());
+ for (UnitXConverterResultStep step:result.getSteps()) {
+ System.out.println("step: "+step.getName()+" in: "+step.getInputValue()+" out: "+step.getOutputValue()+" time: "+step.getConvertTime());
+ }
+
+ System.out.println("");
+
+ result = um.convertStepped(100.0, "K", "°C");
+ System.out.println("Convert from: "+result.getStartType().getName()+" to: "+result.getResultType().getName());
+ System.out.println("startValue: "+result.getStartValue());
+ System.out.println("resultValue: "+result.getResultValue());
+ System.out.println("convertTime: "+result.getConvertTime());
+ for (UnitXConverterResultStep step:result.getSteps()) {
+ System.out.println("step: "+step.getName()+" in: "+step.getInputValue()+" out: "+step.getOutputValue()+" time: "+step.getConvertTime());
+ }
+ }
+
+ @Test
+ public void testConverterTempKvsC() throws Exception {
+ assertEquals(26.85,um.convert(300.0, "K", "°C"),VALUE_DELTA);
+ assertEquals(310.65,um.convert(37.5, "°C", "K"),VALUE_DELTA);
+ }
+
+ @Test
+ public void testConverterTempKvsF() throws Exception {
+ assertEquals(80.32,um.convert(300.0, "K", "°F"),VALUE_DELTA);
+ assertEquals(276.2,um.convert(37.5, "°F", "K"),VALUE_DELTA);
+ assertEquals(276.208,um.convert(37.505, "°F", "K"),VALUE_DELTA);
+ }
+
+ @Test
+ public void testConverterTempFvsC() throws Exception {
+ //assertEquals(74.937,um.convert(166.888, "°F", "°C"),VALUE_DELTA);
+ //assertEquals(211.99,um.convert(100.0, "°C", "°F"),VALUE_DELTA);
+ convertEquals(74.937,"°C",166.888, "°F");
+ convertEquals(211.99,"°F",100.0, "°C");
+ }
+
+ @Test
+ public void testConverterTempRvsC() throws Exception {
+ convertEquals(-143.64,"°C",233.12,"°R");
+ convertEquals(1691.06,"°R",666.333,"°C");
+ }
+}