fixed full compound pair search

This commit is contained in:
Willem 2016-10-29 03:05:23 +02:00
parent f2b7f4c6d5
commit be484ade4e
46 changed files with 1255 additions and 981 deletions

View file

@ -79,7 +79,7 @@ public final class UnitXCFactory {
new UnitXCModuleJounce(),
// named
//new UnitXCModuleNewton(),
new UnitXCModuleNewton(),
// more derived
new UnitXCModuleAreaDensity(),

View file

@ -57,7 +57,6 @@ public class UnitXCConfigManager implements UnitXCManager {
private static Map<String,UnitXCGroup> createUnitGroups(Collection<UnitXCGroup> values) {
Map<String,UnitXCGroup> 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;
}

View file

@ -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<P,T extends AbstractUnitXCGroup,B> extends AbstractUnitXCBuilder<P,T,B> {
public AbstractUnitXCGroupBuilder(P parent, T model, BiConsumer<P, T> parentBuilder) {
super(parent, model, parentBuilder);
}
public UnitXCGroupJumpBuilder<AbstractUnitXCGroupBuilder<P,T,B>> createGroupJump(String unitGroupId) {
return new UnitXCGroupJumpBuilder<>(this,getValue(),unitGroupId,(p,v) -> p.getValue().addGroupJump(v));
}
public UnitXCTypeBuilder<AbstractUnitXCGroupBuilder<P,T,B>> 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));
// }
}

View file

