diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/UnitXCFactory.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/UnitXCFactory.java index e55d34b..8e0fe4e 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/UnitXCFactory.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/UnitXCFactory.java @@ -79,7 +79,7 @@ public final class UnitXCFactory { new UnitXCModuleJounce(), // named - //new UnitXCModuleNewton(), + new UnitXCModuleNewton(), // more derived new UnitXCModuleAreaDensity(), 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 index 89303db..2407312 100644 --- 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 @@ -57,7 +57,6 @@ public class UnitXCConfigManager implements UnitXCManager { private static Map createUnitGroups(Collection values) { Map result = new HashMap<>(); values.forEach((value) -> { - value.setTotalUnitTypes(value.getTypeGenerator().size()); result.put(value.getId(), value); }); return result; @@ -72,7 +71,7 @@ public class UnitXCConfigManager implements UnitXCManager { public UnitXCType getUnitType(String id) { UnitXCType result = null; for (UnitXCGroup group:unitGroups.values()) { - result = group.getTypeGenerator().getUnitType(id); + result = group.getUnitType(id); if (result != null) { break; } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCGroupBuilder.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCGroupBuilder.java new file mode 100644 index 0000000..673d7c9 --- /dev/null +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCGroupBuilder.java @@ -0,0 +1,70 @@ +/* + * 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.builder; + +import java.util.function.BiConsumer; + +import net.forwardfire.unitxc.model.AbstractUnitXCGroup; +import net.forwardfire.unitxc.model.DefaultUnitXCType; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 28, 2016 + */ +abstract public class AbstractUnitXCGroupBuilder extends AbstractUnitXCBuilder { + + public AbstractUnitXCGroupBuilder(P parent, T model, BiConsumer parentBuilder) { + super(parent, model, parentBuilder); + } + + public UnitXCGroupJumpBuilder> createGroupJump(String unitGroupId) { + return new UnitXCGroupJumpBuilder<>(this,getValue(),unitGroupId,(p,v) -> p.getValue().addGroupJump(v)); + } + + public UnitXCTypeBuilder> createUnitType() { + return new UnitXCTypeBuilder<>(this,new DefaultUnitXCType(),(p,v) -> p.getValue().addUnitType(v)); + } + + public B setId(String id) { + return make((v) -> v.setId(id)); + } + + public B setName(String name) { + return make((v) -> v.setName(name)); + } + + public B setDescription(String description) { + return make((v) -> v.setDescription(description)); + } + + public B setBaseTypeId(String baseTypeId) { + return make((v) -> v.setBaseTypeId(baseTypeId)); + } + +// public B addDerivedFrom(String fromId) { +// return make((v) -> v.addDerivedFrom(fromId)); +// } +} diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCTypeBuilder.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCTypeBuilder.java index 995fa53..e1fd4b0 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCTypeBuilder.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/AbstractUnitXCTypeBuilder.java @@ -28,6 +28,7 @@ import java.util.Collection; import java.util.List; import java.util.function.BiConsumer; +import net.forwardfire.unitxc.model.DefaultUnitXCType; import net.forwardfire.unitxc.model.UnitXCType; import net.forwardfire.unitxc.model.step.UnitXConverterStep; @@ -37,13 +38,14 @@ import net.forwardfire.unitxc.model.step.UnitXConverterStep; * @author Willem Cazander * @version 1.0 Oct 22, 2015 */ -public abstract class AbstractUnitXCTypeBuilder extends AbstractUnitXCBuilder { +public abstract class AbstractUnitXCTypeBuilder extends AbstractUnitXCBuilder { - public AbstractUnitXCTypeBuilder(P parent,UnitXCType model,BiConsumer parentBuilder) { + public AbstractUnitXCTypeBuilder(P parent,DefaultUnitXCType model,BiConsumer parentBuilder) { super(parent, model, parentBuilder); } - protected final void buildPreValue(UnitXCType value) { + @Override + protected final void buildPreValue(DefaultUnitXCType value) { if (value.getNamePlural() == null) { setNamePlurals(); } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCConfigBuilder.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCConfigBuilder.java index 9e71916..7449d48 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCConfigBuilder.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCConfigBuilder.java @@ -25,9 +25,12 @@ package net.forwardfire.unitxc.config.builder; import org.apache.commons.lang3.Validate; +import net.forwardfire.unitxc.model.AbstractUnitXCGroup; import net.forwardfire.unitxc.model.UnitXCConfig; import net.forwardfire.unitxc.model.UnitXCGroup; -import net.forwardfire.unitxc.model.UnitXCType; +import net.forwardfire.unitxc.model.UnitXCGroupBase; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundExponent; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; /** * @@ -51,18 +54,21 @@ public class UnitXCConfigBuilder { return config; } - public UnitXCGroupBuilder createUnitGroup() { - return new UnitXCGroupBuilder(this, new UnitXCGroup(), (p,v) -> p.getConfig().addUnitGroup(v)); + public UnitXCGroupBaseBuilder createUnitGroupBase() { + return new UnitXCGroupBaseBuilder(this, new UnitXCGroupBase(), (p,v) -> p.getConfig().addUnitGroup(v)); } - public UnitXCGroupBuilder extendUnitGroup(String groupId) { - UnitXCGroup group = findGroup(groupId); - return new UnitXCGroupBuilder(this, group, (p,v) -> {}); + public UnitXCGroupCompoundPairBuilder createUnitGroupCompoundPair(String parentGroupId, String parentPerGroupId) { + return new UnitXCGroupCompoundPairBuilder(this, new UnitXCGroupCompoundPair(findGroup(parentGroupId),findGroup(parentPerGroupId)), (p,v) -> p.getConfig().addUnitGroup(v)); } - public UnitXCTypeBuilder createUnitType(String groupId) { + public UnitXCGroupCompoundExponentBuilder createUnitGroupCompoundExponent(String parentGroupId, int exponent) { + return new UnitXCGroupCompoundExponentBuilder(this, new UnitXCGroupCompoundExponent(findGroup(parentGroupId),exponent), (p,v) -> p.getConfig().addUnitGroup(v)); + } + + public UnitXCGroupExtendBuilder extendUnitGroup(String groupId) { UnitXCGroup group = findGroup(groupId); - return new UnitXCTypeBuilder<>(this,new UnitXCType(),(p,v) -> group.addUnitType(v)); + return new UnitXCGroupExtendBuilder(this, AbstractUnitXCGroup.class.cast(group), (p,v) -> {}); } private UnitXCGroup findGroup(String id) { @@ -74,17 +80,4 @@ public class UnitXCConfigBuilder { } throw new IllegalArgumentException("Could not find: "+id); } - -// private UnitXCType findType(String id) { -// for (UnitXCType m:config.getUnitTypes()) { -// if (m.getId().equals(id)) { -// return m; -// } -// } -// throw new IllegalArgumentException("Could not find: "+id); -// } -// -// public UnitXCTypeBuilder extendUnitType(String id) { -// return new UnitXCTypeBuilder<>(this,findType(id),(p,v) -> {}); -// } } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupBaseBuilder.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupBaseBuilder.java new file mode 100644 index 0000000..01a3237 --- /dev/null +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupBaseBuilder.java @@ -0,0 +1,50 @@ +/* + * 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.builder; + +import java.util.function.BiConsumer; + +import net.forwardfire.unitxc.model.UnitXCGroupBase; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 22, 2015 + */ +public class UnitXCGroupBaseBuilder extends AbstractUnitXCGroupBuilder { + + public UnitXCGroupBaseBuilder(UnitXCConfigBuilder parent, UnitXCGroupBase model, BiConsumer parentBuilder) { + super(parent, model, parentBuilder); + } + + @Override + protected UnitXCGroupBaseBuilder getBuilder() { + return this; + } + + public UnitXCTypeSIPrefixBuilder createSIUnitTypes() { + return new UnitXCTypeSIPrefixBuilder<>(this,this); + } +} diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupBuilder.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupBuilder.java deleted file mode 100644 index 743aea4..0000000 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupBuilder.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * 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.builder; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.function.BiConsumer; - -import net.forwardfire.unitxc.model.UnitXCGroup; -import net.forwardfire.unitxc.model.UnitXCGroupLevel; -import net.forwardfire.unitxc.model.UnitXCType; -import net.forwardfire.unitxc.model.UnitXCTypeGenerator; - -/** - * - * - * @author Willem Cazander - * @version 1.0 Oct 22, 2015 - */ -public class UnitXCGroupBuilder extends AbstractUnitXCBuilder { - - public UnitXCGroupBuilder(UnitXCConfigBuilder parent, UnitXCGroup model, BiConsumer parentBuilder) { - super(parent, model, parentBuilder); - if (model.getTypeGenerator() == null) { - model.setTypeGenerator(new UnitXCTypeGenerator() { - - @Override - public long size() { - return model.getUnitTypes().size(); - } - - @Override - public Iterator getUnitTypes() { - List result = new ArrayList<>(); - model.getUnitTypes().forEach(t -> result.add(t.getId())); - return result.iterator(); - } - - @Override - public UnitXCType getUnitType(String id) { - for (UnitXCType type:model.getUnitTypes()) { - if (type.getId().equals(id)) { - return type; - } - if (type.getName().equals(id)) { - return type; - } - } - return null; - } - }); - } - } - - @Override - protected UnitXCGroupBuilder getBuilder() { - return this; - } - - public UnitXCGroupJumpBuilder createGroupJump(String unitGroupId) { - return new UnitXCGroupJumpBuilder(getParent(),getValue(),unitGroupId); - } - - public UnitXCTypeBuilder createUnitType() { - return new UnitXCTypeBuilder<>(this,new UnitXCType(),(p,v) -> p.getValue().addUnitType(v)); - } - - public UnitXCTypeSIPrefixBuilder createSIUnitTypes() { - return new UnitXCTypeSIPrefixBuilder<>(this,this); - } - - public UnitXCTypeCompoundExponentBuilder createCompoundExponentUnitTypes(String unitTypeId, int exponent) { - return new UnitXCTypeCompoundExponentBuilder(this, unitTypeId, exponent); - } - - public UnitXCTypeCompoundPairBuilder createCompoundPairUnitTypes(String groupId,String perGroupId) { - return new UnitXCTypeCompoundPairBuilder(this,groupId,perGroupId); - } - - public UnitXCGroupBuilder setId(String id) { - return make((v) -> v.setId(id)); - } - - public UnitXCGroupBuilder setName(String name) { - return make((v) -> v.setName(name)); - } - - public UnitXCGroupBuilder setDescription(String description) { - return make((v) -> v.setDescription(description)); - } - - public UnitXCGroupBuilder setBaseTypeId(String baseTypeId) { - return make((v) -> v.setBaseTypeId(baseTypeId)); - } - - public UnitXCGroupBuilder setGroupLevel(UnitXCGroupLevel type) { - return make((v) -> v.setGroupLevel(type)); - } - -// public UnitXCGroupBuilder addDerivedFrom(String fromId) { -// return make((v) -> v.addDerivedFrom(fromId)); -// } -} diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupCompoundExponentBuilder.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupCompoundExponentBuilder.java new file mode 100644 index 0000000..a73bd0e --- /dev/null +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupCompoundExponentBuilder.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.config.builder; + +import java.util.function.BiConsumer; + +import net.forwardfire.unitxc.model.UnitXCGroupCompoundExponent; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 26, 2015 + */ +public class UnitXCGroupCompoundExponentBuilder extends AbstractUnitXCGroupBuilder { + + public UnitXCGroupCompoundExponentBuilder(UnitXCConfigBuilder parent, UnitXCGroupCompoundExponent model, BiConsumer parentBuilder) { + super(parent, model, parentBuilder); + } + + @Override + protected UnitXCGroupCompoundExponentBuilder getBuilder() { + return this; + } + + @Override + protected void buildPreValue(UnitXCGroupCompoundExponent value) { + // TODO: move + getValue().getDerivedFrom().add(getValue().getParentGroup().getId()); + } + + + public UnitXCGroupCompoundExponentBuilder setUnitIdPostfix(String unitIdPostfix) { + return make(v -> v.setUnitIdPostfix(unitIdPostfix)); + } + + public UnitXCGroupCompoundExponentBuilder setUnitNamePrefix(String unitNamePrefix) { + return make(v -> v.setUnitNamePrefix(unitNamePrefix)); + } +} diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupCompoundPairBuilder.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupCompoundPairBuilder.java new file mode 100644 index 0000000..361b101 --- /dev/null +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupCompoundPairBuilder.java @@ -0,0 +1,92 @@ +/* + * 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.builder; + +import java.util.function.BiConsumer; + +import net.forwardfire.unitxc.model.UnitXCGroup; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; +import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueNamedParameter; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 26, 2015 + */ +public class UnitXCGroupCompoundPairBuilder extends AbstractUnitXCGroupBuilder { + + public UnitXCGroupCompoundPairBuilder(UnitXCConfigBuilder parent, UnitXCGroupCompoundPair model, BiConsumer parentBuilder) { + super(parent, model, parentBuilder); + } + + @Override + protected UnitXCGroupCompoundPairBuilder getBuilder() { + return this; + } + + @Override + protected void buildPreValue(UnitXCGroupCompoundPair value) { + + UnitXCGroup group = getValue().getParentGroup(); + UnitXCGroup perGroup = getValue().getParentPerGroup(); + + // TODO: do once !! + // TODO: move + getValue().getDerivedFrom().add(group.getId()); + getValue().getDerivedFrom().add(perGroup.getId()); +// +// UnitXCGroupJump toGroupJump = new UnitXCGroupJump(); +// toGroupJump.setId("to_"+group.getId()); +// toGroupJump.setUnitGroup(group); +// toGroupJump.addJumpParameter(new UnitXCGroupJumpParameter("to_"+perGroup.getId(),"",perGroup.getId())); +// +// UnitXCGroupJump perGroupJump = new UnitXCGroupJump(); +// perGroupJump.setId("to_"+group.getId()); +// perGroupJump.setUnitGroup(group); + + //getValue().getGroupJumps().add(toGroupJump); // m/s -> m + //getValue().getGroupJumps().add(perGroupJump); // m/s -> h + + //group.getGroupJumps().add(toGroupJump); // m -> m/s + //perGroup.getGroupJumps().add(perGroupJump); // s -> m/s + + // m/s -> m + createGroupJump(group.getId()) + .addJumpParameter(value.getId()+"_"+perGroup.getId(),perGroup.getId()) + .createToGroupConverterSteps() + .multiply(new UnitXConverterStepValueNamedParameter(value.getId()+"_"+perGroup.getId())) + .build() + .build(); + + // m -> m/s + getParent().extendUnitGroup(group.getId()) + .createGroupJump(value.getId()) + .addJumpParameter(value.getId()+"_"+perGroup.getId(),perGroup.getId()) + .createToGroupConverterSteps() + .divide(new UnitXConverterStepValueNamedParameter(value.getId()+"_"+perGroup.getId())) + .build() + .build(); + } +} diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupExtendBuilder.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupExtendBuilder.java new file mode 100644 index 0000000..a7e0483 --- /dev/null +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupExtendBuilder.java @@ -0,0 +1,46 @@ +/* + * 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.builder; + +import java.util.function.BiConsumer; + +import net.forwardfire.unitxc.model.AbstractUnitXCGroup; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 28, 2016 + */ +public class UnitXCGroupExtendBuilder extends AbstractUnitXCGroupBuilder { + + public UnitXCGroupExtendBuilder(UnitXCConfigBuilder parent, AbstractUnitXCGroup model, BiConsumer parentBuilder) { + super(parent, model, parentBuilder); + } + + @Override + protected UnitXCGroupExtendBuilder getBuilder() { + return this; + } +} diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupJumpBuilder.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupJumpBuilder.java index 7709316..5207214 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupJumpBuilder.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCGroupJumpBuilder.java @@ -24,6 +24,8 @@ package net.forwardfire.unitxc.config.builder; +import java.util.function.BiConsumer; + import net.forwardfire.unitxc.model.UnitXCGroup; import net.forwardfire.unitxc.model.UnitXCGroupJump; import net.forwardfire.unitxc.model.UnitXCGroupJumpParameter; @@ -34,28 +36,28 @@ import net.forwardfire.unitxc.model.UnitXCGroupJumpParameter; * @author Willem Cazander * @version 1.0 Apr 1, 2016 */ -public class UnitXCGroupJumpBuilder extends AbstractUnitXCBuilder { +public class UnitXCGroupJumpBuilder

extends AbstractUnitXCBuilder> { - public UnitXCGroupJumpBuilder(UnitXCConfigBuilder parent, UnitXCGroup forGroup, String unitGroupId) { - super(parent, new UnitXCGroupJump(), (b,v) -> forGroup.getGroupJumps().add(v)); + public UnitXCGroupJumpBuilder(P parent, UnitXCGroup forGroup, String unitGroupId,BiConsumer parentBuilder) { + super(parent, new UnitXCGroupJump(), parentBuilder); getValue().setUnitGroupId(unitGroupId); getValue().setId(forGroup.getId()+"_"+unitGroupId); } @Override - protected UnitXCGroupJumpBuilder getBuilder() { + protected UnitXCGroupJumpBuilder

getBuilder() { return this; } - public UnitXCGroupJumpBuilder setId(String id) { + public UnitXCGroupJumpBuilder

setId(String id) { return make((v) -> v.setId(id)); } - public UnitXCGroupJumpBuilder addJumpParameter(String id,String unitGroupId) { + public UnitXCGroupJumpBuilder

addJumpParameter(String id,String unitGroupId) { return make((v) -> v.addJumpParameter(new UnitXCGroupJumpParameter(id, unitGroupId))); } - public UnitXConverterStepBuilder createToGroupConverterSteps() { + public UnitXConverterStepBuilder> createToGroupConverterSteps() { return new UnitXConverterStepBuilder<>(this,(p,v) -> getValue().getToGroupConverterSteps().addAll(v),() -> "group jump"); } } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeBuilder.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeBuilder.java index cf9dbca..579c73d 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeBuilder.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeBuilder.java @@ -25,7 +25,7 @@ package net.forwardfire.unitxc.config.builder; import java.util.function.BiConsumer; -import net.forwardfire.unitxc.model.UnitXCType; +import net.forwardfire.unitxc.model.DefaultUnitXCType; /** * @@ -35,7 +35,7 @@ import net.forwardfire.unitxc.model.UnitXCType; */ public class UnitXCTypeBuilder

extends AbstractUnitXCTypeBuilder> { - public UnitXCTypeBuilder(P parent,UnitXCType model, BiConsumer parentBuilder) { + public UnitXCTypeBuilder(P parent,DefaultUnitXCType model, BiConsumer parentBuilder) { super(parent,model, parentBuilder); } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeCompoundExponentBuilder.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeCompoundExponentBuilder.java deleted file mode 100644 index 1d0fefb..0000000 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeCompoundExponentBuilder.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * 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.builder; - -import java.util.Iterator; - -import org.apache.commons.lang3.Validate; - -import net.forwardfire.unitxc.model.UnitXCGroup; -import net.forwardfire.unitxc.model.UnitXCType; -import net.forwardfire.unitxc.model.UnitXCTypeGenerator; -import net.forwardfire.unitxc.model.step.UnitXCConverterStepReference; - -/** - * - * - * @author Willem Cazander - * @version 1.0 Oct 26, 2015 - */ -public class UnitXCTypeCompoundExponentBuilder extends AbstractUnitXCBuilder { - - private final String unitGroupId; - private final int exponent; - private String unitIdPostfix; - private String unitNamePrefix; - - public UnitXCTypeCompoundExponentBuilder(UnitXCGroupBuilder parent, String unitGroupId, int exponent) { - super(parent,new Object(), (p,v) -> {}); - this.unitGroupId = unitGroupId; - this.exponent = exponent; - UnitXCGroup model = parent.getValue(); - parent.getValue().setTypeGenerator(new UnitXCTypeGenerator() { - - UnitXCGroup getGroup() { - UnitXCGroup group = null; - for (UnitXCGroup unitGroup:getParent().getParent().getConfig().getUnitGroups()) { - if (unitGroup.getId().equals(unitGroupId)) { - group = unitGroup; - break; - } - } - return group; - } - - @Override - public long size() { - return getGroup().getTypeGenerator().size(); - } - - @Override - public Iterator getUnitTypes() { - Iterator g = getGroup().getTypeGenerator().getUnitTypes(); - return new Iterator() { - @Override - public boolean hasNext() { - return g.hasNext(); - } - @Override - public String next() { - return g.next()+unitIdPostfix; - } - }; - } - - public UnitXCType getUnitTypeAlias(String id) { - for (UnitXCType type:model.getUnitTypes()) { - if (type.getId().equals(id)) { - return type; - } - if (type.getName().equals(id)) { - return type; - } - } - return null; - } - - @Override - public UnitXCType getUnitType(String id) { - UnitXCType al = getUnitTypeAlias(id); - if (al != null) { - return al; - } - if (!id.endsWith(unitIdPostfix)) { - return null; - } - String idRaw = id.substring(0, id.length()-unitIdPostfix.length()); - UnitXCGroup group = getGroup(); - UnitXCType unitType = group.getTypeGenerator().getUnitType(idRaw); - if (unitType == null) { - return null; - } - - UnitXCTypeBuilder typeBuilder = new UnitXCTypeBuilder<>(this,new UnitXCType(),(p,v) -> {}); - typeBuilder - .setId(unitType.getId()+unitIdPostfix) - .setName(unitNamePrefix+unitType.getName()) - .addTypeFlags(unitType.getTypeFlags()); - - for (int i=0;i this.unitIdPostfix = unitIdPostfix); - } - - public UnitXCTypeCompoundExponentBuilder setUnitNamePrefix(String unitNamePrefix) { - return make(v -> this.unitNamePrefix = unitNamePrefix); - } -} diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeCompoundPairBuilder.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeCompoundPairBuilder.java deleted file mode 100644 index cec66f5..0000000 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeCompoundPairBuilder.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * 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.builder; - -import java.util.Iterator; - -import org.apache.commons.lang3.Validate; - -import net.forwardfire.unitxc.model.UnitXCGroup; -import net.forwardfire.unitxc.model.UnitXCType; -import net.forwardfire.unitxc.model.UnitXCTypeGenerator; -import net.forwardfire.unitxc.model.step.UnitXCConverterStepReference; -import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueNamedParameter; - -/** - * Build compound pair units. - * - * @author Willem Cazander - * @version 1.0 Oct 26, 2015 - */ -public class UnitXCTypeCompoundPairBuilder extends AbstractUnitXCBuilder { - - public static final String PER_ID = "/"; - public static final String PER_NAME = " per "; - - private final String groupId; - private final String perGroupId; - - public UnitXCTypeCompoundPairBuilder(UnitXCGroupBuilder parent,String groupId,String perGroupId) { - super(parent,parent.getValue(), (p,v) -> {}); - this.groupId = groupId; - this.perGroupId = perGroupId; - - parent.getValue().setTypeGenerator(new UnitXCTypeGenerator() { - - UnitXCGroup getGroup(String id) { - UnitXCGroup perGroup = null; - for (UnitXCGroup unitGroup:getParent().getParent().getConfig().getUnitGroups()) { - if (unitGroup.getId().equals(id)) { - perGroup = unitGroup; - } - } - return perGroup; - } - - @Override - public long size() { - UnitXCGroup group = getGroup(groupId); - UnitXCGroup perGroup = getGroup(perGroupId); - return group.getTypeGenerator().size()*perGroup.getTypeGenerator().size(); - } - - @Override - public Iterator getUnitTypes() { - UnitXCGroup group = getGroup(groupId); - UnitXCGroup perGroup = getGroup(perGroupId); - Iterator groupIt = group.getTypeGenerator().getUnitTypes(); - return new Iterator() { - - String groupId2; - Iterator perGroupIt; - - @Override - public boolean hasNext() { - if (perGroupIt!=null && perGroupIt.hasNext()) { - return true; - } - if (groupIt.hasNext()) { - groupId2 = groupIt.next(); - perGroupIt = perGroup.getTypeGenerator().getUnitTypes(); - return true; - } - return false; - } - - @Override - public String next() { - return groupId2+PER_ID+perGroupIt.next(); - } - }; - } - - @Override - public UnitXCType getUnitType(String id) { - if (!id.contains(PER_ID)) { - return null; - } - UnitXCGroup group = getGroup(groupId); - UnitXCGroup perGroup = getGroup(perGroupId); - Validate.notNull(group,"Could not find group: "+groupId); - Validate.notNull(perGroup,"Could not find group: "+perGroupId); - - String idGroup = id.substring(0,id.lastIndexOf(PER_ID)); // FIXME parse correctly see newton - String idGroupPer = id.substring(id.lastIndexOf(PER_ID)+1); - - UnitXCType unitType = group.getTypeGenerator().getUnitType(idGroup); - if (unitType == null) { - return null; - } - UnitXCType perUnitType = perGroup.getTypeGenerator().getUnitType(idGroupPer); - if (perUnitType == null) { - return null; - } - - // TODO: add name/name alias - UnitXCTypeBuilder typeBuilder = new UnitXCTypeBuilder<>(this,new UnitXCType(),(p,v) -> {}); - typeBuilder - .setId(id) - .setName(unitType.getName()+PER_NAME+perUnitType.getName()) - .addTypeFlags(unitType.getTypeFlags()) - .addTypeFlags(perUnitType.getTypeFlags()); - - typeBuilder.addToBaseConverterStep(new UnitXCConverterStepReference(unitType.getId(),true)); - typeBuilder.addToBaseConverterStep(new UnitXCConverterStepReference(perUnitType.getId(),false)); - typeBuilder.addFromBaseConverterStep(new UnitXCConverterStepReference(perUnitType.getId(),true)); - typeBuilder.addFromBaseConverterStep(new UnitXCConverterStepReference(unitType.getId(),false)); - typeBuilder.build(); - typeBuilder.getValue().setUnitGroup(parent.getValue()); - return typeBuilder.getValue(); - } - - }); - } - - @Override - protected UnitXCTypeCompoundPairBuilder getBuilder() { - return this; - } - - @Override - protected void buildPreValue(UnitXCGroup value) { - - UnitXCGroup group = null; - UnitXCGroup perGroup = null; - for (UnitXCGroup unitGroup:getParent().getParent().getConfig().getUnitGroups()) { - if (unitGroup.getId().equals(groupId)) { - group = unitGroup; - } - if (unitGroup.getId().equals(perGroupId)) { - perGroup = unitGroup; - } - } - Validate.notNull(group,"Could not find group: "+groupId); - Validate.notNull(perGroup,"Could not find group: "+perGroupId); - - getParent().getValue().getDerivedFrom().add(groupId); - getParent().getValue().getDerivedFrom().add(perGroupId); -// -// UnitXCGroupJump toGroupJump = new UnitXCGroupJump(); -// toGroupJump.setId("to_"+group.getId()); -// toGroupJump.setUnitGroup(group); -// toGroupJump.addJumpParameter(new UnitXCGroupJumpParameter("to_"+perGroup.getId(),"",perGroup.getId())); -// -// UnitXCGroupJump perGroupJump = new UnitXCGroupJump(); -// perGroupJump.setId("to_"+group.getId()); -// perGroupJump.setUnitGroup(group); - - //getValue().getGroupJumps().add(toGroupJump); // m/s -> m - //getValue().getGroupJumps().add(perGroupJump); // m/s -> h - - //group.getGroupJumps().add(toGroupJump); // m -> m/s - //perGroup.getGroupJumps().add(perGroupJump); // s -> m/s - - // m/s -> m - getParent() - .createGroupJump(group.getId()) - .addJumpParameter(value.getId()+"_"+perGroup.getId(),perGroup.getId()) - .createToGroupConverterSteps() - .multiply(new UnitXConverterStepValueNamedParameter(value.getId()+"_"+perGroup.getId())) - .build() - .build(); - - // m -> m/s - getParent().getParent().extendUnitGroup(group.getId()) - .createGroupJump(value.getId()) - .addJumpParameter(value.getId()+"_"+perGroup.getId(),perGroup.getId()) - .createToGroupConverterSteps() - .divide(new UnitXConverterStepValueNamedParameter(value.getId()+"_"+perGroup.getId())) - .build() - .build(); - } -} diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeSIPrefixBuilder.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeSIPrefixBuilder.java index ce95cfa..df5b528 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeSIPrefixBuilder.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/config/builder/UnitXCTypeSIPrefixBuilder.java @@ -28,6 +28,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; +import net.forwardfire.unitxc.model.DefaultUnitXCType; import net.forwardfire.unitxc.model.UnitXCType; import net.forwardfire.unitxc.model.step.UnitXCConverterStepPowerOfTen; import net.forwardfire.unitxc.model.step.UnitXConverterStepContext; @@ -40,11 +41,11 @@ import net.forwardfire.unitxc.model.step.UnitXConverterStepContext; */ public class UnitXCTypeSIPrefixBuilder

extends AbstractUnitXCTypeBuilder> { - private final UnitXCGroupBuilder builder; + private final UnitXCGroupBaseBuilder builder; private final List commonSIPrefixes; - public UnitXCTypeSIPrefixBuilder(P parent, UnitXCGroupBuilder builder) { - super(parent,new UnitXCType(), (p,v) -> {}); + public UnitXCTypeSIPrefixBuilder(P parent, UnitXCGroupBaseBuilder builder) { + super(parent,new DefaultUnitXCType(), (p,v) -> {}); this.builder = builder; this.commonSIPrefixes = new ArrayList<>(); } @@ -56,6 +57,9 @@ public class UnitXCTypeSIPrefixBuilder

extends AbstractUnitXCTypeBuilder derivedFrom; + private final List unitTypes; + private final List groupJumps; + + public AbstractUnitXCGroup() { + derivedFrom = new ArrayList<>(); + unitTypes = new ArrayList<>(); + groupJumps = new ArrayList<>(); + } + + public AbstractUnitXCGroup validate() { + Validate.notBlank(id,"The id is blank"); + Validate.notBlank(name,"The name is blank"); + Validate.notBlank(description,"The description is blank"); + Validate.notBlank(baseTypeId,"The baseTypeId is blank"); + return this; + } + + abstract long localUnitTypeSize(); + abstract Iterator localUnitTypeIds(); + abstract UnitXCType localUnitType(String id); + + @Override + final public long getUnitTypeSize() { + return getUnitTypes().size() + localUnitTypeSize(); + } + + @Override + final public Iterator getUnitTypeIds() { + Iterator l = localUnitTypeIds(); + List result = new ArrayList<>(); + getUnitTypes().forEach(t -> result.add(t.getId())); + Iterator g = result.iterator(); + return new Iterator() { + @Override + public boolean hasNext() { + if (l.hasNext()) { + return true; + } + return g.hasNext(); + } + @Override + public String next() { + if (l.hasNext()) { + return l.next(); + } + return g.next(); + } + }; + } + + @Override + final public UnitXCType getUnitType(String id) { + for (UnitXCType type:getUnitTypes()) { + if (type.getId().equals(id)) { + return type; + } + if (type.getName().equals(id)) { + return type; + } + } + return localUnitType(id); + } + + + + /** + * @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; + } + + /** + * @return the derivedFrom + */ + public List getDerivedFrom() { + return derivedFrom; + } + + /** + * @param derivedFrom the derivedFrom to add + */ + public void addDerivedFrom(String derivedFrom) { + this.derivedFrom.add(derivedFrom); + } + + /** + * @return the unit types. + */ + public List getUnitTypes() { + return unitTypes; + } + + public void addUnitType(DefaultUnitXCType type) { + Validate.notNull(type); + type.setUnitGroup(this); + type.validate(); + unitTypes.add(type); + } + + /** + * @return the groupJumps + */ + public List getGroupJumps() { + return groupJumps; + } + + /** + * @param groupJump the groupJump to add + */ + public void addGroupJump(UnitXCGroupJump groupJump) { + this.groupJumps.add(groupJump); + } + + @Override + final public String toString() { + return ReflectionToStringBuilder.toString(this); + } +} diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCType.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCType.java new file mode 100644 index 0000000..00007b8 --- /dev/null +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/DefaultUnitXCType.java @@ -0,0 +1,209 @@ +/* + * 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.List; + +import org.apache.commons.lang3.Validate; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; + +import net.forwardfire.unitxc.model.step.UnitXConverterStep; + +/** + * The unit type. + * + * @author Willem Cazander + * @version 1.0 Oct 10, 2015 + */ +public class DefaultUnitXCType implements UnitXCType { + + private String id; + private String name; + private String namePlural; + private String aliasOfType; + private UnitXCGroup unitGroup; + private final List toBaseConverterSteps; + private final List fromBaseConverterSteps; + private final List typeFlags; + private final List websiteLinks; + + public DefaultUnitXCType() { + typeFlags = new ArrayList<>(); + websiteLinks = new ArrayList<>(); + toBaseConverterSteps = new ArrayList<>(); + fromBaseConverterSteps = new ArrayList<>(); + } + + public UnitXCType validate() { + Validate.notBlank(id,"The id is blank"); + Validate.notBlank(name,"The name is blank of: "+id); + //Validate.notBlank(namePlural,"The namePlural is blank of: "+id); + Validate.notNull(unitGroup,"The unitGroup is null of: "+id); + return this; + } + + /** + * @return the id + */ + @Override + public String getId() { + return id; + } + /** + * @param id the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return the name + */ + @Override + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the namePlural + */ + @Override + public String getNamePlural() { + return namePlural; + } + + /** + * @param namePlural the namePlural to set + */ + public void setNamePlural(String namePlural) { + this.namePlural = namePlural; + } + + /** + * @return the aliasOfType + */ + @Override + public String getAliasOfType() { + return aliasOfType; + } + + /** + * @param aliasOfType the aliasOfType to set + */ + public void setAliasOfType(String aliasOfType) { + this.aliasOfType = aliasOfType; + } + + /** + * @return the unitGroup + */ + @Override + public UnitXCGroup getUnitGroup() { + return unitGroup; + } + + /** + * @param unitGroup the unitGroup to set + */ + public void setUnitGroup(UnitXCGroup unitGroup) { + this.unitGroup = unitGroup; + } + + /** + * @return the toBaseConverterSteps + */ + @Override + public List getToBaseConverterSteps() { + return toBaseConverterSteps; + } + + /** + * @param toBaseConverterSteps the toBaseConverterSteps to set + */ + public void setToBaseConverterSteps(List toBaseConverterSteps) { + this.toBaseConverterSteps.clear(); + this.toBaseConverterSteps.addAll(toBaseConverterSteps); + } + + /** + * @return the fromBaseConverterSteps + */ + @Override + public List getFromBaseConverterSteps() { + return fromBaseConverterSteps; + } + + /** + * @param fromBaseConverterSteps the fromBaseConverterSteps to set + */ + public void setFromBaseConverterSteps(List fromBaseConverterSteps) { + this.fromBaseConverterSteps.clear(); + this.fromBaseConverterSteps.addAll(fromBaseConverterSteps); + } + + /** + * @return the typeFlags + */ + @Override + public List getTypeFlags() { + return typeFlags; + } + + /** + * @param typeFlags the typeFlags to set + */ + public void setTypeFlags(List typeFlags) { + this.typeFlags.clear(); + this.typeFlags.addAll(typeFlags); + } + + /** + * @return the websiteLinks + */ + @Override + public List getWebsiteLinks() { + return websiteLinks; + } + + /** + * @param websiteLinks the websiteLinks to set + */ + public void setWebsiteLinks(List websiteLinks) { + this.websiteLinks.clear(); + this.websiteLinks.addAll(websiteLinks); + } + + @Override + public String toString() { + return ReflectionToStringBuilder.toString(this); + } +} diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCConfig.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCConfig.java index 849617a..49d33b4 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCConfig.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCConfig.java @@ -67,12 +67,12 @@ public class UnitXCConfig { /** * @param unitGroups the groups to set. */ - public void setUnitGroups(List groups) { + public void setUnitGroups(List groups) { this.unitGroups.clear(); groups.forEach(group -> addUnitGroup(group)); } - public void addUnitGroup(UnitXCGroup group) { + public void addUnitGroup(AbstractUnitXCGroup group) { Validate.notNull(group); group.validate(); unitGroups.add(group); diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCGroup.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCGroup.java index 983b04f..1305b16 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCGroup.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCGroup.java @@ -23,205 +23,53 @@ package net.forwardfire.unitxc.model; -import java.util.ArrayList; +import java.util.Iterator; import java.util.List; -import org.apache.commons.lang3.Validate; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; - /** * The unit group. * * @author Willem Cazander * @version 1.0 Oct 10, 2015 */ -public class UnitXCGroup { - - private String id; - private String name; - private String description; - private String baseTypeId; - private long totalUnitTypes = 0L; - private UnitXCGroupLevel groupLevel; - private UnitXCTypeGenerator typeGenerator; - private final List derivedFrom; - private final List unitTypes; - private final List groupJumps; - - public UnitXCGroup() { - derivedFrom = new ArrayList<>(); - unitTypes = new ArrayList<>(); - groupJumps = new ArrayList<>(); - } - - public UnitXCGroup(String id,String name,String description,String baseTypeId) { - this(); - setId(id); - setName(name); - setDescription(description); - setBaseTypeId(baseTypeId); - } - - public UnitXCGroup validate() { - Validate.notBlank(id,"The id is blank"); - Validate.notBlank(name,"The name is blank"); - Validate.notBlank(description,"The description is blank"); - Validate.notBlank(baseTypeId,"The baseTypeId is blank"); - Validate.notNull(groupLevel,"The groupLevel is null"); - return this; - } +public interface UnitXCGroup { /** * @return the id */ - public String getId() { - return id; - } - /** - * @param id the id to set - */ - public void setId(String id) { - this.id = id; - } + String getId(); /** * @return the name */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } + String getName(); /** * @return the description */ - public String getDescription() { - return description; - } - - /** - * @param description the description to set - */ - public void setDescription(String description) { - this.description = description; - } + String getDescription(); /** * @return the baseTypeId */ - public String getBaseTypeId() { - return baseTypeId; - } - - /** - * @param baseTypeId the baseTypeId to set - */ - public void setBaseTypeId(String baseTypeId) { - this.baseTypeId = baseTypeId; - } - - /** - * @return the groupLevel - */ - public UnitXCGroupLevel getGroupLevel() { - return groupLevel; - } - - /** - * @param groupLevel the groupLevel to set - */ - public void setGroupLevel(UnitXCGroupLevel groupLevel) { - this.groupLevel = groupLevel; - } + String getBaseTypeId(); /** * @return the derivedFrom */ - public List getDerivedFrom() { - return derivedFrom; - } - - /** - * @param derivedFrom the derivedFrom to set - */ - public void setDerivedFrom(List derivedFrom) { - this.derivedFrom.clear(); - this.derivedFrom.addAll(derivedFrom); - } - - /** - * @return the unit types. - */ - public List getUnitTypes() { - return unitTypes; - } - - /** - * @param unitTypes the types to set. - */ - public void setUnitTypes(List types) { - this.unitTypes.clear(); - types.forEach(type -> addUnitType(type)); - } - - public void addUnitType(UnitXCType type) { - Validate.notNull(type); - type.setUnitGroup(this); - type.validate(); - unitTypes.add(type); - } + List getDerivedFrom(); /** * @return the groupJumps */ - public List getGroupJumps() { - return groupJumps; - } - - /** - * @param groupJumps the groupJumps to set - */ - public void setGroupJumps(List groupJumps) { - this.groupJumps.clear(); - this.groupJumps.addAll(groupJumps); - } - - /** - * @return the typeGenerator - */ - public UnitXCTypeGenerator getTypeGenerator() { - return typeGenerator; - } - - /** - * @param typeGenerator the typeGenerator to set - */ - public void setTypeGenerator(UnitXCTypeGenerator typeGenerator) { - this.typeGenerator = typeGenerator; - } + List getGroupJumps(); /** * @return the totalUnitTypes */ - public long getTotalUnitTypes() { - return totalUnitTypes; - } + long getUnitTypeSize(); - /** - * @param totalUnitTypes the totalUnitTypes to set - */ - public void setTotalUnitTypes(long totalUnitTypes) { - this.totalUnitTypes = totalUnitTypes; - } - - @Override - public String toString() { - return ReflectionToStringBuilder.toString(this); - } + Iterator getUnitTypeIds(); + + UnitXCType getUnitType(String id); } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupBase.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupBase.java new file mode 100644 index 0000000..b5b7b72 --- /dev/null +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupBase.java @@ -0,0 +1,56 @@ +/* + * 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.Collections; +import java.util.Iterator; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 28, 2016 + */ +public class UnitXCGroupBase extends AbstractUnitXCGroup { + + public UnitXCGroupBase() { + + } + + @Override + public long localUnitTypeSize() { + return 0L; + } + + @Override + public Iterator localUnitTypeIds() { + return Collections.emptyIterator(); + } + + @Override + public UnitXCType localUnitType(String id) { + return null; + } + +} diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupCompoundExponent.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupCompoundExponent.java new file mode 100644 index 0000000..1bcbc5e --- /dev/null +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupCompoundExponent.java @@ -0,0 +1,143 @@ +/* + * 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.Iterator; + +import org.apache.commons.lang3.Validate; + +import net.forwardfire.unitxc.config.builder.UnitXCTypeBuilder; +import net.forwardfire.unitxc.model.step.UnitXCConverterStepReference; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Oct 28, 2016 + */ +public class UnitXCGroupCompoundExponent extends AbstractUnitXCGroup { + + private final UnitXCGroup parentGroup; + private final int exponent; + private String unitIdPostfix; + private String unitNamePrefix; + + public UnitXCGroupCompoundExponent(UnitXCGroup parentGroup,int exponent) { + this.parentGroup = Validate.notNull(parentGroup); + this.exponent = exponent; + Validate.isTrue(exponent > 1); + } + + @Override + public long localUnitTypeSize() { + return getParentGroup().getUnitTypeSize(); + } + + @Override + public Iterator localUnitTypeIds() { + Iterator g = getParentGroup().getUnitTypeIds(); + return new Iterator() { + @Override + public boolean hasNext() { + return g.hasNext(); + } + @Override + public String next() { + return g.next()+unitIdPostfix; + } + }; + } + + @Override + public UnitXCType localUnitType(String id) { + if (!id.endsWith(unitIdPostfix)) { + return null; + } + String idRaw = id.substring(0, id.length()-unitIdPostfix.length()); + UnitXCGroup group = getParentGroup(); + UnitXCType unitType = group.getUnitType(idRaw); + if (unitType == null) { + return null; + } + + DefaultUnitXCType result = new DefaultUnitXCType(); + UnitXCTypeBuilder typeBuilder = new UnitXCTypeBuilder<>(this,result,(p,v) -> {}); + typeBuilder + .setId(unitType.getId()+unitIdPostfix) + .setName(unitNamePrefix+unitType.getName()) + .addTypeFlags(unitType.getTypeFlags()); + + for (int i=0;i localUnitTypeIds() { + Iterator groupIt = getParentGroup().getUnitTypeIds(); + return new Iterator() { + + String groupId2; + Iterator perGroupIt; + + @Override + public boolean hasNext() { + if (perGroupIt!=null && perGroupIt.hasNext()) { + return true; + } + if (groupIt.hasNext()) { + groupId2 = groupIt.next(); + perGroupIt = getParentPerGroup().getUnitTypeIds(); + return true; + } + return false; + } + + @Override + public String next() { + return groupId2+PER_ID+perGroupIt.next(); + } + }; + } + + @Override + public UnitXCType localUnitType(String id) { +// if (!id.contains(PER_ID)) { +// return null; +// } + String[] units = id.split(PER_ID); + if (units.length < 2) { + return null; + } +// System.out.println("checking pair: "+id); + for (int i=1;i typeBuilder = new UnitXCTypeBuilder<>(this,result,(p,v) -> {}); + typeBuilder + .setId(id) + .setName(unitType.getName()+PER_NAME+perUnitType.getName()) + .addTypeFlags(unitType.getTypeFlags()) + .addTypeFlags(perUnitType.getTypeFlags()); + + typeBuilder.addToBaseConverterStep(new UnitXCConverterStepReference(unitType.getId(),true)); + typeBuilder.addToBaseConverterStep(new UnitXCConverterStepReference(perUnitType.getId(),false)); + typeBuilder.addFromBaseConverterStep(new UnitXCConverterStepReference(perUnitType.getId(),true)); + typeBuilder.addFromBaseConverterStep(new UnitXCConverterStepReference(unitType.getId(),false)); + typeBuilder.build(); + result.setUnitGroup(this); + return result; + } + + /** + * @return the parentGroup + */ + public UnitXCGroup getParentGroup() { + return parentGroup; + } + + /** + * @return the parentPerGroup + */ + public UnitXCGroup getParentPerGroup() { + return parentPerGroup; + } +} + diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupLevel.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupLevel.java deleted file mode 100644 index 6b6df92..0000000 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCGroupLevel.java +++ /dev/null @@ -1,13 +0,0 @@ -package net.forwardfire.unitxc.model; - -/** - * - * - * @author Willem Cazander - * @version 1.0 Oct 26, 2015 - */ -public enum UnitXCGroupLevel { - - SI_BASE, - SI_DERIVED -} 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 index 5b05cd8..f00eb7c 100644 --- 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 @@ -23,12 +23,8 @@ package net.forwardfire.unitxc.model; -import java.util.ArrayList; import java.util.List; -import org.apache.commons.lang3.Validate; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; - import net.forwardfire.unitxc.model.step.UnitXConverterStep; /** @@ -37,164 +33,52 @@ import net.forwardfire.unitxc.model.step.UnitXConverterStep; * @author Willem Cazander * @version 1.0 Oct 10, 2015 */ -public class UnitXCType { - - private String id; - private String name; - private String namePlural; - private String aliasOfType; - private UnitXCGroup unitGroup; - private final List toBaseConverterSteps; - private final List fromBaseConverterSteps; - private final List typeFlags; - private final List websiteLinks; - - public UnitXCType() { - typeFlags = new ArrayList<>(); - websiteLinks = new ArrayList<>(); - toBaseConverterSteps = new ArrayList<>(); - fromBaseConverterSteps = new ArrayList<>(); - } - - public UnitXCType validate() { - Validate.notBlank(id,"The id is blank"); - Validate.notBlank(name,"The name is blank of: "+id); - Validate.notBlank(namePlural,"The namePlural is blank of: "+id); - Validate.notNull(unitGroup,"The unitGroup is null of: "+id); - return this; - } +public interface UnitXCType { /** * @return the id */ - public String getId() { - return id; - } - /** - * @param id the id to set - */ - public void setId(String id) { - this.id = id; - } + String getId(); + /** * @return the name */ - public String getName() { - return name; - } + String getName(); /** - * @param name the name to set + * The name in plugal form. + * @return the namePlural. */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the namePlural - */ - public String getNamePlural() { - return namePlural; - } - - /** - * @param namePlural the namePlural to set - */ - public void setNamePlural(String namePlural) { - this.namePlural = namePlural; - } + String getNamePlural(); /** * @return the aliasOfType */ - public String getAliasOfType() { - return aliasOfType; - } - - /** - * @param aliasOfType the aliasOfType to set - */ - public void setAliasOfType(String aliasOfType) { - this.aliasOfType = aliasOfType; - } + String getAliasOfType(); /** * @return the unitGroup */ - public UnitXCGroup getUnitGroup() { - return unitGroup; - } - - /** - * @param unitGroup the unitGroup to set - */ - public void setUnitGroup(UnitXCGroup unitGroup) { - this.unitGroup = unitGroup; - } + UnitXCGroup getUnitGroup(); /** * @return the toBaseConverterSteps */ - public List getToBaseConverterSteps() { - return toBaseConverterSteps; - } - - /** - * @param toBaseConverterSteps the toBaseConverterSteps to set - */ - public void setToBaseConverterSteps(List toBaseConverterSteps) { - this.toBaseConverterSteps.clear(); - this.toBaseConverterSteps.addAll(toBaseConverterSteps); - } + List getToBaseConverterSteps(); /** * @return the fromBaseConverterSteps */ - public List getFromBaseConverterSteps() { - return fromBaseConverterSteps; - } - - /** - * @param fromBaseConverterSteps the fromBaseConverterSteps to set - */ - public void setFromBaseConverterSteps(List fromBaseConverterSteps) { - this.fromBaseConverterSteps.clear(); - this.fromBaseConverterSteps.addAll(fromBaseConverterSteps); - } + List getFromBaseConverterSteps(); /** * @return the typeFlags */ - public List getTypeFlags() { - return typeFlags; - } - - /** - * @param typeFlags the typeFlags to set - */ - public void setTypeFlags(List typeFlags) { - this.typeFlags.clear(); - this.typeFlags.addAll(typeFlags); - } + List getTypeFlags(); /** * @return the websiteLinks */ - public List getWebsiteLinks() { - return websiteLinks; - } - - /** - * @param websiteLinks the websiteLinks to set - */ - public void setWebsiteLinks(List websiteLinks) { - this.websiteLinks.clear(); - this.websiteLinks.addAll(websiteLinks); - } - - @Override - public String toString() { - return ReflectionToStringBuilder.toString(this); - } + List getWebsiteLinks(); } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCTypeGenerator.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCTypeGenerator.java deleted file mode 100644 index 2c18697..0000000 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/model/UnitXCTypeGenerator.java +++ /dev/null @@ -1,12 +0,0 @@ -package net.forwardfire.unitxc.model; - -import java.util.Iterator; - -public interface UnitXCTypeGenerator { - - long size(); - - Iterator getUnitTypes(); - - UnitXCType getUnitType(String id); -} diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleElectricCurrent.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleElectricCurrent.java index 870ded8..b31d168 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleElectricCurrent.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleElectricCurrent.java @@ -24,7 +24,6 @@ package net.forwardfire.unitxc.module; import static net.forwardfire.unitxc.config.UnitXCConfigModule.buildFlag; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_BASE; import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; @@ -50,8 +49,7 @@ public class UnitXCModuleElectricCurrent implements UnitXCConfigModule { @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_BASE) + builder.createUnitGroupBase() .setId( GROUP_ID) .setName( TYPE_AMPERE_NAME) .setDescription ( GROUP_DESCRIPTION) diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleLength.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleLength.java index 7a78590..45fe846 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleLength.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleLength.java @@ -24,7 +24,6 @@ package net.forwardfire.unitxc.module; import static net.forwardfire.unitxc.config.UnitXCConfigModule.buildFlag; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_BASE; import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; @@ -126,8 +125,7 @@ public class UnitXCModuleLength implements UnitXCConfigModule { @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_BASE) + builder.createUnitGroupBase() .setId( GROUP_ID) .setName( TYPE_METRE_NAME) .setDescription ( GROUP_DESCRIPTION) diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleLuminousIntensity.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleLuminousIntensity.java index 09f94a1..8753e5d 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleLuminousIntensity.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleLuminousIntensity.java @@ -24,7 +24,6 @@ package net.forwardfire.unitxc.module; import static net.forwardfire.unitxc.config.UnitXCConfigModule.buildFlag; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_BASE; import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; @@ -49,8 +48,7 @@ public class UnitXCModuleLuminousIntensity implements UnitXCConfigModule { @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_BASE) + builder.createUnitGroupBase() .setId( GROUP_ID) .setName( TYPE_CANDELA_NAME) .setDescription ( GROUP_DESCRIPTION) diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleMass.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleMass.java index ef34d82..0c86240 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleMass.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleMass.java @@ -24,7 +24,6 @@ package net.forwardfire.unitxc.module; import static net.forwardfire.unitxc.config.UnitXCConfigModule.buildFlag; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_BASE; import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; @@ -80,8 +79,7 @@ public class UnitXCModuleMass implements UnitXCConfigModule { @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_BASE) + builder.createUnitGroupBase() .setId( GROUP_ID) .setName( GROUP_NAME) .setDescription ( GROUP_DESCRIPTION) diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleSubstance.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleSubstance.java index 44d762e..e2f66ce 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleSubstance.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleSubstance.java @@ -24,7 +24,6 @@ package net.forwardfire.unitxc.module; import static net.forwardfire.unitxc.config.UnitXCConfigModule.buildFlag; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_BASE; import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; @@ -56,8 +55,7 @@ public class UnitXCModuleSubstance implements UnitXCConfigModule { @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_BASE) + builder.createUnitGroupBase() .setId( GROUP_ID) .setName( TYPE_MOLE_NAME) .setDescription ( GROUP_DESCRIPTION) diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleTemperature.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleTemperature.java index dfcc6e9..3b4ccab 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleTemperature.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleTemperature.java @@ -27,7 +27,6 @@ import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; import static net.forwardfire.unitxc.config.UnitXCConfigModule.buildFlag; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_BASE; import org.apache.commons.lang3.math.Fraction; @@ -78,8 +77,7 @@ public class UnitXCModuleTemperature implements UnitXCConfigModule { @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_BASE) + builder.createUnitGroupBase() .setId( GROUP_ID) .setName( TYPE_KELVIN_NAME) .setDescription( GROUP_DESCRIPTION) diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleTime.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleTime.java index 83c7dd7..ba01df9 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleTime.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/UnitXCModuleTime.java @@ -24,7 +24,6 @@ package net.forwardfire.unitxc.module; import static net.forwardfire.unitxc.config.UnitXCConfigModule.buildFlag; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_BASE; import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; @@ -73,8 +72,7 @@ public class UnitXCModuleTime implements UnitXCConfigModule { @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_BASE) + builder.createUnitGroupBase() .setId( GROUP_ID) .setName( TYPE_SECOND_NAME) .setDescription ( GROUP_DESCRIPTION) diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleAcceleration.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleAcceleration.java index fd72952..3cf2aeb 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleAcceleration.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleAcceleration.java @@ -24,11 +24,10 @@ package net.forwardfire.unitxc.module.derived; import static net.forwardfire.unitxc.config.builder.UnitXCNumberTypeSetting.toSuperScript; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED; import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; -import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; import net.forwardfire.unitxc.module.UnitXCModuleTime; /** @@ -43,19 +42,21 @@ public class UnitXCModuleAcceleration implements UnitXCConfigModule { private static final String UNIT_ID_POSTFIX = toSuperScript(UNIT_COMPOUND_EXPONENT); public static final String GROUP_ID = "acceleration"; - public static final String GROUP_NAME = UnitXCModuleSpeed.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleTime.GROUP_NAME; + public static final String GROUP_NAME = UnitXCModuleSpeed.GROUP_NAME+UnitXCGroupCompoundPair.PER_NAME+UnitXCModuleTime.GROUP_NAME; public static final String GROUP_DESCRIPTION = "Acceleration, is the rate of change of velocity of an object with respect to time."; - public static final String GROUP_BASE_TYPE_ID = UnitXCModuleSpeed.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID; + public static final String GROUP_BASE_TYPE_ID = "m"+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID+UNIT_ID_POSTFIX; //UnitXCModuleSpeed.GROUP_BASE_TYPE_ID; @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_DERIVED) + builder.createUnitGroupCompoundPair(UnitXCModuleSpeed.GROUP_ID, UnitXCModuleTime.GROUP_ID) .setId( GROUP_ID) .setName( GROUP_NAME) .setDescription ( GROUP_DESCRIPTION) .setBaseTypeId( GROUP_BASE_TYPE_ID) - .createCompoundPairUnitTypes(UnitXCModuleSpeed.GROUP_ID, UnitXCModuleTime.GROUP_ID) + .createUnitType() + .setAliasOfType("m/s/s") + .setId(GROUP_BASE_TYPE_ID) + .setName("Meter per second2") .build() .build() ; diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleArea.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleArea.java index 7f16f03..874ee11 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleArea.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleArea.java @@ -24,7 +24,6 @@ package net.forwardfire.unitxc.module.derived; import static net.forwardfire.unitxc.config.builder.UnitXCNumberTypeSetting.toSuperScript; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED; import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; @@ -64,16 +63,13 @@ public class UnitXCModuleArea implements UnitXCConfigModule { @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_DERIVED) + builder.createUnitGroupCompoundExponent(UnitXCModuleLength.GROUP_ID, UNIT_COMPOUND_EXPONENT) .setId( GROUP_ID) .setName( GROUP_NAME) .setDescription ( GROUP_DESCRIPTION) .setBaseTypeId( GROUP_BASE_TYPE_ID) - .createCompoundExponentUnitTypes(UnitXCModuleLength.GROUP_ID, UNIT_COMPOUND_EXPONENT) - .setUnitIdPostfix(UNIT_ID_POSTFIX) - .setUnitNamePrefix(UNIT_NAME_PREFIX) - .build() + .setUnitIdPostfix(UNIT_ID_POSTFIX) + .setUnitNamePrefix(UNIT_NAME_PREFIX) .createUnitType() .setAliasOfType( TYPE_CENTIARE_ALIAS) .setId( TYPE_CENTIARE_ID) diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleAreaDensity.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleAreaDensity.java index ac379fd..c831d4e 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleAreaDensity.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleAreaDensity.java @@ -23,11 +23,9 @@ package net.forwardfire.unitxc.module.derived; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED; - import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; -import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; import net.forwardfire.unitxc.module.UnitXCModuleMass; /** @@ -39,20 +37,17 @@ import net.forwardfire.unitxc.module.UnitXCModuleMass; public class UnitXCModuleAreaDensity implements UnitXCConfigModule { public static final String GROUP_ID = "area_density"; - public static final String GROUP_NAME = UnitXCModuleMass.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleArea.GROUP_NAME; + public static final String GROUP_NAME = UnitXCModuleMass.GROUP_NAME+UnitXCGroupCompoundPair.PER_NAME+UnitXCModuleArea.GROUP_NAME; public static final String GROUP_DESCRIPTION = "Area density is of a two-dimensional object is calculated as the mass per unit area."; - public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMass.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleArea.GROUP_BASE_TYPE_ID; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMass.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleArea.GROUP_BASE_TYPE_ID; @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_DERIVED) + builder.createUnitGroupCompoundPair(UnitXCModuleMass.GROUP_ID, UnitXCModuleArea.GROUP_ID) .setId( GROUP_ID) .setName( GROUP_NAME) .setDescription ( GROUP_DESCRIPTION) .setBaseTypeId( GROUP_BASE_TYPE_ID) - .createCompoundPairUnitTypes(UnitXCModuleMass.GROUP_ID, UnitXCModuleArea.GROUP_ID) - .build() .build() ; } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleJerk.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleJerk.java index f6ba630..41676fb 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleJerk.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleJerk.java @@ -23,11 +23,9 @@ package net.forwardfire.unitxc.module.derived; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED; - import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; -import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; import net.forwardfire.unitxc.module.UnitXCModuleTime; /** @@ -39,21 +37,18 @@ import net.forwardfire.unitxc.module.UnitXCModuleTime; public class UnitXCModuleJerk implements UnitXCConfigModule { public static final String GROUP_ID = "jerk"; - public static final String GROUP_NAME = UnitXCModuleAcceleration.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleTime.GROUP_NAME; + public static final String GROUP_NAME = UnitXCModuleAcceleration.GROUP_NAME+UnitXCGroupCompoundPair.PER_NAME+UnitXCModuleTime.GROUP_NAME; public static final String GROUP_DESCRIPTION = "Jerk, also known as jolt, surge, or lurch, is the rate of change of acceleration, with respect to time."; - public static final String GROUP_BASE_TYPE_ID = UnitXCModuleAcceleration.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleAcceleration.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID; // TODO: add aliases @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_DERIVED) + builder.createUnitGroupCompoundPair(UnitXCModuleAcceleration.GROUP_ID, UnitXCModuleTime.GROUP_ID) .setId( GROUP_ID) .setName( GROUP_NAME) .setDescription ( GROUP_DESCRIPTION) .setBaseTypeId( GROUP_BASE_TYPE_ID) - .createCompoundPairUnitTypes(UnitXCModuleAcceleration.GROUP_ID, UnitXCModuleTime.GROUP_ID) - .build() .build() ; } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleJounce.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleJounce.java index 9fe4e4d..3172dec 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleJounce.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleJounce.java @@ -23,11 +23,9 @@ package net.forwardfire.unitxc.module.derived; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED; - import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; -import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; import net.forwardfire.unitxc.module.UnitXCModuleTime; /** @@ -39,21 +37,18 @@ import net.forwardfire.unitxc.module.UnitXCModuleTime; public class UnitXCModuleJounce implements UnitXCConfigModule { public static final String GROUP_ID = "jounce"; - public static final String GROUP_NAME = UnitXCModuleJerk.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleTime.GROUP_NAME; + public static final String GROUP_NAME = UnitXCModuleJerk.GROUP_NAME+UnitXCGroupCompoundPair.PER_NAME+UnitXCModuleTime.GROUP_NAME; public static final String GROUP_DESCRIPTION = "Is the fourth derivative of the position vector with respect to time or the rate of change of the jerk with respect to time."; - public static final String GROUP_BASE_TYPE_ID = UnitXCModuleJerk.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleJerk.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID; // TODO: add aliases @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_DERIVED) + builder.createUnitGroupCompoundPair(UnitXCModuleJerk.GROUP_ID, UnitXCModuleTime.GROUP_ID) .setId( GROUP_ID) .setName( GROUP_NAME) .setDescription ( GROUP_DESCRIPTION) .setBaseTypeId( GROUP_BASE_TYPE_ID) - .createCompoundPairUnitTypes(UnitXCModuleJerk.GROUP_ID, UnitXCModuleTime.GROUP_ID) - .build() .build() ; } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMassDensity.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMassDensity.java index c45749b..47c76a0 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMassDensity.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMassDensity.java @@ -23,11 +23,9 @@ package net.forwardfire.unitxc.module.derived; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED; - import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; -import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; import net.forwardfire.unitxc.module.UnitXCModuleMass; /** @@ -39,20 +37,17 @@ import net.forwardfire.unitxc.module.UnitXCModuleMass; public class UnitXCModuleMassDensity implements UnitXCConfigModule { public static final String GROUP_ID = "mass_density"; - public static final String GROUP_NAME = UnitXCModuleMass.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleVolume.GROUP_NAME; + public static final String GROUP_NAME = UnitXCModuleMass.GROUP_NAME+UnitXCGroupCompoundPair.PER_NAME+UnitXCModuleVolume.GROUP_NAME; public static final String GROUP_DESCRIPTION = "The volumetric mass density, of a substance is its mass per unit volume."; - public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMass.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleVolume.GROUP_BASE_TYPE_ID; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMass.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleVolume.GROUP_BASE_TYPE_ID; @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_DERIVED) + builder.createUnitGroupCompoundPair(UnitXCModuleMass.GROUP_ID, UnitXCModuleVolume.GROUP_ID) .setId( GROUP_ID) .setName( GROUP_NAME) .setDescription ( GROUP_DESCRIPTION) .setBaseTypeId( GROUP_BASE_TYPE_ID) - .createCompoundPairUnitTypes(UnitXCModuleMass.GROUP_ID, UnitXCModuleVolume.GROUP_ID) - .build() .build() ; } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMolarConcentration.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMolarConcentration.java index 4b5fb78..032fb5f 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMolarConcentration.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMolarConcentration.java @@ -23,11 +23,9 @@ package net.forwardfire.unitxc.module.derived; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED; - import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; -import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; import net.forwardfire.unitxc.module.UnitXCModuleSubstance; /** @@ -39,20 +37,17 @@ import net.forwardfire.unitxc.module.UnitXCModuleSubstance; public class UnitXCModuleMolarConcentration implements UnitXCConfigModule { public static final String GROUP_ID = "molar_concentration"; - public static final String GROUP_NAME = UnitXCModuleSubstance.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleVolume.GROUP_NAME; + public static final String GROUP_NAME = UnitXCModuleSubstance.GROUP_NAME+UnitXCGroupCompoundPair.PER_NAME+UnitXCModuleVolume.GROUP_NAME; public static final String GROUP_DESCRIPTION = "Molar concentration is a measure of the concentration of a solute in a solution."; - public static final String GROUP_BASE_TYPE_ID = UnitXCModuleSubstance.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleVolume.GROUP_BASE_TYPE_ID; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleSubstance.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleVolume.GROUP_BASE_TYPE_ID; @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_DERIVED) + builder.createUnitGroupCompoundPair(UnitXCModuleSubstance.GROUP_ID, UnitXCModuleVolume.GROUP_ID) .setId( GROUP_ID) .setName( GROUP_NAME) .setDescription ( GROUP_DESCRIPTION) .setBaseTypeId( GROUP_BASE_TYPE_ID) - .createCompoundPairUnitTypes(UnitXCModuleSubstance.GROUP_ID, UnitXCModuleVolume.GROUP_ID) - .build() .build() ; } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMolarVolume.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMolarVolume.java index 5197fea..aa9a07d 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMolarVolume.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleMolarVolume.java @@ -23,11 +23,9 @@ package net.forwardfire.unitxc.module.derived; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED; - import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; -import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; import net.forwardfire.unitxc.module.UnitXCModuleSubstance; /** @@ -39,20 +37,17 @@ import net.forwardfire.unitxc.module.UnitXCModuleSubstance; public class UnitXCModuleMolarVolume implements UnitXCConfigModule { public static final String GROUP_ID = "molar_volume"; - public static final String GROUP_NAME = UnitXCModuleVolume.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleSubstance.GROUP_NAME; + public static final String GROUP_NAME = UnitXCModuleVolume.GROUP_NAME+UnitXCGroupCompoundPair.PER_NAME+UnitXCModuleSubstance.GROUP_NAME; public static final String GROUP_DESCRIPTION = "Molar volume is the volume occupied by one mole of a substance."; - public static final String GROUP_BASE_TYPE_ID = UnitXCModuleVolume.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleSubstance.GROUP_BASE_TYPE_ID; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleVolume.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleSubstance.GROUP_BASE_TYPE_ID; @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_DERIVED) + builder.createUnitGroupCompoundPair(UnitXCModuleVolume.GROUP_ID, UnitXCModuleSubstance.GROUP_ID) .setId( GROUP_ID) .setName( GROUP_NAME) .setDescription ( GROUP_DESCRIPTION) .setBaseTypeId( GROUP_BASE_TYPE_ID) - .createCompoundPairUnitTypes(UnitXCModuleVolume.GROUP_ID, UnitXCModuleSubstance.GROUP_ID) - .build() .build() ; } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleSpecificVolume.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleSpecificVolume.java index 38404ba..070aaa1 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleSpecificVolume.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleSpecificVolume.java @@ -23,11 +23,9 @@ package net.forwardfire.unitxc.module.derived; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED; - import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; -import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; import net.forwardfire.unitxc.module.UnitXCModuleMass; /** @@ -39,20 +37,17 @@ import net.forwardfire.unitxc.module.UnitXCModuleMass; public class UnitXCModuleSpecificVolume implements UnitXCConfigModule { public static final String GROUP_ID = "specific_volume"; - public static final String GROUP_NAME = UnitXCModuleVolume.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleMass.GROUP_NAME; + public static final String GROUP_NAME = UnitXCModuleVolume.GROUP_NAME+UnitXCGroupCompoundPair.PER_NAME+UnitXCModuleMass.GROUP_NAME; public static final String GROUP_DESCRIPTION = "In thermodynamics, the specific volume of a substance is the ratio of the substance's volume to its mass."; - public static final String GROUP_BASE_TYPE_ID = UnitXCModuleVolume.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleMass.GROUP_BASE_TYPE_ID; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleVolume.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleMass.GROUP_BASE_TYPE_ID; @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_DERIVED) + builder.createUnitGroupCompoundPair(UnitXCModuleVolume.GROUP_ID, UnitXCModuleMass.GROUP_ID) .setId( GROUP_ID) .setName( GROUP_NAME) .setDescription ( GROUP_DESCRIPTION) .setBaseTypeId( GROUP_BASE_TYPE_ID) - .createCompoundPairUnitTypes(UnitXCModuleVolume.GROUP_ID, UnitXCModuleMass.GROUP_ID) - .build() .build() ; } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleSpeed.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleSpeed.java index 2a7ef87..7961392 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleSpeed.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleSpeed.java @@ -23,11 +23,9 @@ package net.forwardfire.unitxc.module.derived; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED; - import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; -import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; import net.forwardfire.unitxc.module.UnitXCModuleLength; import net.forwardfire.unitxc.module.UnitXCModuleTime; @@ -40,20 +38,17 @@ import net.forwardfire.unitxc.module.UnitXCModuleTime; public class UnitXCModuleSpeed implements UnitXCConfigModule { public static final String GROUP_ID = "speed"; - public static final String GROUP_NAME = UnitXCModuleLength.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleTime.GROUP_NAME; + public static final String GROUP_NAME = UnitXCModuleLength.GROUP_NAME+UnitXCGroupCompoundPair.PER_NAME+UnitXCModuleTime.GROUP_NAME; public static final String GROUP_DESCRIPTION = "Speed is the dimensions of a length divided by a time."; - public static final String GROUP_BASE_TYPE_ID = UnitXCModuleLength.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleLength.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID; @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_DERIVED) + builder.createUnitGroupCompoundPair(UnitXCModuleLength.GROUP_ID, UnitXCModuleTime.GROUP_ID) .setId( GROUP_ID) .setName( GROUP_NAME) .setDescription ( GROUP_DESCRIPTION) .setBaseTypeId( GROUP_BASE_TYPE_ID) - .createCompoundPairUnitTypes(UnitXCModuleLength.GROUP_ID, UnitXCModuleTime.GROUP_ID) - .build() .build() ; } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleVolume.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleVolume.java index b2cd847..0d01637 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleVolume.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleVolume.java @@ -24,7 +24,6 @@ package net.forwardfire.unitxc.module.derived; import static net.forwardfire.unitxc.config.builder.UnitXCNumberTypeSetting.toSuperScript; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED; import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; @@ -49,16 +48,13 @@ public class UnitXCModuleVolume implements UnitXCConfigModule { @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_DERIVED) + builder.createUnitGroupCompoundExponent(UnitXCModuleLength.GROUP_ID, UNIT_COMPOUND_EXPONENT) .setId( GROUP_ID) .setName( GROUP_NAME) .setDescription ( GROUP_DESCRIPTION) .setBaseTypeId( GROUP_BASE_TYPE_ID) - .createCompoundExponentUnitTypes(UnitXCModuleLength.GROUP_ID, UNIT_COMPOUND_EXPONENT) - .setUnitIdPostfix(UNIT_ID_POSTFIX) - .setUnitNamePrefix(UNIT_NAME_PREFIX) - .build() + .setUnitIdPostfix(UNIT_ID_POSTFIX) + .setUnitNamePrefix(UNIT_NAME_PREFIX) .build() ; } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleVolumetricFlow.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleVolumetricFlow.java index 7254cb3..83f1768 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleVolumetricFlow.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/derived/UnitXCModuleVolumetricFlow.java @@ -23,11 +23,9 @@ package net.forwardfire.unitxc.module.derived; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED; - import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; -import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; import net.forwardfire.unitxc.module.UnitXCModuleTime; /** @@ -39,20 +37,17 @@ import net.forwardfire.unitxc.module.UnitXCModuleTime; public class UnitXCModuleVolumetricFlow implements UnitXCConfigModule { public static final String GROUP_ID = "volumetric_flow"; - public static final String GROUP_NAME = UnitXCModuleVolume.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleTime.GROUP_NAME; + public static final String GROUP_NAME = UnitXCModuleVolume.GROUP_NAME+UnitXCGroupCompoundPair.PER_NAME+UnitXCModuleTime.GROUP_NAME; public static final String GROUP_DESCRIPTION = "Volumetric flow is the volume of fluid which passes per unit time."; - public static final String GROUP_BASE_TYPE_ID = UnitXCModuleVolume.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID; + public static final String GROUP_BASE_TYPE_ID = UnitXCModuleVolume.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID; @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_DERIVED) + builder.createUnitGroupCompoundPair(UnitXCModuleVolume.GROUP_ID, UnitXCModuleTime.GROUP_ID) .setId( GROUP_ID) .setName( GROUP_NAME) .setDescription ( GROUP_DESCRIPTION) .setBaseTypeId( GROUP_BASE_TYPE_ID) - .createCompoundPairUnitTypes(UnitXCModuleVolume.GROUP_ID, UnitXCModuleTime.GROUP_ID) - .build() .build() ; } diff --git a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/named/UnitXCModuleNewton.java b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/named/UnitXCModuleNewton.java index 07ccce8..6d9275f 100644 --- a/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/named/UnitXCModuleNewton.java +++ b/ff-unitxc-converter/src/main/java/net/forwardfire/unitxc/module/named/UnitXCModuleNewton.java @@ -23,11 +23,9 @@ package net.forwardfire.unitxc.module.named; -import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED; - import net.forwardfire.unitxc.config.UnitXCConfigModule; import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder; -import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder; +import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair; import net.forwardfire.unitxc.module.UnitXCModuleMass; import net.forwardfire.unitxc.module.derived.UnitXCModuleAcceleration; @@ -40,23 +38,24 @@ import net.forwardfire.unitxc.module.derived.UnitXCModuleAcceleration; public class UnitXCModuleNewton implements UnitXCConfigModule { public static final String GROUP_ID = "newton"; - public static final String GROUP_NAME = UnitXCModuleMass.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleAcceleration.GROUP_NAME; + public static final String GROUP_NAME = UnitXCModuleMass.GROUP_NAME+UnitXCGroupCompoundPair.PER_NAME+UnitXCModuleAcceleration.GROUP_NAME; public static final String GROUP_DESCRIPTION = "One newton is the force needed to accelerate one kilogram of mass at the rate of one metre per second squared in direction of the applied force."; - public static final String GROUP_BASE_TYPE_ID = "kg"+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleAcceleration.GROUP_BASE_TYPE_ID; + public static final String GROUP_BASE_TYPE_ID = "kg"+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleAcceleration.GROUP_BASE_TYPE_ID; // TODO: symbol N + fix builder @Override public void configModule(UnitXCConfigBuilder builder) { - builder.createUnitGroup() - .setGroupLevel( SI_DERIVED) + builder.createUnitGroupCompoundPair(UnitXCModuleMass.GROUP_ID, UnitXCModuleAcceleration.GROUP_ID) .setId( GROUP_ID) .setName( GROUP_NAME) .setDescription ( GROUP_DESCRIPTION) .setBaseTypeId( GROUP_BASE_TYPE_ID) - .createCompoundPairUnitTypes(UnitXCModuleMass.GROUP_ID, UnitXCModuleAcceleration.GROUP_ID) + .createUnitType() + .setId("N") + .setName(GROUP_ID) + .setAliasOfType(GROUP_BASE_TYPE_ID) .build() - .build() - ; + .build(); } } diff --git a/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/UnitXCConverterStepTest.java b/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/UnitXCConverterStepTest.java index 3ed13e1..8715919 100644 --- a/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/UnitXCConverterStepTest.java +++ b/ff-unitxc-converter/src/test/java/net/forwardfire/unitxc/UnitXCConverterStepTest.java @@ -64,11 +64,12 @@ public class UnitXCConverterStepTest { for (UnitXCGroup typeGroup:unitManager.getConfig().getUnitGroups()) { UnitXCType type = unitManager.getUnitType(typeGroup.getBaseTypeId()); if (type == null) { - throw new IllegalStateException("No base type for: "+typeGroup); + throw new IllegalStateException("No base type for: "+typeGroup.getId()+" needs: "+typeGroup.getBaseTypeId()); } - long tc = typeGroup.getTotalUnitTypes(); + long tc = typeGroup.getUnitTypeSize(); ts += tc; - System.out.println("TypeGroup: "+typeGroup.getId()+"\tunits:"+tc+"\t name: "+typeGroup.getName()+"\t\t baseType: "+type.getId()); + String groupLine = String.format("%-20s %-20d %-10s %s", typeGroup.getId(),tc,type.getId(),typeGroup.getName()); + System.out.println(groupLine); } System.out.println("\ntotalTypes: "+ts); System.out.println("");