@ -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<P,B> extends AbstractUnitXCBuilder<P,UnitXCType,B> {
public abstract class AbstractUnitXCTypeBuilder<P,B> extends AbstractUnitXCBuilder<P,DefaultUnitXCType,B> {
public AbstractUnitXCTypeBuilder(P parent,UnitXCType model,BiConsumer<P, UnitXCType> parentBuilder) {
public AbstractUnitXCTypeBuilder(P parent,DefaultUnitXCType model,BiConsumer<P, DefaultUnitXCType> parentBuilder) {
super(parent, model, parentBuilder);
}
protected final void buildPreValue(UnitXCType value) {
@Override
protected final void buildPreValue(DefaultUnitXCType value) {
if (value.getNamePlural() == null) {
setNamePlurals();
}

View file

@ -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<UnitXCConfigBuilder> 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<UnitXCConfigBuilder> extendUnitType(String id) {
// return new UnitXCTypeBuilder<>(this,findType(id),(p,v) -> {});
// }
}

View file

@ -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<UnitXCConfigBuilder,UnitXCGroupBase,UnitXCGroupBaseBuilder> {
public UnitXCGroupBaseBuilder(UnitXCConfigBuilder parent, UnitXCGroupBase model, BiConsumer<UnitXCConfigBuilder, UnitXCGroupBase> parentBuilder) {
super(parent, model, parentBuilder);
}
@Override
protected UnitXCGroupBaseBuilder getBuilder() {
return this;
}
public UnitXCTypeSIPrefixBuilder<UnitXCGroupBaseBuilder> createSIUnitTypes() {
return new UnitXCTypeSIPrefixBuilder<>(this,this);
}
}

View file

@ -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<UnitXCConfigBuilder,UnitXCGroup,UnitXCGroupBuilder> {
public UnitXCGroupBuilder(UnitXCConfigBuilder parent, UnitXCGroup model, BiConsumer<UnitXCConfigBuilder, UnitXCGroup> parentBuilder) {
super(parent, model, parentBuilder);
if (model.getTypeGenerator() == null) {
model.setTypeGenerator(new UnitXCTypeGenerator() {
@Override
public long size() {
return model.getUnitTypes().size();
}
@Override
public Iterator<String> getUnitTypes() {
List<String> 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<UnitXCGroupBuilder> createUnitType() {
return new UnitXCTypeBuilder<>(this,new UnitXCType(),(p,v) -> p.getValue().addUnitType(v));
}
public UnitXCTypeSIPrefixBuilder<UnitXCGroupBuilder> 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));
// }
}

View file

@ -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<UnitXCConfigBuilder,UnitXCGroupCompoundExponent,UnitXCGroupCompoundExponentBuilder> {
public UnitXCGroupCompoundExponentBuilder(UnitXCConfigBuilder parent, UnitXCGroupCompoundExponent model, BiConsumer<UnitXCConfigBuilder, UnitXCGroupCompoundExponent> 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));
}
}

View file

@ -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<UnitXCConfigBuilder,UnitXCGroupCompoundPair,UnitXCGroupCompoundPairBuilder> {
public UnitXCGroupCompoundPairBuilder(UnitXCConfigBuilder parent, UnitXCGroupCompoundPair model, BiConsumer<UnitXCConfigBuilder, UnitXCGroupCompoundPair> 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();
}
}

View file

@ -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<UnitXCConfigBuilder,AbstractUnitXCGroup,UnitXCGroupExtendBuilder> {
public UnitXCGroupExtendBuilder(UnitXCConfigBuilder parent, AbstractUnitXCGroup model, BiConsumer<UnitXCConfigBuilder, AbstractUnitXCGroup> parentBuilder) {
super(parent, model, parentBuilder);
}
@Override
protected UnitXCGroupExtendBuilder getBuilder() {
return this;
}
}

View file

@ -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<UnitXCConfigBuilder,UnitXCGroupJump,UnitXCGroupJumpBuilder> {
public class UnitXCGroupJumpBuilder<P> extends AbstractUnitXCBuilder<P,UnitXCGroupJump,UnitXCGroupJumpBuilder<P>> {
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<P, UnitXCGroupJump> parentBuilder) {
super(parent, new UnitXCGroupJump(), parentBuilder);
getValue().setUnitGroupId(unitGroupId);
getValue().setId(forGroup.getId()+"_"+unitGroupId);
}
@Override
protected UnitXCGroupJumpBuilder getBuilder() {
protected UnitXCGroupJumpBuilder<P> getBuilder() {
return this;
}
public UnitXCGroupJumpBuilder setId(String id) {
public UnitXCGroupJumpBuilder<P> setId(String id) {
return make((v) -> v.setId(id));
}
public UnitXCGroupJumpBuilder addJumpParameter(String id,String unitGroupId) {
public UnitXCGroupJumpBuilder<P> addJumpParameter(String id,String unitGroupId) {
return make((v) -> v.addJumpParameter(new UnitXCGroupJumpParameter(id, unitGroupId)));
}
public UnitXConverterStepBuilder<UnitXCGroupJumpBuilder> createToGroupConverterSteps() {
public UnitXConverterStepBuilder<UnitXCGroupJumpBuilder<P>> createToGroupConverterSteps() {
return new UnitXConverterStepBuilder<>(this,(p,v) -> getValue().getToGroupConverterSteps().addAll(v),() -> "group jump");
}
}

View file

@ -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<P> extends AbstractUnitXCTypeBuilder<P,UnitXCTypeBuilder<P>> {
public UnitXCTypeBuilder(P parent,UnitXCType model, BiConsumer<P, UnitXCType> parentBuilder) {
public UnitXCTypeBuilder(P parent,DefaultUnitXCType model, BiConsumer<P, DefaultUnitXCType> parentBuilder) {
super(parent,model, parentBuilder);
}

View file

@ -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<UnitXCGroupBuilder,Object,UnitXCTypeCompoundExponentBuilder> {
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<String> getUnitTypes() {
Iterator<String> g = getGroup().getTypeGenerator().getUnitTypes();
return new Iterator<String>() {
@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<Object> 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<UnitXCTypeCompoundExponentBuilder.this.exponent;i++) {
typeBuilder.addToBaseConverterStep(new UnitXCConverterStepReference(unitType.getId(),true));
typeBuilder.addFromBaseConverterStep(new UnitXCConverterStepReference(unitType.getId(),false));
}
typeBuilder.build();
typeBuilder.getValue().setUnitGroup(parent.getValue());
return typeBuilder.getValue();
}
});
}
@Override
protected UnitXCTypeCompoundExponentBuilder getBuilder() {
return this;
}
@Override
protected void buildPreValue(Object v) {
UnitXCGroup group = null;
for (UnitXCGroup unitGroup:getParent().getParent().getConfig().getUnitGroups()) {
if (unitGroup.getId().equals(unitGroupId)) {
group = unitGroup;
break;
}
}
Validate.notNull(group,"Could not find group: "+unitGroupId);
getParent().getValue().getDerivedFrom().add(unitGroupId);
}
public UnitXCTypeCompoundExponentBuilder setUnitIdPostfix(String unitIdPostfix) {
return make(v -> this.unitIdPostfix = unitIdPostfix);
}
public UnitXCTypeCompoundExponentBuilder setUnitNamePrefix(String unitNamePrefix) {
return make(v -> this.unitNamePrefix = unitNamePrefix);
}
}

View file

@ -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<UnitXCGroupBuilder,UnitXCGroup,UnitXCTypeCompoundPairBuilder> {
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<String> getUnitTypes() {
UnitXCGroup group = getGroup(groupId);
UnitXCGroup perGroup = getGroup(perGroupId);
Iterator<String> groupIt = group.getTypeGenerator().getUnitTypes();
return new Iterator<String>() {
String groupId2;
Iterator<String> 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<Object> 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();
}
}

View file

@ -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<P> extends AbstractUnitXCTypeBuilder<P,UnitXCTypeSIPrefixBuilder<P>> {
private final UnitXCGroupBuilder builder;
private final UnitXCGroupBaseBuilder builder;
private final List<UnitXCTypeSIPrefix> 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<P> extends AbstractUnitXCTypeBuilder<P,Un
@Override
protected void buildModel(UnitXCType v) {
// FIXME: if v.getAliasOfType() != null than skip copy steps
builder.createUnitType()
.setId(v.getId())
.setName(v.getName())

View file

@ -0,0 +1,212 @@
/*
* 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.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
*/
abstract public class AbstractUnitXCGroup implements UnitXCGroup {
private String id;
private String name;
private String description;
private String baseTypeId;
private final List<String> derivedFrom;
private final List<UnitXCType> unitTypes;
private final List<UnitXCGroupJump> 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<String> localUnitTypeIds();
abstract UnitXCType localUnitType(String id);
@Override
final public long getUnitTypeSize() {
return getUnitTypes().size() + localUnitTypeSize();
}
@Override
final public Iterator<String> getUnitTypeIds() {
Iterator<String> l = localUnitTypeIds();
List<String> result = new ArrayList<>();
getUnitTypes().forEach(t -> result.add(t.getId()));
Iterator<String> g = result.iterator();
return new Iterator<String>() {
@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<String> getDerivedFrom() {
return derivedFrom;
}
/**
* @param derivedFrom the derivedFrom to add
*/
public void addDerivedFrom(String derivedFrom) {
this.derivedFrom.add(derivedFrom);
}
/**
* @return the unit types.
*/
public List<UnitXCType> getUnitTypes() {
return unitTypes;
}
public void addUnitType(DefaultUnitXCType type) {
Validate.notNull(type);
type.setUnitGroup(this);
type.validate();
unitTypes.add(type);
}
/**
* @return the groupJumps
*/
public List<UnitXCGroupJump> 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);
}
}

View file

@ -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<UnitXConverterStep> toBaseConverterSteps;
private final List<UnitXConverterStep> fromBaseConverterSteps;
private final List<String> typeFlags;
private final List<String> 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<UnitXConverterStep> getToBaseConverterSteps() {
return toBaseConverterSteps;
}
/**
* @param toBaseConverterSteps the toBaseConverterSteps to set
*/
public void setToBaseConverterSteps(List<UnitXConverterStep> toBaseConverterSteps) {
this.toBaseConverterSteps.clear();
this.toBaseConverterSteps.addAll(toBaseConverterSteps);
}
/**
* @return the fromBaseConverterSteps
*/
@Override
public List<UnitXConverterStep> getFromBaseConverterSteps() {
return fromBaseConverterSteps;
}
/**
* @param fromBaseConverterSteps the fromBaseConverterSteps to set
*/
public void setFromBaseConverterSteps(List<UnitXConverterStep> fromBaseConverterSteps) {
this.fromBaseConverterSteps.clear();
this.fromBaseConverterSteps.addAll(fromBaseConverterSteps);
}
/**
* @return the typeFlags
*/
@Override
public List<String> getTypeFlags() {
return typeFlags;
}
/**
* @param typeFlags the typeFlags to set
*/
public void setTypeFlags(List<String> typeFlags) {
this.typeFlags.clear();
this.typeFlags.addAll(typeFlags);
}
/**
* @return the websiteLinks
*/
@Override
public List<String> getWebsiteLinks() {
return websiteLinks;
}
/**
* @param websiteLinks the websiteLinks to set
*/
public void setWebsiteLinks(List<String> websiteLinks) {
this.websiteLinks.clear();
this.websiteLinks.addAll(websiteLinks);
}
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
}
}

View file

@ -67,12 +67,12 @@ public class UnitXCConfig {
/**
* @param unitGroups the groups to set.
*/
public void setUnitGroups(List<UnitXCGroup> groups) {
public void setUnitGroups(List<AbstractUnitXCGroup> 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);

View file

@ -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<String> derivedFrom;
private final List<UnitXCType> unitTypes;
private final List<UnitXCGroupJump> 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<String> getDerivedFrom() {
return derivedFrom;
}
/**
* @param derivedFrom the derivedFrom to set
*/
public void setDerivedFrom(List<String> derivedFrom) {
this.derivedFrom.clear();
this.derivedFrom.addAll(derivedFrom);
}
/**
* @return the unit types.
*/
public List<UnitXCType> getUnitTypes() {
return unitTypes;
}
/**
* @param unitTypes the types to set.
*/
public void setUnitTypes(List<UnitXCType> 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<String> getDerivedFrom();
/**
* @return the groupJumps
*/
public List<UnitXCGroupJump> getGroupJumps() {
return groupJumps;
}
/**
* @param groupJumps the groupJumps to set
*/
public void setGroupJumps(List<UnitXCGroupJump> 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<UnitXCGroupJump> 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<String> getUnitTypeIds();
UnitXCType getUnitType(String id);
}

View file

@ -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<String> localUnitTypeIds() {
return Collections.emptyIterator();
}
@Override
public UnitXCType localUnitType(String id) {
return null;
}
}

View file

@ -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<String> localUnitTypeIds() {
Iterator<String> g = getParentGroup().getUnitTypeIds();
return new Iterator<String>() {
@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<Object> typeBuilder = new UnitXCTypeBuilder<>(this,result,(p,v) -> {});
typeBuilder
.setId(unitType.getId()+unitIdPostfix)
.setName(unitNamePrefix+unitType.getName())
.addTypeFlags(unitType.getTypeFlags());
for (int i=0;i<exponent;i++) {
typeBuilder.addToBaseConverterStep(new UnitXCConverterStepReference(unitType.getId(),true));
typeBuilder.addFromBaseConverterStep(new UnitXCConverterStepReference(unitType.getId(),false));
}
typeBuilder.build();
result.setUnitGroup(this);
return result;
}
/**
* @return the exponent
*/
public int getExponent() {
return exponent;
}
/**
* @return the unitIdPostfix
*/
public String getUnitIdPostfix() {
return unitIdPostfix;
}
/**
* @param unitIdPostfix the unitIdPostfix to set
*/
public void setUnitIdPostfix(String unitIdPostfix) {
this.unitIdPostfix = unitIdPostfix;
}
/**
* @return the unitNamePrefix
*/
public String getUnitNamePrefix() {
return unitNamePrefix;
}
/**
* @param unitNamePrefix the unitNamePrefix to set
*/
public void setUnitNamePrefix(String unitNamePrefix) {
this.unitNamePrefix = unitNamePrefix;
}
/**
* @return the parentGroup
*/
public UnitXCGroup getParentGroup() {
return parentGroup;
}
}

View file

@ -0,0 +1,180 @@
/*
* 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 ch.qos.logback.core.joran.conditional.IfAction;
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 UnitXCGroupCompoundPair extends AbstractUnitXCGroup {
public static final String PER_ID = "/";
public static final String PER_NAME = " per ";
private final UnitXCGroup parentGroup;
private final UnitXCGroup parentPerGroup;
public UnitXCGroupCompoundPair(UnitXCGroup parentGroup,UnitXCGroup parentPerGroup) {
this.parentGroup = Validate.notNull(parentGroup);
this.parentPerGroup = Validate.notNull(parentPerGroup);
}
@Override
public long localUnitTypeSize() {
return getParentGroup().getUnitTypeSize()*getParentPerGroup().getUnitTypeSize();
}
@Override
public Iterator<String> localUnitTypeIds() {
Iterator<String> groupIt = getParentGroup().getUnitTypeIds();
return new Iterator<String>() {
String groupId2;
Iterator<String> 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<units.length;i++) {
StringBuilder idGroup = new StringBuilder();
StringBuilder idGroupPer = new StringBuilder();
for (int ii=0;ii<i;ii++) {
idGroup.append(units[ii]);
if (ii+1<i) {
idGroup.append(PER_ID);
}
}
String checkExponent = null;
boolean checkExponentUse = false;
for (int ii=i;ii<units.length;ii++) {
if (checkExponent!=null && !checkExponent.equals(units[ii])) {
checkExponentUse = true;
}
checkExponent = units[ii];
idGroupPer.append(units[ii]);
if (ii+1<units.length) {
idGroupPer.append(PER_ID);
}
}
if (checkExponentUse) {
}
UnitXCType result = getUnitType(id,idGroup.toString(),idGroupPer.toString());
if (result != null) {
return result;
}
}
return null;
//String idGroup = id.substring(0,id.lastIndexOf(PER_ID)); // FIXME parse correctly see newton
//String idGroupPer = id.substring(id.lastIndexOf(PER_ID)+1);
}
private UnitXCType getUnitType(String id,String idGroup,String idGroupPer) {
// System.out.println("checking: "+idGroup+" and "+idGroupPer);
UnitXCType unitType = getParentGroup().getUnitType(idGroup);
if (unitType == null) {
return null;
}
UnitXCType perUnitType = getParentPerGroup().getUnitType(idGroupPer);
if (perUnitType == null) {
return null;
}
return createUnitType(id, unitType, perUnitType);
}
private UnitXCType createUnitType(String id,UnitXCType unitType,UnitXCType perUnitType) {
// TODO: add name/name alias
DefaultUnitXCType result = new DefaultUnitXCType();
UnitXCTypeBuilder<Object> 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;
}
}

View file

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

View file

@ -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<UnitXConverterStep> toBaseConverterSteps;
private final List<UnitXConverterStep> fromBaseConverterSteps;
private final List<String> typeFlags;
private final List<String> 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<UnitXConverterStep> getToBaseConverterSteps() {
return toBaseConverterSteps;
}
/**
* @param toBaseConverterSteps the toBaseConverterSteps to set
*/
public void setToBaseConverterSteps(List<UnitXConverterStep> toBaseConverterSteps) {
this.toBaseConverterSteps.clear();
this.toBaseConverterSteps.addAll(toBaseConverterSteps);
}
List<UnitXConverterStep> getToBaseConverterSteps();
/**
* @return the fromBaseConverterSteps
*/
public List<UnitXConverterStep> getFromBaseConverterSteps() {
return fromBaseConverterSteps;
}
/**
* @param fromBaseConverterSteps the fromBaseConverterSteps to set
*/
public void setFromBaseConverterSteps(List<UnitXConverterStep> fromBaseConverterSteps) {
this.fromBaseConverterSteps.clear();
this.fromBaseConverterSteps.addAll(fromBaseConverterSteps);
}
List<UnitXConverterStep> getFromBaseConverterSteps();
/**
* @return the typeFlags
*/
public List<String> getTypeFlags() {
return typeFlags;
}
/**
* @param typeFlags the typeFlags to set
*/
public void setTypeFlags(List<String> typeFlags) {
this.typeFlags.clear();
this.typeFlags.addAll(typeFlags);
}
List<String> getTypeFlags();
/**
* @return the websiteLinks
*/
public List<String> getWebsiteLinks() {
return websiteLinks;
}
/**
* @param websiteLinks the websiteLinks to set
*/
public void setWebsiteLinks(List<String> websiteLinks) {
this.websiteLinks.clear();
this.websiteLinks.addAll(websiteLinks);
}
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
}
List<String> getWebsiteLinks();
}

View file

@ -1,12 +0,0 @@
package net.forwardfire.unitxc.model;
import java.util.Iterator;
public interface UnitXCTypeGenerator {
long size();
Iterator<String> getUnitTypes();
UnitXCType getUnitType(String id);
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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