added groups and started on i18n
This commit is contained in:
parent
1701255350
commit
8751873145
|
@ -18,5 +18,11 @@
|
|||
<artifactId>commons-lang3</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -31,25 +31,26 @@ import net.forwardfire.unitxc.config.UnitXCConfigManager;
|
|||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.model.UnitXCConfig;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleSubstance;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleElectricCurrent;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleLength;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleLuminousIntensity;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleMass;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleTemperature;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleAcceleration;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleArea;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleAreaDensity;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleJerk;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleJounce;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleMassDensity;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleMolarConcentration;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleMolarVolume;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleSpecificVolume;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleSpeed;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleVolume;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleVolumetricFlow;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleMole;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleAmpere;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleMetre;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleCandela;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleKilogram;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleKelvin;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleSecond;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleMetrePerSecondSquared;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleSquareMetre;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleKilogramPerSquareMetre;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleMetrePerSecondCubed;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleMetrePerQuarticSecond;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleKilogramPerCubicMetre;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleMolePerCubicMetre;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleCubicMetrePerMole;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleNewtonPerSecond;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleCubicMetrePerKilogram;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleMetrePerSecond;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleCubicMetre;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleCubicMetrePerSecond;
|
||||
import net.forwardfire.unitxc.module.named.UnitXCModuleNewton;
|
||||
|
||||
/**
|
||||
|
@ -61,39 +62,40 @@ import net.forwardfire.unitxc.module.named.UnitXCModuleNewton;
|
|||
public final class UnitXCFactory {
|
||||
|
||||
private static final List<UnitXCConfigModule> DEFAULT_CONFIG_MODULES = Collections.unmodifiableList(Arrays.asList(
|
||||
new UnitXCModuleTemperature(),
|
||||
new UnitXCModuleElectricCurrent(),
|
||||
new UnitXCModuleLuminousIntensity(),
|
||||
new UnitXCModuleSubstance(),
|
||||
new UnitXCModuleLength(),
|
||||
new UnitXCModuleMass(),
|
||||
new UnitXCModuleTime(),
|
||||
new UnitXCModuleKelvin(),
|
||||
new UnitXCModuleAmpere(),
|
||||
new UnitXCModuleCandela(),
|
||||
new UnitXCModuleMole(),
|
||||
new UnitXCModuleMetre(),
|
||||
new UnitXCModuleKilogram(),
|
||||
new UnitXCModuleSecond(),
|
||||
|
||||
// currently ordered here
|
||||
new UnitXCModuleArea(),
|
||||
new UnitXCModuleVolume(),
|
||||
new UnitXCModuleSpeed(),
|
||||
new UnitXCModuleVolumetricFlow(),
|
||||
new UnitXCModuleAcceleration(),
|
||||
new UnitXCModuleJerk(),
|
||||
new UnitXCModuleJounce(),
|
||||
new UnitXCModuleSquareMetre(),
|
||||
new UnitXCModuleCubicMetre(),
|
||||
new UnitXCModuleMetrePerSecond(),
|
||||
new UnitXCModuleCubicMetrePerSecond(),
|
||||
new UnitXCModuleMetrePerSecondSquared(),
|
||||
new UnitXCModuleMetrePerSecondCubed(),
|
||||
new UnitXCModuleMetrePerQuarticSecond(),
|
||||
|
||||
// named
|
||||
new UnitXCModuleNewton(),
|
||||
|
||||
// more derived
|
||||
new UnitXCModuleAreaDensity(),
|
||||
new UnitXCModuleMassDensity(),
|
||||
new UnitXCModuleSpecificVolume(),
|
||||
new UnitXCModuleMolarConcentration(),
|
||||
new UnitXCModuleMolarVolume()
|
||||
new UnitXCModuleKilogramPerSquareMetre(),
|
||||
new UnitXCModuleKilogramPerCubicMetre(),
|
||||
new UnitXCModuleCubicMetrePerKilogram(),
|
||||
new UnitXCModuleMolePerCubicMetre(),
|
||||
new UnitXCModuleCubicMetrePerMole(),
|
||||
new UnitXCModuleNewtonPerSecond()
|
||||
|
||||
));
|
||||
|
||||
|
||||
protected UnitXCFactory() {
|
||||
}
|
||||
|
||||
|
||||
private static UnitXCConfig buildAll(UnitXCConfig config,List<UnitXCConfigModule> configInit) {
|
||||
UnitXCConfigBuilder builder = new UnitXCConfigBuilder(config);
|
||||
configInit.forEach(ci -> ci.configModule(builder));
|
||||
|
|
|
@ -23,9 +23,11 @@
|
|||
|
||||
package net.forwardfire.unitxc.config.builder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import net.forwardfire.unitxc.model.AbstractUnitXCGroup;
|
||||
import net.forwardfire.unitxc.model.DefaultUnitXCGroupQuantity;
|
||||
import net.forwardfire.unitxc.model.DefaultUnitXCType;
|
||||
|
||||
/**
|
||||
|
@ -48,22 +50,19 @@ abstract public class AbstractUnitXCGroupBuilder<P,T extends AbstractUnitXCGroup
|
|||
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 addQuantityId(String id) {
|
||||
return make((v) -> v.addQuantity(new DefaultUnitXCGroupQuantity(null,"group."+v.getId()+".quantity",id)));
|
||||
}
|
||||
|
||||
public B addQuantityIds(String...ids) {
|
||||
Arrays.asList(ids).forEach(id -> addQuantityId(id));
|
||||
return getBuilder();
|
||||
}
|
||||
|
||||
// public B addDerivedFrom(String fromId) {
|
||||
// return make((v) -> v.addDerivedFrom(fromId));
|
||||
// }
|
||||
|
|
|
@ -78,16 +78,12 @@ public abstract class AbstractUnitXCTypeBuilder<P,B> extends AbstractUnitXCBuild
|
|||
return make((v) -> v.setAliasOfType(aliasOfType));
|
||||
}
|
||||
|
||||
public B addWebsiteWiki(String websiteLink) {
|
||||
return addWebsiteLink("https://en.wikipedia.org/wiki/"+websiteLink);
|
||||
public B setWebLinkWiki(String websiteLink) {
|
||||
return setWebLink(UnitXCConfigBuilder.WIKI_BASE_URL+websiteLink);
|
||||
}
|
||||
|
||||
public B addWebsiteLink(String websiteLink) {
|
||||
return make((v) -> v.getWebsiteLinks().add(websiteLink));
|
||||
}
|
||||
|
||||
public B addWebsiteLinks(Collection<String> websiteLinks) {
|
||||
return make((v) -> v.getWebsiteLinks().addAll(websiteLinks));
|
||||
public B setWebLink(String websiteLink) {
|
||||
return make((v) -> v.setWebLink(websiteLink));
|
||||
}
|
||||
|
||||
public B addTypeFlag(String flag) {
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
|
||||
package net.forwardfire.unitxc.config.builder;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.unitxc.model.AbstractUnitXCGroup;
|
||||
|
@ -31,6 +35,7 @@ import net.forwardfire.unitxc.model.UnitXCGroup;
|
|||
import net.forwardfire.unitxc.model.UnitXCGroupBase;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupCompoundExponent;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair;
|
||||
import net.forwardfire.unitxc.model.UnitXCResourceBundle;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -44,26 +49,41 @@ public class UnitXCConfigBuilder {
|
|||
public static final String TYPE_FLAG_IMPERIAL_EXTRA = "IMPERIAL_EXTRA";
|
||||
public static final String TYPE_FLAG_ALIAS = "ALIAS";
|
||||
|
||||
public static final String WIKI_BASE_URL = "https://en.wikipedia.org/wiki/";
|
||||
|
||||
private final UnitXCConfig config;
|
||||
private final UnitXCResourceBundle bundle;
|
||||
|
||||
public UnitXCConfigBuilder(UnitXCConfig config) {
|
||||
this.config = Validate.notNull(config);
|
||||
this.bundle = new UnitXCResourceBundle();
|
||||
this.initBundle();
|
||||
}
|
||||
|
||||
private void initBundle() {
|
||||
config.getLanguages().add(Locale.forLanguageTag(""));
|
||||
for (Locale l:config.getLanguages()) {
|
||||
String language = l.toLanguageTag();
|
||||
ResourceBundle b = ResourceBundle.getBundle("net.forwardfire.unitxc.UnitXCBundle", l);
|
||||
System.out.println("loading bundle language: "+language+" baseBundle: "+b.getBaseBundleName()+" size: "+b.keySet().size());
|
||||
b.keySet().forEach(k -> bundle.addData(language, k, b.getString(k)));
|
||||
}
|
||||
}
|
||||
|
||||
protected UnitXCConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public UnitXCGroupBaseBuilder createUnitGroupBase() {
|
||||
return new UnitXCGroupBaseBuilder(this, new UnitXCGroupBase(), (p,v) -> p.getConfig().addUnitGroup(v));
|
||||
public UnitXCGroupBaseBuilder createUnitGroupBase(String groupId) {
|
||||
return new UnitXCGroupBaseBuilder(this, new UnitXCGroupBase(bundle,groupId), (p,v) -> p.getConfig().addUnitGroup(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 UnitXCGroupCompoundPairBuilder createUnitGroupCompoundPair(String groupId, String parentGroupId, String parentPerGroupId) {
|
||||
return new UnitXCGroupCompoundPairBuilder(this, new UnitXCGroupCompoundPair(bundle,groupId,findGroup(parentGroupId),findGroup(parentPerGroupId)), (p,v) -> p.getConfig().addUnitGroup(v));
|
||||
}
|
||||
|
||||
public UnitXCGroupCompoundExponentBuilder createUnitGroupCompoundExponent(String parentGroupId, int exponent) {
|
||||
return new UnitXCGroupCompoundExponentBuilder(this, new UnitXCGroupCompoundExponent(findGroup(parentGroupId),exponent), (p,v) -> p.getConfig().addUnitGroup(v));
|
||||
public UnitXCGroupCompoundExponentBuilder createUnitGroupCompoundExponent(String groupId, String parentGroupId, int exponent) {
|
||||
return new UnitXCGroupCompoundExponentBuilder(this, new UnitXCGroupCompoundExponent(bundle,groupId,findGroup(parentGroupId),exponent), (p,v) -> p.getConfig().addUnitGroup(v));
|
||||
}
|
||||
|
||||
public UnitXCGroupExtendBuilder extendUnitGroup(String groupId) {
|
||||
|
|
|
@ -88,5 +88,25 @@ public class UnitXCGroupCompoundPairBuilder extends AbstractUnitXCGroupBuilder<U
|
|||
.divide(new UnitXConverterStepValueNamedParameter(value.getId()+"_"+perGroup.getId()))
|
||||
.build()
|
||||
.build();
|
||||
|
||||
|
||||
//FIXME
|
||||
// m/s -> s
|
||||
createGroupJump(perGroup.getId())
|
||||
.addJumpParameter(value.getId()+"_"+group.getId(),group.getId())
|
||||
.createToGroupConverterSteps()
|
||||
.multiply(new UnitXConverterStepValueNamedParameter(value.getId()+"_"+group.getId()))
|
||||
.build()
|
||||
.build();
|
||||
|
||||
// s -> m/s
|
||||
getParent().extendUnitGroup(perGroup.getId())
|
||||
.createGroupJump(value.getId())
|
||||
.addJumpParameter(value.getId()+"_"+group.getId(),group.getId())
|
||||
.createToGroupConverterSteps()
|
||||
.divide(new UnitXConverterStepValueNamedParameter(value.getId()+"_"+group.getId()))
|
||||
.build()
|
||||
.build();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class UnitXCTypeSIPrefixBuilder<P> extends AbstractUnitXCTypeBuilder<P,Un
|
|||
.setId(v.getId())
|
||||
.setName(v.getName())
|
||||
.setNamePlural(v.getNamePlural())
|
||||
.addWebsiteLinks(v.getWebsiteLinks())
|
||||
.setWebLink(v.getWebLink())
|
||||
.addTypeFlags(v.getTypeFlags())
|
||||
.addFromBaseConverterSteps(v.getFromBaseConverterSteps())
|
||||
.addToBaseConverterSteps(v.getToBaseConverterSteps())
|
||||
|
|
|
@ -212,9 +212,9 @@ public final class UnitXConverterEngine {
|
|||
return mathContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXCManager getUnitManager() {
|
||||
return manager;
|
||||
}
|
||||
// @Override
|
||||
// public UnitXCManager getUnitManager() {
|
||||
// return manager;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,24 +38,27 @@ import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
|||
*/
|
||||
abstract public class AbstractUnitXCGroup implements UnitXCGroup {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String description;
|
||||
private final String id;
|
||||
private final UnitXCResourceValue name;
|
||||
private final UnitXCResourceValue description;
|
||||
private String baseTypeId;
|
||||
private final List<UnitXCGroupQuantity> quantities;
|
||||
private final List<String> derivedFrom;
|
||||
private final List<UnitXCType> unitTypes;
|
||||
private final List<UnitXCGroupJump> groupJumps;
|
||||
|
||||
public AbstractUnitXCGroup() {
|
||||
public AbstractUnitXCGroup(UnitXCResourceBundle bundle, String id) {
|
||||
quantities = new ArrayList<>();
|
||||
derivedFrom = new ArrayList<>();
|
||||
unitTypes = new ArrayList<>();
|
||||
groupJumps = new ArrayList<>();
|
||||
this.name = new DefaultUnitXCResourceValue(bundle,"group."+id+".name");
|
||||
this.description = new DefaultUnitXCResourceValue(bundle,"group."+id+".description");
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -114,41 +117,21 @@ abstract public class AbstractUnitXCGroup implements UnitXCGroup {
|
|||
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() {
|
||||
public UnitXCResourceValue getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription() {
|
||||
public UnitXCResourceValue getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description the description to set
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the baseTypeId
|
||||
*/
|
||||
|
@ -163,6 +146,17 @@ abstract public class AbstractUnitXCGroup implements UnitXCGroup {
|
|||
this.baseTypeId = baseTypeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the quantities of the group.
|
||||
*/
|
||||
public List<UnitXCGroupQuantity> getQuantities() {
|
||||
return quantities;
|
||||
}
|
||||
|
||||
public void addQuantity(UnitXCGroupQuantity quantity) {
|
||||
this.quantities.add(quantity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the derivedFrom
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* The unit group quantity.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 31, 2016
|
||||
*/
|
||||
public class DefaultUnitXCGroupQuantity implements UnitXCGroupQuantity {
|
||||
|
||||
private final String id;
|
||||
private final UnitXCResourceValue name;
|
||||
private final UnitXCResourceValue wikiLink;
|
||||
|
||||
public DefaultUnitXCGroupQuantity(UnitXCResourceBundle bundle, String parentKey, String id) {
|
||||
this.name = new DefaultUnitXCResourceValue(bundle,parentKey+"."+id+".name");
|
||||
this.wikiLink = new DefaultUnitXCResourceValue(bundle,parentKey+"."+id+".wikiLink");
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXCResourceValue getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXCResourceValue getWikiLink() {
|
||||
return wikiLink;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The resource value wrapper holder
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 31, 2016
|
||||
*/
|
||||
public class DefaultUnitXCResourceValue implements UnitXCResourceValue {
|
||||
|
||||
private final UnitXCResourceBundle bundle;
|
||||
private final String bundleKey;
|
||||
|
||||
public DefaultUnitXCResourceValue(UnitXCResourceBundle bundle, String bundleKey) {
|
||||
super();
|
||||
this.bundle = bundle;
|
||||
this.bundleKey = bundleKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBundleKey() {
|
||||
return bundleKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLanguages() {
|
||||
return bundle.getValueLanguages(getBundleKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String language) {
|
||||
return bundle.getValue(language, getBundleKey());
|
||||
}
|
||||
}
|
|
@ -44,14 +44,13 @@ public class DefaultUnitXCType implements UnitXCType {
|
|||
private String namePlural;
|
||||
private String aliasOfType;
|
||||
private UnitXCGroup unitGroup;
|
||||
private String weblink;
|
||||
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<>();
|
||||
}
|
||||
|
@ -187,19 +186,18 @@ public class DefaultUnitXCType implements UnitXCType {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the websiteLinks
|
||||
* @return the weblink
|
||||
*/
|
||||
@Override
|
||||
public List<String> getWebsiteLinks() {
|
||||
return websiteLinks;
|
||||
public String getWebLink() {
|
||||
return weblink;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param websiteLinks the websiteLinks to set
|
||||
* @param webLink the webLink to set
|
||||
*/
|
||||
public void setWebsiteLinks(List<String> websiteLinks) {
|
||||
this.websiteLinks.clear();
|
||||
this.websiteLinks.addAll(websiteLinks);
|
||||
public void setWebLink(String weblink) {
|
||||
this.weblink = weblink;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,6 +25,7 @@ package net.forwardfire.unitxc.model;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
|
@ -38,9 +39,11 @@ public class UnitXCConfig {
|
|||
|
||||
private UnitXCRounding rounding;
|
||||
private final List<UnitXCGroup> unitGroups;
|
||||
private final List<Locale> languages;
|
||||
|
||||
public UnitXCConfig() {
|
||||
unitGroups = new ArrayList<>();
|
||||
languages = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,17 +67,17 @@ public class UnitXCConfig {
|
|||
return unitGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unitGroups the groups to set.
|
||||
*/
|
||||
public void setUnitGroups(List<AbstractUnitXCGroup> groups) {
|
||||
this.unitGroups.clear();
|
||||
groups.forEach(group -> addUnitGroup(group));
|
||||
}
|
||||
|
||||
public void addUnitGroup(AbstractUnitXCGroup group) {
|
||||
Validate.notNull(group);
|
||||
group.validate();
|
||||
unitGroups.add(group);
|
||||
}
|
||||
|
||||
public List<Locale> getLanguages() {
|
||||
return languages;
|
||||
}
|
||||
|
||||
public void addLanguage(Locale language) {
|
||||
languages.add(Validate.notNull(language));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,18 +42,23 @@ public interface UnitXCGroup {
|
|||
/**
|
||||
* @return the name
|
||||
*/
|
||||
String getName();
|
||||
UnitXCResourceValue getName();
|
||||
|
||||
/**
|
||||
* @return the description
|
||||
*/
|
||||
String getDescription();
|
||||
UnitXCResourceValue getDescription();
|
||||
|
||||
/**
|
||||
* @return the baseTypeId
|
||||
*/
|
||||
String getBaseTypeId();
|
||||
|
||||
/**
|
||||
* @return the quantities of the group.
|
||||
*/
|
||||
List<UnitXCGroupQuantity> getQuantities();
|
||||
|
||||
/**
|
||||
* @return the derivedFrom
|
||||
*/
|
||||
|
|
|
@ -34,10 +34,10 @@ import java.util.Iterator;
|
|||
*/
|
||||
public class UnitXCGroupBase extends AbstractUnitXCGroup {
|
||||
|
||||
public UnitXCGroupBase() {
|
||||
|
||||
public UnitXCGroupBase(UnitXCResourceBundle bundle, String id) {
|
||||
super(bundle, id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long localUnitTypeSize() {
|
||||
return 0L;
|
||||
|
|
|
@ -43,7 +43,8 @@ public class UnitXCGroupCompoundExponent extends AbstractUnitXCGroup {
|
|||
private String unitIdPostfix;
|
||||
private String unitNamePrefix;
|
||||
|
||||
public UnitXCGroupCompoundExponent(UnitXCGroup parentGroup,int exponent) {
|
||||
public UnitXCGroupCompoundExponent(UnitXCResourceBundle bundle, String id,UnitXCGroup parentGroup,int exponent) {
|
||||
super(bundle, id);
|
||||
this.parentGroup = Validate.notNull(parentGroup);
|
||||
this.exponent = exponent;
|
||||
Validate.isTrue(exponent > 1);
|
||||
|
@ -89,8 +90,8 @@ public class UnitXCGroupCompoundExponent extends AbstractUnitXCGroup {
|
|||
.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.addToBaseConverterStep(new UnitXCConverterStepReference(unitType,true));
|
||||
typeBuilder.addFromBaseConverterStep(new UnitXCConverterStepReference(unitType,false));
|
||||
}
|
||||
typeBuilder.build();
|
||||
result.setUnitGroup(this);
|
||||
|
|
|
@ -27,7 +27,6 @@ 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;
|
||||
|
||||
|
@ -45,7 +44,8 @@ public class UnitXCGroupCompoundPair extends AbstractUnitXCGroup {
|
|||
private final UnitXCGroup parentGroup;
|
||||
private final UnitXCGroup parentPerGroup;
|
||||
|
||||
public UnitXCGroupCompoundPair(UnitXCGroup parentGroup,UnitXCGroup parentPerGroup) {
|
||||
public UnitXCGroupCompoundPair(UnitXCResourceBundle bundle, String id,UnitXCGroup parentGroup,UnitXCGroup parentPerGroup) {
|
||||
super(bundle, id);
|
||||
this.parentGroup = Validate.notNull(parentGroup);
|
||||
this.parentPerGroup = Validate.notNull(parentPerGroup);
|
||||
}
|
||||
|
@ -88,6 +88,7 @@ public class UnitXCGroupCompoundPair extends AbstractUnitXCGroup {
|
|||
// if (!id.contains(PER_ID)) {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
String[] units = id.split(PER_ID);
|
||||
if (units.length < 2) {
|
||||
return null;
|
||||
|
@ -154,10 +155,10 @@ public class UnitXCGroupCompoundPair extends AbstractUnitXCGroup {
|
|||
.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.addToBaseConverterStep(new UnitXCConverterStepReference(unitType,true));
|
||||
typeBuilder.addToBaseConverterStep(new UnitXCConverterStepReference(perUnitType,false));
|
||||
typeBuilder.addFromBaseConverterStep(new UnitXCConverterStepReference(perUnitType,true));
|
||||
typeBuilder.addFromBaseConverterStep(new UnitXCConverterStepReference(unitType,false));
|
||||
typeBuilder.build();
|
||||
result.setUnitGroup(this);
|
||||
return result;
|
||||
|
|
|
@ -23,11 +23,8 @@
|
|||
|
||||
package net.forwardfire.unitxc.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStep;
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.model;
|
||||
|
||||
/**
|
||||
* The unit group quantity.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 31, 2016
|
||||
*/
|
||||
public interface UnitXCGroupQuantity {
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
UnitXCResourceValue getName();
|
||||
|
||||
/**
|
||||
* @return the wikilink
|
||||
*/
|
||||
UnitXCResourceValue getWikiLink();
|
||||
}
|
|
@ -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.model;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The unit group source.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Dec 4, 2016
|
||||
*/
|
||||
public interface UnitXCGroupSource {
|
||||
|
||||
/**
|
||||
* @return the derivedFrom
|
||||
*/
|
||||
List<String> getDerivedFrom();
|
||||
|
||||
/**
|
||||
* @return the totalUnitTypes
|
||||
*/
|
||||
long getUnitTypeSize();
|
||||
|
||||
Iterator<String> getUnitTypeIds();
|
||||
|
||||
UnitXCType getUnitType(String id);
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The resource value wrapper
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 31, 2016
|
||||
*/
|
||||
public @interface UnitXCModule {
|
||||
|
||||
String groupId();
|
||||
|
||||
String[] dependencies();
|
||||
|
||||
// public @interface UnitXCModuleDependency {
|
||||
// String groupId();
|
||||
// }
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* 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.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* The resource value wrapper
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 31, 2016
|
||||
*/
|
||||
public class UnitXCResourceBundle {
|
||||
|
||||
private Map<String,Map<String,String>> data = new HashMap<>();
|
||||
|
||||
// FIXME: not public or interface or x
|
||||
public void addData(String language,String key,String value) {
|
||||
Map<String,String> ld = data.get(language);
|
||||
if (ld == null) {
|
||||
ld = new HashMap<>();
|
||||
data.put(language, ld);
|
||||
}
|
||||
ld.put(key, value);
|
||||
}
|
||||
|
||||
public List<String> getLanguages() {
|
||||
return new ArrayList<>(data.keySet());
|
||||
}
|
||||
|
||||
public List<String> getValueLanguages(String key) {
|
||||
List<String> result = new ArrayList<>();
|
||||
data.forEach((k,v) -> {
|
||||
if (v.containsKey(key)) {
|
||||
result.add(k);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getValue(String lang,String key) {
|
||||
if (lang.isEmpty()) {
|
||||
lang = "und"; // undefined
|
||||
}
|
||||
return Validate.notNull(Validate.notNull(data.get(lang),"Could not find langauge: "+lang).get(key),"Could not find key: "+key);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The resource value wrapper
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 31, 2016
|
||||
*/
|
||||
public interface UnitXCResourceValue {
|
||||
|
||||
/**
|
||||
* @return the bundle key.
|
||||
*/
|
||||
String getBundleKey();
|
||||
|
||||
List<String> getLanguages();
|
||||
|
||||
String getValue(String language);
|
||||
}
|
|
@ -78,7 +78,7 @@ public interface UnitXCType {
|
|||
List<String> getTypeFlags();
|
||||
|
||||
/**
|
||||
* @return the websiteLinks
|
||||
* @return the weblink
|
||||
*/
|
||||
List<String> getWebsiteLinks();
|
||||
String getWebLink();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
package net.forwardfire.unitxc.model.step;
|
||||
|
||||
public class RuleStepCode {
|
||||
|
||||
private String id;
|
||||
private String type;
|
||||
private String style;
|
||||
private String code;
|
||||
private String matcher;
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the type to set
|
||||
*/
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the style
|
||||
*/
|
||||
public String getStyle() {
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param style the style to set
|
||||
*/
|
||||
public void setStyle(String style) {
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the code
|
||||
*/
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param code the code to set
|
||||
*/
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the matcher
|
||||
*/
|
||||
public String getMatcher() {
|
||||
return matcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param matcher the matcher to set
|
||||
*/
|
||||
public void setMatcher(String matcher) {
|
||||
this.matcher = matcher;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
package net.forwardfire.unitxc.model.step;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
public class RuleStepCodePrinter {
|
||||
|
||||
private final StringBuilder result = new StringBuilder();
|
||||
private final RuleStepCodeStyle codeStyle;
|
||||
private int indentLevel = 0;
|
||||
|
||||
public RuleStepCodePrinter(RuleStepCodeStyle codeStyle) {
|
||||
this.codeStyle = Validate.notNull(codeStyle);
|
||||
}
|
||||
|
||||
public static String print(RuleStepCodeStyle codeStyle, List<UnitXConverterStep> steps, String id) {
|
||||
RuleStepCodePrinter printer = new RuleStepCodePrinter(codeStyle);
|
||||
printer.line(); // make copy/paste easy
|
||||
if (printer.isEnglish()) {
|
||||
printer.line("Description of: ",id);
|
||||
printer.line();
|
||||
} else {
|
||||
printer.line("code['",id,"'] = function(ctx) {");
|
||||
printer.pushIndent();
|
||||
}
|
||||
printer.printSteps(steps);
|
||||
if (printer.isJavascript()) {
|
||||
printer.popIndent();
|
||||
printer.line("}");
|
||||
}
|
||||
return printer.getResult();
|
||||
}
|
||||
|
||||
public void printSteps(List<UnitXConverterStep> steps) {
|
||||
steps.forEach(s -> s.toRuleCode(this));
|
||||
}
|
||||
|
||||
public String getResult() {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public RuleStepCodeStyle getCodeStyle() {
|
||||
return codeStyle;
|
||||
}
|
||||
|
||||
public boolean isEnglish() {
|
||||
return RuleStepCodeStyle.ENGLISH.equals(getCodeStyle());
|
||||
}
|
||||
|
||||
public boolean isJavascript() {
|
||||
return RuleStepCodeStyle.JAVASCRIPT.equals(getCodeStyle());
|
||||
}
|
||||
/*
|
||||
public boolean isXslt() {
|
||||
return RuleStepCodeType.XSLT.equals(getCodeStyle());
|
||||
}
|
||||
*/
|
||||
public void pushIndent() {
|
||||
indentLevel++;
|
||||
}
|
||||
|
||||
public void popIndent() {
|
||||
if (indentLevel > 0) {
|
||||
indentLevel--;
|
||||
}
|
||||
}
|
||||
|
||||
private void appendIndent() {
|
||||
for (int i = 0;i < indentLevel*4; i++) {
|
||||
appendSpace();
|
||||
}
|
||||
}
|
||||
|
||||
public void line(String...text) {
|
||||
lineStart(text);
|
||||
lineEnd();
|
||||
}
|
||||
|
||||
public void lineStart(String...text) {
|
||||
appendIndent();
|
||||
append(text);
|
||||
}
|
||||
|
||||
public void lineEnd(String...text) {
|
||||
append(text);
|
||||
result.append(StringUtils.LF);
|
||||
}
|
||||
|
||||
public void append(String...texts) {
|
||||
Arrays.asList(texts).forEach(text -> result.append(text));
|
||||
}
|
||||
|
||||
public void appendJS(String...texts) {
|
||||
if (isJavascript()) {
|
||||
append(texts);
|
||||
}
|
||||
}
|
||||
|
||||
public void appendSpace() {
|
||||
result.append(StringUtils.SPACE);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package net.forwardfire.unitxc.model.step;
|
||||
|
||||
public enum RuleStepCodeStyle {
|
||||
ENGLISH,
|
||||
JAVASCRIPT
|
||||
;
|
||||
}
|
|
@ -17,6 +17,23 @@ public class UnitXCConverterStepAutoRounding extends AbstractUnitXConverterStep
|
|||
setResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toRuleCode(RuleStepCodePrinter printer) {
|
||||
if (printer.isEnglish()) {
|
||||
printer.lineStart("Rounding ");
|
||||
getOperand().toRuleCodeRead(printer);
|
||||
printer.append(" to ");
|
||||
getResult().toRuleCodeRead(printer);
|
||||
printer.lineEnd(".");
|
||||
return;
|
||||
}
|
||||
printer.lineStart();
|
||||
getResult().toRuleCodeWrite(printer);
|
||||
printer.append(" = ");
|
||||
getOperand().toRuleCodeRead(printer);
|
||||
printer.lineEnd();
|
||||
}
|
||||
|
||||
private double round(double value,double prevValue) {
|
||||
String valueStr = Double.toString(value);
|
||||
String valueOrgStr = Double.toString(prevValue);
|
||||
|
|
|
@ -52,6 +52,74 @@ public class UnitXCConverterStepCondition extends AbstractUnitXConverterStep {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toRuleCode(RuleStepCodePrinter printer) {
|
||||
if (printer.isEnglish()) {
|
||||
printer.lineStart("If ");
|
||||
toPseudoCodeExpression(printer);
|
||||
printer.lineEnd(" then;");
|
||||
printer.pushIndent();
|
||||
printer.printSteps(getConditionalSteps());
|
||||
printer.popIndent();
|
||||
// if (!stepsFalse.isEmpty()) {
|
||||
// printer.line("Else do;");
|
||||
// printer.pushIndent();
|
||||
// printer.printSteps(getStepsFalse());
|
||||
// printer.popIndent();
|
||||
// }
|
||||
printer.line(); // for readablity
|
||||
return;
|
||||
}
|
||||
printer.lineStart("if");
|
||||
toPseudoCodeExpression(printer);
|
||||
printer.lineEnd("{");
|
||||
printer.pushIndent();
|
||||
printer.printSteps(getConditionalSteps());
|
||||
printer.popIndent();
|
||||
// if (stepsFalse.isEmpty()) {
|
||||
// printer.line("}");
|
||||
// } else {
|
||||
// printer.line("} else {");
|
||||
// printer.pushIndent();
|
||||
// printer.printSteps(getStepsFalse());
|
||||
// printer.popIndent();
|
||||
// printer.line("}");
|
||||
// }
|
||||
}
|
||||
|
||||
public void toPseudoCodeExpression(RuleStepCodePrinter printer/*, List<RuleStepConditionExpression> expressions*/) {
|
||||
printer.appendJS(" ( ");
|
||||
getEquality().toRuleCode(printer, operandA, operandB);
|
||||
printer.appendJS(" ) ");
|
||||
|
||||
// Iterator<RuleStepConditionExpression> i = expressions.iterator();
|
||||
// if (!i.hasNext()) {
|
||||
// return;
|
||||
// }
|
||||
// printer.appendJS(" ( ");
|
||||
// while (i.hasNext()) {
|
||||
// RuleStepConditionExpression ex = i.next();
|
||||
// ex.getEquality().toRuleCode(printer, ex.getOperandA(), ex.getOperandB());
|
||||
// // TODO: this not yet looks correctly,,.somewhere here?
|
||||
// if (i.hasNext()) {
|
||||
// if (printer.isEnglish()) {
|
||||
// printer.append(" and ");
|
||||
// } else {
|
||||
// printer.append(" && ");
|
||||
// }
|
||||
// }
|
||||
// if (!ex.getExpressions().isEmpty()) {
|
||||
// if (printer.isEnglish()) {
|
||||
// printer.append(" or ");
|
||||
// } else {
|
||||
// printer.append(" || ");
|
||||
// }
|
||||
// toPseudoCodeExpression(printer,ex.getExpressions());
|
||||
// }
|
||||
// }
|
||||
// printer.appendJS(" ) ");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the equality
|
||||
*/
|
||||
|
|
|
@ -2,21 +2,29 @@ package net.forwardfire.unitxc.model.step;
|
|||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead;
|
||||
|
||||
public enum UnitXCConverterStepConditionEquality {
|
||||
|
||||
EQUALS ((l,r) -> l.compareTo(r) == 0, (l,r) -> l.compareTo(r) == 0, (l,r) -> l.compareTo(r) == 0),
|
||||
NOT_EQUALS ((l,r) -> l.compareTo(r) != 0, (l,r) -> l.compareTo(r) != 0, (l,r) -> l.compareTo(r) != 0),
|
||||
GREATER_THEN ((l,r) -> l.compareTo(r) > 0, (l,r) -> l.compareTo(r) > 0, (l,r) -> l.compareTo(r) > 0),
|
||||
LESSER_THEN ((l,r) -> l.compareTo(r) < 0, (l,r) -> l.compareTo(r) < 0, (l,r) -> l.compareTo(r) < 0),
|
||||
GREATER_OR_EQUALS ((l,r) -> l.compareTo(r) >= 0, (l,r) -> l.compareTo(r) >= 0, (l,r) -> l.compareTo(r) >= 0),
|
||||
LESSER_OR_EQUALS ((l,r) -> l.compareTo(r) <= 0, (l,r) -> l.compareTo(r) <= 0, (l,r) -> l.compareTo(r) <= 0),
|
||||
EQUALS ("===",(l,r) -> l.compareTo(r) == 0, (l,r) -> l.compareTo(r) == 0, (l,r) -> l.compareTo(r) == 0),
|
||||
NOT_EQUALS ("!==",(l,r) -> l.compareTo(r) != 0, (l,r) -> l.compareTo(r) != 0, (l,r) -> l.compareTo(r) != 0),
|
||||
GREATER_THEN (">", (l,r) -> l.compareTo(r) > 0, (l,r) -> l.compareTo(r) > 0, (l,r) -> l.compareTo(r) > 0),
|
||||
LESSER_THEN ("<", (l,r) -> l.compareTo(r) < 0, (l,r) -> l.compareTo(r) < 0, (l,r) -> l.compareTo(r) < 0),
|
||||
GREATER_OR_EQUALS (">=",(l,r) -> l.compareTo(r) >= 0, (l,r) -> l.compareTo(r) >= 0, (l,r) -> l.compareTo(r) >= 0),
|
||||
LESSER_OR_EQUALS ("<=",(l,r) -> l.compareTo(r) <= 0, (l,r) -> l.compareTo(r) <= 0, (l,r) -> l.compareTo(r) <= 0),
|
||||
;
|
||||
|
||||
private final BiFunction<Double,Double,Boolean> opertionDouble;
|
||||
private final String jsCode;
|
||||
private final String enCode;
|
||||
private final BiFunction<Double,Double,Boolean> opertionDouble; // TODO: convert to IntPredicate
|
||||
private final BiFunction<Integer,Integer,Boolean> opertionInteger;
|
||||
private final BiFunction<String,String,Boolean> opertionString;
|
||||
|
||||
private UnitXCConverterStepConditionEquality(BiFunction<Double,Double,Boolean> opertionDouble,BiFunction<Integer,Integer,Boolean> opertionInteger,BiFunction<String,String,Boolean> opertionString) {
|
||||
private UnitXCConverterStepConditionEquality(String jsCode, BiFunction<Double,Double,Boolean> opertionDouble,BiFunction<Integer,Integer,Boolean> opertionInteger,BiFunction<String,String,Boolean> opertionString) {
|
||||
this.jsCode = jsCode;
|
||||
this.enCode = name().toLowerCase().replaceAll("_", StringUtils.SPACE);
|
||||
this.opertionDouble = opertionDouble;
|
||||
this.opertionInteger = opertionInteger;
|
||||
this.opertionString = opertionString;
|
||||
|
@ -34,4 +42,22 @@ public enum UnitXCConverterStepConditionEquality {
|
|||
}
|
||||
throw new IllegalArgumentException("Unknown typeClass: "+left.getClass());
|
||||
}
|
||||
|
||||
public void toRuleCode(RuleStepCodePrinter printer, UnitXConverterStepValueRead operandA, UnitXConverterStepValueRead operandB) {
|
||||
if (printer.isEnglish()) {
|
||||
operandA.toRuleCodeRead(printer);
|
||||
printer.append(" is ", enCode);
|
||||
if (jsCode.contains("=")) {
|
||||
printer.append(" to");
|
||||
}
|
||||
printer.appendSpace();
|
||||
operandB.toRuleCodeRead(printer);
|
||||
return;
|
||||
}
|
||||
operandA.toRuleCodeRead(printer);
|
||||
printer.appendSpace();
|
||||
printer.append(jsCode);
|
||||
printer.appendSpace();
|
||||
operandB.toRuleCodeRead(printer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,23 @@ public class UnitXCConverterStepOperation extends AbstractUnitXConverterStep {
|
|||
result.valueWrite(ctx, operator.execute(operandA.valueRead(ctx),operandB.valueRead(ctx)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toRuleCode(RuleStepCodePrinter printer) {
|
||||
if (printer.isEnglish()) {
|
||||
printer.lineStart("Update ");
|
||||
getResult().toRuleCodeWrite(printer);
|
||||
printer.append(" with value from ");
|
||||
getOperator().toRuleCode(printer, getOperandA(), getOperandB());
|
||||
printer.lineEnd(".");
|
||||
return;
|
||||
}
|
||||
printer.lineStart();
|
||||
getResult().toRuleCodeWrite(printer);
|
||||
printer.append(" = ");
|
||||
getOperator().toRuleCode(printer, getOperandA(), getOperandB());
|
||||
printer.lineEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the operator
|
||||
*/
|
||||
|
|
|
@ -6,22 +6,28 @@ import java.util.function.BinaryOperator;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead;
|
||||
|
||||
public enum UnitXCConverterStepOperationOperator {
|
||||
|
||||
ADD ((l,r) -> l+r, (l,r) -> l+r, (l,r) -> l+r),
|
||||
SUBTRACT ((l,r) -> l-r, (l,r) -> l-r, (l,r) -> l.replaceAll(l, StringUtils.EMPTY)),
|
||||
MULTIPLY ((l,r) -> l*r, (l,r) -> l*r, null),
|
||||
DIVIDE ((l,r) -> l/r, (l,r) -> l/r, null),
|
||||
POWER ((l,r) -> p(l,r), (l,r) -> p(l,r), null),
|
||||
AND (null, (l,r) -> l & r, null),
|
||||
OR (null, (l,r) -> l | r, null),
|
||||
ADD ("+",(l,r) -> l+r, (l,r) -> l+r, (l,r) -> l+r),
|
||||
SUBTRACT ("-",(l,r) -> l-r, (l,r) -> l-r, (l,r) -> l.replaceAll(l, StringUtils.EMPTY)),
|
||||
MULTIPLY ("*",(l,r) -> l*r, (l,r) -> l*r, null),
|
||||
DIVIDE ("/",(l,r) -> l/r, (l,r) -> l/r, null),
|
||||
POWER ("pow",(l,r) -> p(l,r), (l,r) -> p(l,r), null),
|
||||
AND ("&", null, (l,r) -> l & r, null),
|
||||
OR ("|",null, (l,r) -> l | r, null),
|
||||
;
|
||||
|
||||
private final String jsCode;
|
||||
private final String enCode;
|
||||
private final BinaryOperator<Double> opertionDouble;
|
||||
private final BinaryOperator<Integer> opertionInteger;
|
||||
private final BinaryOperator<String> opertionString;
|
||||
|
||||
private UnitXCConverterStepOperationOperator(BinaryOperator<Double> opertionDouble,BinaryOperator<Integer> opertionInteger,BinaryOperator<String> opertionString) {
|
||||
private UnitXCConverterStepOperationOperator(String jsCode, BinaryOperator<Double> opertionDouble,BinaryOperator<Integer> opertionInteger,BinaryOperator<String> opertionString) {
|
||||
this.jsCode = jsCode;
|
||||
this.enCode = name().toLowerCase();
|
||||
this.opertionDouble = opertionDouble;
|
||||
this.opertionInteger = opertionInteger;
|
||||
this.opertionString = opertionString;
|
||||
|
@ -54,4 +60,27 @@ public enum UnitXCConverterStepOperationOperator {
|
|||
}
|
||||
throw new IllegalArgumentException("Unknown typeClass: "+left.getClass());
|
||||
}
|
||||
|
||||
public void toRuleCode(RuleStepCodePrinter printer, UnitXConverterStepValueRead operandA, UnitXConverterStepValueRead operandB) {
|
||||
if (printer.isEnglish()) {
|
||||
printer.append(enCode," ");
|
||||
operandA.toRuleCodeRead(printer);
|
||||
printer.append(" and ");
|
||||
operandB.toRuleCodeRead(printer);
|
||||
return;
|
||||
}
|
||||
if (POWER.equals(this)) {
|
||||
printer.append(jsCode,"(");
|
||||
operandA.toRuleCodeRead(printer);
|
||||
printer.append(", ");
|
||||
operandB.toRuleCodeRead(printer);
|
||||
printer.append(")");
|
||||
return;
|
||||
}
|
||||
operandA.toRuleCodeRead(printer);
|
||||
printer.appendSpace();
|
||||
printer.append(jsCode);
|
||||
printer.appendSpace();
|
||||
operandB.toRuleCodeRead(printer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,32 @@ public class UnitXCConverterStepPowerOfTen extends AbstractUnitXConverterStep {
|
|||
result.valueWrite(ctx, convert((Double)operand.valueRead(ctx)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toRuleCode(RuleStepCodePrinter printer) {
|
||||
if (printer.isEnglish()) {
|
||||
printer.lineStart("Update ");
|
||||
getResult().toRuleCodeWrite(printer);
|
||||
printer.append(" with value from ");
|
||||
printer.append(" * ");
|
||||
if (exponentReverse) {
|
||||
printer.append(" -1? "); // TODO: fix reverse
|
||||
}
|
||||
printer.append(" 10^", Integer.toString(exponent));
|
||||
printer.lineEnd(".");
|
||||
return;
|
||||
}
|
||||
printer.lineStart();
|
||||
getResult().toRuleCodeWrite(printer);
|
||||
printer.append(" = ");
|
||||
getOperand().toRuleCodeRead(printer);
|
||||
printer.append(" * ");
|
||||
if (exponentReverse) {
|
||||
printer.append(" -1? "); // TODO: fix reverse
|
||||
}
|
||||
printer.append(" 10^", Integer.toString(exponent));
|
||||
printer.lineEnd();
|
||||
}
|
||||
|
||||
public double convert(double value) {
|
||||
int exponentShift = exponent<0?0-exponent:exponent;
|
||||
for (int i=0;i<exponentShift;i++) {
|
||||
|
|
|
@ -25,6 +25,8 @@ package net.forwardfire.unitxc.model.step;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.unitxc.model.UnitXCType;
|
||||
|
||||
/**
|
||||
|
@ -35,49 +37,44 @@ import net.forwardfire.unitxc.model.UnitXCType;
|
|||
*/
|
||||
public class UnitXCConverterStepReference extends AbstractUnitXConverterStep {
|
||||
|
||||
private String unitTypeId;
|
||||
private Boolean toBaseSteps;
|
||||
private final UnitXCType unitType;
|
||||
private final boolean toBaseSteps;
|
||||
|
||||
public UnitXCConverterStepReference() {
|
||||
}
|
||||
|
||||
public UnitXCConverterStepReference(String unitTypeId,Boolean toBaseSteps) {
|
||||
setUnitTypeId(unitTypeId);
|
||||
setToBaseSteps(toBaseSteps);
|
||||
public UnitXCConverterStepReference(UnitXCType unitType,boolean toBaseSteps) {
|
||||
this.unitType = Validate.notNull(unitType);
|
||||
this.toBaseSteps = toBaseSteps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runStep(UnitXConverterStepContext ctx) {
|
||||
UnitXCType type = ctx.getUnitManager().getUnitType(getUnitTypeId());
|
||||
List<UnitXConverterStep> steps = Boolean.TRUE.equals(toBaseSteps)?type.getToBaseConverterSteps():type.getFromBaseConverterSteps();
|
||||
List<UnitXConverterStep> steps = toBaseSteps?unitType.getToBaseConverterSteps():unitType.getFromBaseConverterSteps();
|
||||
ctx.runSteps(steps);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the unitTypeId
|
||||
*/
|
||||
public String getUnitTypeId() {
|
||||
return unitTypeId;
|
||||
@Override
|
||||
public void toRuleCode(RuleStepCodePrinter printer) {
|
||||
if (printer.isEnglish()) {
|
||||
printer.lineStart("Call ", unitType.getName());
|
||||
printer.append(" with base steps ... ");
|
||||
printer.lineEnd(".");
|
||||
return;
|
||||
}
|
||||
printer.lineStart();
|
||||
printer.append(" TODO REF ");
|
||||
printer.lineEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unitTypeId the unitTypeId to set
|
||||
* @return the unitType
|
||||
*/
|
||||
public void setUnitTypeId(String unitTypeId) {
|
||||
this.unitTypeId = unitTypeId;
|
||||
public UnitXCType getUnitType() {
|
||||
return unitType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the toBaseSteps
|
||||
*/
|
||||
public Boolean getToBaseSteps() {
|
||||
public boolean toBaseSteps() {
|
||||
return toBaseSteps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param toBaseSteps the toBaseSteps to set
|
||||
*/
|
||||
public void setToBaseSteps(Boolean toBaseSteps) {
|
||||
this.toBaseSteps = toBaseSteps;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,4 +38,6 @@ public interface UnitXConverterStep {
|
|||
List<String> getStepReasons();
|
||||
|
||||
void addStepReason(String stepReason); // TODO: rm : fix builder
|
||||
|
||||
void toRuleCode(RuleStepCodePrinter printer);
|
||||
}
|
||||
|
|
|
@ -52,8 +52,6 @@ public interface UnitXConverterStepContext {
|
|||
|
||||
void runSteps(List<UnitXConverterStep> steps);
|
||||
|
||||
UnitXCManager getUnitManager();
|
||||
|
||||
public static UnitXConverterStepValueReadWrite createStepValue() {
|
||||
return new UnitXConverterStepValueNamedVariable(Double.class,VALUE);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
package net.forwardfire.unitxc.model.step.value;
|
||||
|
||||
import net.forwardfire.unitxc.model.step.RuleStepCodePrinter;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
|
@ -47,6 +48,20 @@ public class UnitXConverterStepValueNamedParameter implements UnitXConverterStep
|
|||
return ctx.getNamedParameter(parameterName).valueRead(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toRuleCodeRead(RuleStepCodePrinter printer) {
|
||||
if (printer.isEnglish()) {
|
||||
printer.append(parameterName);
|
||||
return;
|
||||
}
|
||||
printer.append("ctx.params['",parameterName,"']");
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void toRuleCodeWrite(RuleStepCodePrinter printer) {
|
||||
// toRuleCodeRead(printer);
|
||||
// }
|
||||
|
||||
/**
|
||||
* @return the parameterName
|
||||
*/
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
package net.forwardfire.unitxc.model.step.value;
|
||||
|
||||
import net.forwardfire.unitxc.model.step.RuleStepCodePrinter;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
|
@ -54,6 +55,20 @@ public class UnitXConverterStepValueNamedVariable implements UnitXConverterStepV
|
|||
ctx.getNamedVariable(variableName).valueWrite(ctx,value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toRuleCodeRead(RuleStepCodePrinter printer) {
|
||||
if (printer.isEnglish()) {
|
||||
printer.append(variableName);
|
||||
} else {
|
||||
printer.append("ctx.vars['",variableName,"']");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toRuleCodeWrite(RuleStepCodePrinter printer) {
|
||||
toRuleCodeRead(printer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the variableName
|
||||
*/
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
package net.forwardfire.unitxc.model.step.value;
|
||||
|
||||
import net.forwardfire.unitxc.model.step.RuleStepCodePrinter;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
|
@ -34,4 +35,6 @@ import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
|||
public interface UnitXConverterStepValueRead {
|
||||
|
||||
Object valueRead(UnitXConverterStepContext ctx);
|
||||
|
||||
void toRuleCodeRead(RuleStepCodePrinter printer);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
package net.forwardfire.unitxc.model.step.value;
|
||||
|
||||
import net.forwardfire.unitxc.model.step.RuleStepCodePrinter;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
|
@ -34,4 +35,6 @@ import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
|||
public interface UnitXConverterStepValueReadWrite extends UnitXConverterStepValueRead {
|
||||
|
||||
void valueWrite(UnitXConverterStepContext ctx,Object value);
|
||||
|
||||
void toRuleCodeWrite(RuleStepCodePrinter printer);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
|
||||
package net.forwardfire.unitxc.model.step.value;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.forwardfire.unitxc.model.step.RuleStepCodePrinter;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
|
@ -52,6 +55,16 @@ public class UnitXConverterStepValueReferenceDouble implements UnitXConverterSte
|
|||
this.value = Double.class.cast(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toRuleCodeRead(RuleStepCodePrinter printer) {
|
||||
printer.append(""+value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toRuleCodeWrite(RuleStepCodePrinter printer) {
|
||||
printer.append(StringUtils.EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
|
||||
package net.forwardfire.unitxc.model.step.value;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import net.forwardfire.unitxc.model.step.RuleStepCodePrinter;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
|
@ -52,6 +51,11 @@ public class UnitXConverterStepValueReferenceDoubleFraction implements UnitXConv
|
|||
return (Double)(((Integer)numerator).doubleValue()/((Integer)denominator).doubleValue()); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toRuleCodeRead(RuleStepCodePrinter printer) {
|
||||
printer.append(""+numerator+"/"+denominator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the numerator
|
||||
*/
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
|
||||
package net.forwardfire.unitxc.model.step.value;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.forwardfire.unitxc.model.step.RuleStepCodePrinter;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
|
@ -52,6 +55,16 @@ public class UnitXConverterStepValueReferenceInteger implements UnitXConverterSt
|
|||
this.value = Integer.class.cast(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toRuleCodeRead(RuleStepCodePrinter printer) {
|
||||
printer.append(""+value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toRuleCodeWrite(RuleStepCodePrinter printer) {
|
||||
printer.append(StringUtils.EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
|
||||
package net.forwardfire.unitxc.model.step.value;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.forwardfire.unitxc.model.step.RuleStepCodePrinter;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
|
@ -52,6 +55,21 @@ public class UnitXConverterStepValueReferenceString implements UnitXConverterSte
|
|||
this.value = String.class.cast(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toRuleCodeRead(RuleStepCodePrinter printer) {
|
||||
if (value instanceof String && printer.isJavascript()) {
|
||||
String valueEscaped = value.toString().replaceAll("'", "\\\\'");
|
||||
printer.append("'",valueEscaped,"'");
|
||||
} else {
|
||||
printer.append(""+value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toRuleCodeWrite(RuleStepCodePrinter printer) {
|
||||
printer.append(StringUtils.EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
|
|
|
@ -35,30 +35,27 @@ import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 18, 2015
|
||||
*/
|
||||
public class UnitXCModuleElectricCurrent implements UnitXCConfigModule {
|
||||
public class UnitXCModuleAmpere implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "current";
|
||||
public static final String GROUP_NAME = "ampere";
|
||||
public static final String GROUP_DESCRIPTION = "The ampere is a measure of the amount of electric charge passing a point in an electric circuit per unit time, with 6.241×1018 electrons (or one coulomb) per second constituting one ampere.";
|
||||
public static final String GROUP_ID = "ampere";
|
||||
public static final String GROUP_BASE_TYPE_ID = "A";
|
||||
private static final String[] GROUP_QUANTITIES = {"electric_current"};
|
||||
|
||||
public static final String TYPE_AMPERE_ID = GROUP_BASE_TYPE_ID;
|
||||
public static final String TYPE_AMPERE_NAME = GROUP_NAME;
|
||||
public static final String TYPE_AMPERE_NAME = "ampere";
|
||||
public static final String TYPE_AMPERE_FLAG = buildFlag(GROUP_ID,TYPE_AMPERE_NAME);
|
||||
private static final String TYPE_AMPERE_WIKI = "Ampere";
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupBase()
|
||||
.setId( GROUP_ID)
|
||||
.setName( TYPE_AMPERE_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( TYPE_AMPERE_ID)
|
||||
builder.createUnitGroupBase(GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId(GROUP_BASE_TYPE_ID)
|
||||
.createSIUnitTypes()
|
||||
.setId( TYPE_AMPERE_ID)
|
||||
.setName( TYPE_AMPERE_NAME)
|
||||
.addTypeFlag( TYPE_AMPERE_FLAG)
|
||||
.addWebsiteWiki( TYPE_AMPERE_WIKI)
|
||||
.setWebLinkWiki( TYPE_AMPERE_WIKI)
|
||||
.addCommonSIPrefix(UnitXCTypeSIPrefix.MEGA)
|
||||
.addCommonSIPrefix(UnitXCTypeSIPrefix.KILO)
|
||||
.addCommonSIPrefix(UnitXCTypeSIPrefix.MILLI)
|
|
@ -34,30 +34,27 @@ import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 23, 2015
|
||||
*/
|
||||
public class UnitXCModuleLuminousIntensity implements UnitXCConfigModule {
|
||||
public class UnitXCModuleCandela implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "light";
|
||||
public static final String GROUP_NAME = "candela";
|
||||
public static final String GROUP_DESCRIPTION = "The candela is the luminous intensity, in a given direction, of a source that emits monochromatic radiation of frequency 540×1012 hertz and that has a radiant intensity in that direction of 1/683 watt per steradian.";
|
||||
public static final String GROUP_ID = "candela";
|
||||
public static final String GROUP_BASE_TYPE_ID = "cd";
|
||||
private static final String[] GROUP_QUANTITIES = {"luminous_intensity"};
|
||||
|
||||
public static final String TYPE_CANDELA_ID = GROUP_BASE_TYPE_ID;
|
||||
public static final String TYPE_CANDELA_NAME = GROUP_NAME;
|
||||
public static final String TYPE_CANDELA_NAME = "candela";
|
||||
public static final String TYPE_CANDELA_FLAG = buildFlag(GROUP_ID,TYPE_CANDELA_NAME);
|
||||
private static final String TYPE_CANDELA_WIKI = "Candela";
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupBase()
|
||||
.setId( GROUP_ID)
|
||||
.setName( TYPE_CANDELA_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( TYPE_CANDELA_ID)
|
||||
builder.createUnitGroupBase(GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId(GROUP_BASE_TYPE_ID)
|
||||
.createSIUnitTypes()
|
||||
.setId( TYPE_CANDELA_ID)
|
||||
.setName( TYPE_CANDELA_NAME)
|
||||
.addTypeFlag( TYPE_CANDELA_FLAG)
|
||||
.addWebsiteWiki( TYPE_CANDELA_WIKI)
|
||||
.setWebLinkWiki( TYPE_CANDELA_WIKI)
|
||||
.build()
|
||||
.build()
|
||||
;
|
|
@ -36,15 +36,14 @@ import org.apache.commons.lang3.math.Fraction;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 17, 2015
|
||||
*/
|
||||
public class UnitXCModuleTemperature implements UnitXCConfigModule {
|
||||
public class UnitXCModuleKelvin implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "temperature";
|
||||
public static final String GROUP_NAME = "kelvin";
|
||||
public static final String GROUP_DESCRIPTION = "The kelvin, unit of thermodynamic temperature, is the fraction 1/273.16 of the thermodynamic temperature of the triple point of water.";
|
||||
public static final String GROUP_ID = "kelvin";
|
||||
public static final String GROUP_BASE_TYPE_ID = "K";
|
||||
private static final String[] GROUP_QUANTITIES = {"thermodynamic_temperature"};
|
||||
|
||||
public static final String TYPE_KELVIN_ID = GROUP_BASE_TYPE_ID;
|
||||
public static final String TYPE_KELVIN_NAME = GROUP_NAME;
|
||||
public static final String TYPE_KELVIN_NAME = GROUP_ID;
|
||||
public static final String TYPE_KELVIN_FLAG = buildFlag(GROUP_ID,TYPE_KELVIN_NAME);
|
||||
private static final String TYPE_KELVIN_WIKI = "Kelvin";
|
||||
|
||||
|
@ -77,22 +76,20 @@ public class UnitXCModuleTemperature implements UnitXCConfigModule {
|
|||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupBase()
|
||||
.setId( GROUP_ID)
|
||||
.setName( TYPE_KELVIN_NAME)
|
||||
.setDescription( GROUP_DESCRIPTION)
|
||||
builder.createUnitGroupBase(GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId( TYPE_KELVIN_ID)
|
||||
.createSIUnitTypes()
|
||||
.setId( TYPE_KELVIN_ID)
|
||||
.setName( TYPE_KELVIN_NAME)
|
||||
.addTypeFlag( TYPE_KELVIN_FLAG)
|
||||
.addWebsiteWiki(TYPE_KELVIN_WIKI)
|
||||
.setWebLinkWiki(TYPE_KELVIN_WIKI)
|
||||
.build()
|
||||
.createSIUnitTypes()
|
||||
.setId( TYPE_CELSIUS_ID)
|
||||
.setName( TYPE_CELSIUS_NAME)
|
||||
.addTypeFlag( TYPE_CELSIUS_FLAG)
|
||||
.addWebsiteWiki(TYPE_CELSIUS_WIKI)
|
||||
.setWebLinkWiki(TYPE_CELSIUS_WIKI)
|
||||
.createToBaseConverterSteps().offsetUp(TYPE_CELSIUS_OFFSET).build()
|
||||
.createFromBaseConverterSteps().offsetDown(TYPE_CELSIUS_OFFSET).build()
|
||||
.build()
|
||||
|
@ -101,7 +98,7 @@ public class UnitXCModuleTemperature implements UnitXCConfigModule {
|
|||
.setName( TYPE_FAHRENHEIT_NAME)
|
||||
.addTypeFlag( TYPE_FAHRENHEIT_FLAG)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addWebsiteWiki( TYPE_FAHRENHEIT_WIKI)
|
||||
.setWebLinkWiki( TYPE_FAHRENHEIT_WIKI)
|
||||
.createToBaseConverterSteps()
|
||||
.offsetUp( TYPE_FAHRENHEIT_OFFSET)
|
||||
.multiply( TYPE_FAHRENHEIT_FRACTION)
|
||||
|
@ -115,7 +112,7 @@ public class UnitXCModuleTemperature implements UnitXCConfigModule {
|
|||
.setId( TYPE_RANKINE_ID)
|
||||
.setName( TYPE_RANKINE_NAME)
|
||||
.addTypeFlag ( TYPE_RANKINE_FLAG)
|
||||
.addWebsiteWiki( TYPE_RANKINE_WIKI)
|
||||
.setWebLinkWiki( TYPE_RANKINE_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_FAHRENHEIT_FRACTION).build()
|
||||
.createFromBaseConverterSteps().multiply(TYPE_FAHRENHEIT_FRACTION.invert()).build()
|
||||
.build()
|
||||
|
@ -123,7 +120,7 @@ public class UnitXCModuleTemperature implements UnitXCConfigModule {
|
|||
.setId( TYPE_ROMER_ID)
|
||||
.setName( TYPE_ROMER_NAME)
|
||||
.addTypeFlag( TYPE_ROMER_FLAG)
|
||||
.addWebsiteWiki( TYPE_ROMER_WIKI)
|
||||
.setWebLinkWiki( TYPE_ROMER_WIKI)
|
||||
.createToBaseConverterSteps()
|
||||
.offsetUp( TYPE_CELSIUS_OFFSET)
|
||||
.multiply( TYPE_ROMER_FRACTION)
|
|
@ -35,12 +35,11 @@ import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 25, 2015
|
||||
*/
|
||||
public class UnitXCModuleMass implements UnitXCConfigModule {
|
||||
public class UnitXCModuleKilogram implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "mass";
|
||||
public static final String GROUP_NAME = "kilogram";
|
||||
public static final String GROUP_DESCRIPTION = "The kilogram is the unit of mass; it is equal to the mass of the international prototype of the kilogram.";
|
||||
public static final String GROUP_ID = "kilogram";
|
||||
public static final String GROUP_BASE_TYPE_ID = "g";
|
||||
private static final String[] GROUP_QUANTITIES = {"mass"};
|
||||
|
||||
public static final String TYPE_GRAM_ID = GROUP_BASE_TYPE_ID;
|
||||
public static final String TYPE_GRAM_NAME = "gram";
|
||||
|
@ -79,16 +78,14 @@ public class UnitXCModuleMass implements UnitXCConfigModule {
|
|||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupBase()
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( TYPE_GRAM_ID)
|
||||
builder.createUnitGroupBase(GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId(GROUP_BASE_TYPE_ID)
|
||||
.createSIUnitTypes()
|
||||
.setId( TYPE_GRAM_ID)
|
||||
.setName( TYPE_GRAM_NAME)
|
||||
.addTypeFlag( TYPE_GRAM_FLAG)
|
||||
.addWebsiteWiki( TYPE_GRAM_WIKI)
|
||||
.setWebLinkWiki( TYPE_GRAM_WIKI)
|
||||
.addCommonSIPrefix(UnitXCTypeSIPrefix.MEGA)
|
||||
.addCommonSIPrefix(UnitXCTypeSIPrefix.KILO)
|
||||
.addCommonSIPrefix(UnitXCTypeSIPrefix.HECTO)
|
||||
|
@ -103,7 +100,7 @@ public class UnitXCModuleMass implements UnitXCConfigModule {
|
|||
.setName( TYPE_GRAIN_NAME)
|
||||
.addTypeFlag( TYPE_GRAIN_FLAG)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addWebsiteWiki( TYPE_GRAIN_WIKI)
|
||||
.setWebLinkWiki( TYPE_GRAIN_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_GRAIN_FACTOR).power10Down(UnitXCTypeSIPrefix.MILLI).build()
|
||||
.createFromBaseConverterSteps().power10Up(UnitXCTypeSIPrefix.MILLI).divide(TYPE_GRAIN_FACTOR).build()
|
||||
.build()
|
||||
|
@ -113,7 +110,7 @@ public class UnitXCModuleMass implements UnitXCConfigModule {
|
|||
.addTypeFlag( TYPE_DRAM_FLAG)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL_EXTRA)
|
||||
.addWebsiteWiki( TYPE_DRAM_WIKI)
|
||||
.setWebLinkWiki( TYPE_DRAM_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_DRAM_FACTOR).build()
|
||||
.createFromBaseConverterSteps().divide(TYPE_DRAM_FACTOR).build()
|
||||
.build()
|
||||
|
@ -122,7 +119,7 @@ public class UnitXCModuleMass implements UnitXCConfigModule {
|
|||
.setName( TYPE_OUNCE_NAME)
|
||||
.addTypeFlag( TYPE_OUNCE_FLAG)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addWebsiteWiki( TYPE_OUNCE_WIKI)
|
||||
.setWebLinkWiki( TYPE_OUNCE_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_OUNCE_FACTOR).build()
|
||||
.createFromBaseConverterSteps().divide(TYPE_OUNCE_FACTOR).build()
|
||||
.build()
|
||||
|
@ -131,7 +128,7 @@ public class UnitXCModuleMass implements UnitXCConfigModule {
|
|||
.setName( TYPE_POUND_NAME)
|
||||
.addTypeFlag( TYPE_POUND_FLAG)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addWebsiteWiki( TYPE_POUND_WIKI)
|
||||
.setWebLinkWiki( TYPE_POUND_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_POUND_FACTOR).build()
|
||||
.createFromBaseConverterSteps().divide(TYPE_POUND_FACTOR).build()
|
||||
.build()
|
||||
|
@ -141,7 +138,7 @@ public class UnitXCModuleMass implements UnitXCConfigModule {
|
|||
.addTypeFlag( TYPE_STONE_FLAG)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL_EXTRA)
|
||||
.addWebsiteWiki( TYPE_STONE_WIKI)
|
||||
.setWebLinkWiki( TYPE_STONE_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_STONE_FACTOR).power10Up(UnitXCTypeSIPrefix.MILLI).build()
|
||||
.createFromBaseConverterSteps().power10Down(UnitXCTypeSIPrefix.MILLI).divide(TYPE_STONE_FACTOR).build()
|
||||
.build()
|
|
@ -35,15 +35,14 @@ import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 24, 2015
|
||||
*/
|
||||
public class UnitXCModuleLength implements UnitXCConfigModule {
|
||||
public class UnitXCModuleMetre implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "length";
|
||||
public static final String GROUP_NAME = "metre";
|
||||
public static final String GROUP_DESCRIPTION = "The metre is the length of the path travelled by light in vacuum during a time interval of 1/299792458 of a second.";
|
||||
public static final String GROUP_ID = "metre";
|
||||
public static final String GROUP_BASE_TYPE_ID = "m";
|
||||
private static final String[] GROUP_QUANTITIES = {"length"};
|
||||
|
||||
public static final String TYPE_METRE_ID = GROUP_BASE_TYPE_ID;
|
||||
public static final String TYPE_METRE_NAME = GROUP_NAME;
|
||||
public static final String TYPE_METRE_NAME = "metre";
|
||||
public static final String TYPE_METRE_FLAG = buildFlag(GROUP_ID,TYPE_METRE_NAME);
|
||||
public static final String TYPE_METRE_ALIAS_METER = "meter";
|
||||
public static final String TYPE_METRE_ALIAS_METER_FLAG = buildFlag(GROUP_ID,TYPE_METRE_ALIAS_METER);
|
||||
|
@ -125,16 +124,14 @@ public class UnitXCModuleLength implements UnitXCConfigModule {
|
|||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupBase()
|
||||
.setId( GROUP_ID)
|
||||
.setName( TYPE_METRE_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
builder.createUnitGroupBase(GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId( TYPE_METRE_ID)
|
||||
.createSIUnitTypes()
|
||||
.setId( TYPE_METRE_ID)
|
||||
.setName( TYPE_METRE_NAME)
|
||||
.addTypeFlag( TYPE_METRE_FLAG)
|
||||
.addWebsiteWiki( TYPE_METRE_WIKI)
|
||||
.setWebLinkWiki( TYPE_METRE_WIKI)
|
||||
.addCommonSIPrefixes(TYPE_METRE_COMMON_SI)
|
||||
.build()
|
||||
.createSIUnitTypes()
|
||||
|
@ -150,7 +147,7 @@ public class UnitXCModuleLength implements UnitXCConfigModule {
|
|||
.setNamePlural( TYPE_INCH_NAME_PLURAL)
|
||||
.addTypeFlag( TYPE_INCH_FLAG)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addWebsiteWiki( TYPE_INCH_WIKI)
|
||||
.setWebLinkWiki( TYPE_INCH_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_INCH_FACTOR).power10Down(UnitXCTypeSIPrefix.MILLI).build()
|
||||
.createFromBaseConverterSteps().power10Up(UnitXCTypeSIPrefix.MILLI).divide(TYPE_INCH_FACTOR).build()
|
||||
.build()
|
||||
|
@ -160,7 +157,7 @@ public class UnitXCModuleLength implements UnitXCConfigModule {
|
|||
.addTypeFlag( TYPE_LINK_FLAG)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL_EXTRA)
|
||||
.addWebsiteWiki( TYPE_LINK_WIKI)
|
||||
.setWebLinkWiki( TYPE_LINK_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_LINK_FACTOR).power10Down(UnitXCTypeSIPrefix.MILLI).build()
|
||||
.createFromBaseConverterSteps().power10Up(UnitXCTypeSIPrefix.MILLI).divide(TYPE_LINK_FACTOR).build()
|
||||
.build()
|
||||
|
@ -170,7 +167,7 @@ public class UnitXCModuleLength implements UnitXCConfigModule {
|
|||
.setNamePlural( TYPE_FOOT_NAME_PLURAL)
|
||||
.addTypeFlag( TYPE_FOOT_FLAG)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addWebsiteWiki( TYPE_FOOT_WIKI)
|
||||
.setWebLinkWiki( TYPE_FOOT_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_FOOT_FACTOR).power10Down(UnitXCTypeSIPrefix.MILLI).build()
|
||||
.createFromBaseConverterSteps().power10Up(UnitXCTypeSIPrefix.MILLI).divide(TYPE_FOOT_FACTOR).build()
|
||||
.build()
|
||||
|
@ -179,7 +176,7 @@ public class UnitXCModuleLength implements UnitXCConfigModule {
|
|||
.setName( TYPE_YARD_NAME)
|
||||
.addTypeFlag( TYPE_YARD_FLAG)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addWebsiteWiki( TYPE_YARD_WIKI)
|
||||
.setWebLinkWiki( TYPE_YARD_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_YARD_FACTOR).build()
|
||||
.createFromBaseConverterSteps().divide(TYPE_YARD_FACTOR).build()
|
||||
.build()
|
||||
|
@ -189,7 +186,7 @@ public class UnitXCModuleLength implements UnitXCConfigModule {
|
|||
.addTypeFlag( TYPE_ROD_FLAG)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL_EXTRA)
|
||||
.addWebsiteWiki( TYPE_ROD_WIKI)
|
||||
.setWebLinkWiki( TYPE_ROD_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_ROD_FACTOR).build()
|
||||
.createFromBaseConverterSteps().divide(TYPE_ROD_FACTOR).build()
|
||||
.build()
|
||||
|
@ -199,7 +196,7 @@ public class UnitXCModuleLength implements UnitXCConfigModule {
|
|||
.addTypeFlag( TYPE_CHAIN_FLAG)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL_EXTRA)
|
||||
.addWebsiteWiki( TYPE_CHAIN_WIKI)
|
||||
.setWebLinkWiki( TYPE_CHAIN_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_CHAIN_FACTOR).build()
|
||||
.createFromBaseConverterSteps().divide(TYPE_CHAIN_FACTOR).build()
|
||||
.build()
|
||||
|
@ -209,7 +206,7 @@ public class UnitXCModuleLength implements UnitXCConfigModule {
|
|||
.addTypeFlag( TYPE_FURLONG_FLAG)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL_EXTRA)
|
||||
.addWebsiteWiki( TYPE_FURLONG_WIKI)
|
||||
.setWebLinkWiki( TYPE_FURLONG_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_FURLONG_FACTOR).build()
|
||||
.createFromBaseConverterSteps().divide(TYPE_FURLONG_FACTOR).build()
|
||||
.build()
|
||||
|
@ -218,7 +215,7 @@ public class UnitXCModuleLength implements UnitXCConfigModule {
|
|||
.setName( TYPE_MILE_NAME)
|
||||
.addTypeFlag( TYPE_MILE_FLAG)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addWebsiteWiki( TYPE_MILE_WIKI)
|
||||
.setWebLinkWiki( TYPE_MILE_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_MILE_FACTOR).build()
|
||||
.createFromBaseConverterSteps().divide(TYPE_MILE_FACTOR).build()
|
||||
.build()
|
||||
|
@ -227,7 +224,7 @@ public class UnitXCModuleLength implements UnitXCConfigModule {
|
|||
.setName( TYPE_MILE_US_NAME)
|
||||
.addTypeFlag( TYPE_MILE_US_FLAG)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addWebsiteWiki( TYPE_MILE_US_WIKI)
|
||||
.setWebLinkWiki( TYPE_MILE_US_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_MILE_US_FACTOR).build()
|
||||
.createFromBaseConverterSteps().divide(TYPE_MILE_US_FACTOR).build()
|
||||
.build()
|
||||
|
@ -236,7 +233,7 @@ public class UnitXCModuleLength implements UnitXCConfigModule {
|
|||
.setName( TYPE_MILE_NAUTICAL_NAME)
|
||||
.addTypeFlag( TYPE_MILE_NAUTICAL_FLAG)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addWebsiteWiki( TYPE_MILE_NAUTICAL_WIKI)
|
||||
.setWebLinkWiki( TYPE_MILE_NAUTICAL_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_MILE_NAUTICAL_FACTOR).build()
|
||||
.createFromBaseConverterSteps().divide(TYPE_MILE_NAUTICAL_FACTOR).build()
|
||||
.build()
|
|
@ -35,19 +35,18 @@ import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 23, 2015
|
||||
*/
|
||||
public class UnitXCModuleSubstance implements UnitXCConfigModule {
|
||||
public class UnitXCModuleMole implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "substance";
|
||||
public static final String GROUP_NAME = "mole";
|
||||
public static final String GROUP_DESCRIPTION = "The mole is the amount of substance of a system which contains as many elementary entities as there are atoms in 0.012 kilogram of carbon 12.";
|
||||
public static final String GROUP_ID = "mole";
|
||||
public static final String GROUP_BASE_TYPE_ID = "mol";
|
||||
private static final String[] GROUP_QUANTITIES = {"amount_of_substance"};
|
||||
|
||||
public static final String TYPE_MOLE_ID = GROUP_BASE_TYPE_ID;
|
||||
public static final String TYPE_MOLE_NAME = GROUP_NAME;
|
||||
public static final String TYPE_MOLE_FLAG = buildFlag(GROUP_ID,TYPE_MOLE_NAME);
|
||||
private static final String TYPE_MOLE_WIKI = "Mole_(unit)";
|
||||
public static final String TYPE_MOL_ID = GROUP_BASE_TYPE_ID;
|
||||
public static final String TYPE_MOL_NAME = "mole";
|
||||
public static final String TYPE_MOL_FLAG = buildFlag(GROUP_ID,TYPE_MOL_NAME);
|
||||
private static final String TYPE_MOL_WIKI = "Mole_(unit)";
|
||||
|
||||
public static final String TYPE_POUND_MOLE_ID = "lbmol";
|
||||
public static final String TYPE_POUND_MOLE_ID = "lbmol";// TODO: add lb-mol
|
||||
public static final String TYPE_POUND_MOLE_NAME = "pound-mole";
|
||||
public static final String TYPE_POUND_MOLE_FLAG = buildFlag(GROUP_ID,TYPE_POUND_MOLE_NAME);
|
||||
private static final double TYPE_POUND_MOLE_FACTOR = 453.59237;
|
||||
|
@ -55,16 +54,14 @@ public class UnitXCModuleSubstance implements UnitXCConfigModule {
|
|||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupBase()
|
||||
.setId( GROUP_ID)
|
||||
.setName( TYPE_MOLE_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( TYPE_MOLE_ID)
|
||||
builder.createUnitGroupBase(GROUP_ID)
|
||||
.addQuantityIds( GROUP_QUANTITIES)
|
||||
.setBaseTypeId( TYPE_MOL_ID)
|
||||
.createSIUnitTypes()
|
||||
.setId( TYPE_MOLE_ID)
|
||||
.setName( TYPE_MOLE_NAME)
|
||||
.addTypeFlag( TYPE_MOLE_FLAG)
|
||||
.addWebsiteWiki( TYPE_MOLE_WIKI)
|
||||
.setId( TYPE_MOL_ID)
|
||||
.setName( TYPE_MOL_NAME)
|
||||
.addTypeFlag( TYPE_MOL_FLAG)
|
||||
.setWebLinkWiki( TYPE_MOL_WIKI)
|
||||
.addCommonSIPrefix(UnitXCTypeSIPrefix.MILLI)
|
||||
.addCommonSIPrefix(UnitXCTypeSIPrefix.MICRO)
|
||||
.addCommonSIPrefix(UnitXCTypeSIPrefix.NANO)
|
||||
|
@ -75,7 +72,7 @@ public class UnitXCModuleSubstance implements UnitXCConfigModule {
|
|||
.setId( TYPE_POUND_MOLE_ID)
|
||||
.setName( TYPE_POUND_MOLE_NAME)
|
||||
.addTypeFlag( UnitXCConfigBuilder.TYPE_FLAG_IMPERIAL)
|
||||
.addWebsiteWiki( TYPE_POUND_MOLE_WIKI)
|
||||
.setWebLinkWiki( TYPE_POUND_MOLE_WIKI)
|
||||
.createToBaseConverterSteps().multiply(TYPE_POUND_MOLE_FACTOR).build()
|
||||
.createFromBaseConverterSteps().divide(TYPE_POUND_MOLE_FACTOR).build()
|
||||
.build()
|
|
@ -35,15 +35,14 @@ import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 25, 2015
|
||||
*/
|
||||
public class UnitXCModuleTime implements UnitXCConfigModule {
|
||||
public class UnitXCModuleSecond implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "time";
|
||||
public static final String GROUP_NAME = "second";
|
||||
public static final String GROUP_DESCRIPTION = "The second is the duration of 9192631770 periods of the radiation corresponding to the transition between the two hyperfine levels of the ground state of the caesium 133 atom.";
|
||||
public static final String GROUP_ID = "second";
|
||||
public static final String GROUP_BASE_TYPE_ID = "s";
|
||||
private static final String[] GROUP_QUANTITIES = {"time"};
|
||||
|
||||
public static final String TYPE_SECOND_ID = GROUP_BASE_TYPE_ID;
|
||||
public static final String TYPE_SECOND_NAME = GROUP_NAME;
|
||||
public static final String TYPE_SECOND_NAME = "second";
|
||||
public static final String TYPE_SECOND_NAMES = TYPE_SECOND_NAME+TYPE_SECOND_ID;
|
||||
public static final String TYPE_SECOND_FLAG = buildFlag(GROUP_ID,TYPE_SECOND_NAME);
|
||||
|
||||
|
@ -72,10 +71,8 @@ public class UnitXCModuleTime implements UnitXCConfigModule {
|
|||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupBase()
|
||||
.setId( GROUP_ID)
|
||||
.setName( TYPE_SECOND_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
builder.createUnitGroupBase(GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId( TYPE_SECOND_ID)
|
||||
.createSIUnitTypes()
|
||||
.setId( TYPE_SECOND_ID)
|
|
@ -27,7 +27,7 @@ import static net.forwardfire.unitxc.config.builder.UnitXCNumberTypeSetting.toSu
|
|||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleLength;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleMetre;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -35,24 +35,22 @@ import net.forwardfire.unitxc.module.UnitXCModuleLength;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 28, 2015
|
||||
*/
|
||||
public class UnitXCModuleVolume implements UnitXCConfigModule {
|
||||
public class UnitXCModuleCubicMetre implements UnitXCConfigModule {
|
||||
|
||||
private static final int UNIT_COMPOUND_EXPONENT = 3;
|
||||
private static final String UNIT_ID_POSTFIX = toSuperScript(UNIT_COMPOUND_EXPONENT);
|
||||
private static final String UNIT_NAME_PREFIX = "cubic ";
|
||||
|
||||
public static final String GROUP_ID = "volume";
|
||||
public static final String GROUP_NAME = UNIT_NAME_PREFIX+UnitXCModuleLength.GROUP_NAME;
|
||||
public static final String GROUP_DESCRIPTION = "It is the volume of a cube with edges one metre in length.";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleLength.GROUP_BASE_TYPE_ID+UNIT_ID_POSTFIX;
|
||||
public static final String GROUP_ID = "cubic_metre";
|
||||
public static final String GROUP_DESCRIPTION = "";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMetre.GROUP_BASE_TYPE_ID+UNIT_ID_POSTFIX;
|
||||
private static final String[] GROUP_QUANTITIES = {"volume"};
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupCompoundExponent(UnitXCModuleLength.GROUP_ID, UNIT_COMPOUND_EXPONENT)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
builder.createUnitGroupCompoundExponent(GROUP_ID,UnitXCModuleMetre.GROUP_ID, UNIT_COMPOUND_EXPONENT)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId(GROUP_BASE_TYPE_ID)
|
||||
.setUnitIdPostfix(UNIT_ID_POSTFIX)
|
||||
.setUnitNamePrefix(UNIT_NAME_PREFIX)
|
||||
.build()
|
|
@ -26,7 +26,7 @@ package net.forwardfire.unitxc.module.derived;
|
|||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleMass;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleKilogram;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -34,20 +34,17 @@ import net.forwardfire.unitxc.module.UnitXCModuleMass;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 12, 2016
|
||||
*/
|
||||
public class UnitXCModuleAreaDensity implements UnitXCConfigModule {
|
||||
public class UnitXCModuleCubicMetrePerKilogram implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "area_density";
|
||||
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+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleArea.GROUP_BASE_TYPE_ID;
|
||||
public static final String GROUP_ID = "cubic_metre_per_kilogram";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleCubicMetre.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleKilogram.GROUP_BASE_TYPE_ID;
|
||||
private static final String[] GROUP_QUANTITIES = {"specific_volume"};
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupCompoundPair(UnitXCModuleMass.GROUP_ID, UnitXCModuleArea.GROUP_ID)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleCubicMetre.GROUP_ID, UnitXCModuleKilogram.GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId(GROUP_BASE_TYPE_ID)
|
||||
.build()
|
||||
;
|
||||
}
|
|
@ -26,7 +26,7 @@ package net.forwardfire.unitxc.module.derived;
|
|||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleSubstance;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleMole;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -34,20 +34,17 @@ import net.forwardfire.unitxc.module.UnitXCModuleSubstance;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 12, 2016
|
||||
*/
|
||||
public class UnitXCModuleMolarVolume implements UnitXCConfigModule {
|
||||
public class UnitXCModuleCubicMetrePerMole implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "molar_volume";
|
||||
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+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleSubstance.GROUP_BASE_TYPE_ID;
|
||||
public static final String GROUP_ID = "cubic_metre_per_mole";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleCubicMetre.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleMole.GROUP_BASE_TYPE_ID;
|
||||
private static final String[] GROUP_QUANTITIES = {"molar_volume"};
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupCompoundPair(UnitXCModuleVolume.GROUP_ID, UnitXCModuleSubstance.GROUP_ID)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleCubicMetre.GROUP_ID, UnitXCModuleMole.GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId(GROUP_BASE_TYPE_ID)
|
||||
.build()
|
||||
;
|
||||
}
|
|
@ -26,7 +26,7 @@ package net.forwardfire.unitxc.module.derived;
|
|||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleSecond;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -34,19 +34,16 @@ import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 1, 2016
|
||||
*/
|
||||
public class UnitXCModuleVolumetricFlow implements UnitXCConfigModule {
|
||||
public class UnitXCModuleCubicMetrePerSecond implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "volumetric_flow";
|
||||
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+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID;
|
||||
public static final String GROUP_ID = "cubic_metre_per_second";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleCubicMetre.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleSecond.GROUP_BASE_TYPE_ID;
|
||||
private static final String[] GROUP_QUANTITIES = {"volumetric_flow"};
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupCompoundPair(UnitXCModuleVolume.GROUP_ID, UnitXCModuleTime.GROUP_ID)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
builder.createUnitGroupCompoundPair(GROUP_ID,UnitXCModuleCubicMetre.GROUP_ID, UnitXCModuleSecond.GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
.build()
|
||||
;
|
|
@ -26,7 +26,7 @@ package net.forwardfire.unitxc.module.derived;
|
|||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleMass;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleKilogram;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -34,20 +34,17 @@ import net.forwardfire.unitxc.module.UnitXCModuleMass;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 12, 2016
|
||||
*/
|
||||
public class UnitXCModuleSpecificVolume implements UnitXCConfigModule {
|
||||
public class UnitXCModuleKilogramPerCubicMetre implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "specific_volume";
|
||||
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+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleMass.GROUP_BASE_TYPE_ID;
|
||||
public static final String GROUP_ID = "kilogram_per_cubic_metre";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleKilogram.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleCubicMetre.GROUP_BASE_TYPE_ID;
|
||||
private static final String[] GROUP_QUANTITIES = {"density","mass_density"};
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupCompoundPair(UnitXCModuleVolume.GROUP_ID, UnitXCModuleMass.GROUP_ID)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleKilogram.GROUP_ID, UnitXCModuleCubicMetre.GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId(GROUP_BASE_TYPE_ID)
|
||||
.build()
|
||||
;
|
||||
}
|
|
@ -26,7 +26,7 @@ package net.forwardfire.unitxc.module.derived;
|
|||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleMass;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleKilogram;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -34,19 +34,16 @@ import net.forwardfire.unitxc.module.UnitXCModuleMass;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 12, 2016
|
||||
*/
|
||||
public class UnitXCModuleMassDensity implements UnitXCConfigModule {
|
||||
public class UnitXCModuleKilogramPerSquareMetre implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "mass_density";
|
||||
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+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleVolume.GROUP_BASE_TYPE_ID;
|
||||
public static final String GROUP_ID = "kilogram_per_square_metre";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleKilogram.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleSquareMetre.GROUP_BASE_TYPE_ID;
|
||||
private static final String[] GROUP_QUANTITIES = {"area_density"};
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupCompoundPair(UnitXCModuleMass.GROUP_ID, UnitXCModuleVolume.GROUP_ID)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleKilogram.GROUP_ID, UnitXCModuleSquareMetre.GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
.build()
|
||||
;
|
|
@ -26,7 +26,7 @@ package net.forwardfire.unitxc.module.derived;
|
|||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleSecond;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -34,21 +34,18 @@ import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 1, 2016
|
||||
*/
|
||||
public class UnitXCModuleJounce implements UnitXCConfigModule {
|
||||
public class UnitXCModuleMetrePerQuarticSecond implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "jounce";
|
||||
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+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID;
|
||||
public static final String GROUP_ID = "metre_per_quartic_second";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMetrePerSecondCubed.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleSecond.GROUP_BASE_TYPE_ID;
|
||||
private static final String[] GROUP_QUANTITIES = {"snap","jounce"};
|
||||
|
||||
// TODO: add aliases
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupCompoundPair(UnitXCModuleJerk.GROUP_ID, UnitXCModuleTime.GROUP_ID)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleMetrePerSecondCubed.GROUP_ID, UnitXCModuleSecond.GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId(GROUP_BASE_TYPE_ID)
|
||||
.build()
|
||||
;
|
||||
}
|
|
@ -26,8 +26,9 @@ package net.forwardfire.unitxc.module.derived;
|
|||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleLength;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
||||
import net.forwardfire.unitxc.model.UnitXCModule;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleMetre;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleSecond;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -35,20 +36,18 @@ import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Nov 3, 2015
|
||||
*/
|
||||
public class UnitXCModuleSpeed implements UnitXCConfigModule {
|
||||
@UnitXCModule(groupId=UnitXCModuleMetrePerSecond.GROUP_ID,dependencies={UnitXCModuleMetre.GROUP_ID, UnitXCModuleSecond.GROUP_ID})
|
||||
public class UnitXCModuleMetrePerSecond implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "speed";
|
||||
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+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID;
|
||||
public static final String GROUP_ID = "metre_per_second";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMetre.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleSecond.GROUP_BASE_TYPE_ID;
|
||||
private static final String[] GROUP_QUANTITIES = {"speed","velocity"};
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupCompoundPair(UnitXCModuleLength.GROUP_ID, UnitXCModuleTime.GROUP_ID)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
builder.createUnitGroupCompoundPair(GROUP_ID,UnitXCModuleMetre.GROUP_ID, UnitXCModuleSecond.GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId(GROUP_BASE_TYPE_ID)
|
||||
.build()
|
||||
;
|
||||
}
|
|
@ -26,7 +26,7 @@ package net.forwardfire.unitxc.module.derived;
|
|||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleSecond;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -34,20 +34,17 @@ import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 1, 2016
|
||||
*/
|
||||
public class UnitXCModuleJerk implements UnitXCConfigModule {
|
||||
public class UnitXCModuleMetrePerSecondCubed implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "jerk";
|
||||
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+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID;
|
||||
public static final String GROUP_ID = "metre_per_second_cubed";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMetrePerSecondSquared.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleSecond.GROUP_BASE_TYPE_ID;
|
||||
private static final String[] GROUP_QUANTITIES = {"jerk","jolt","surge","lurch"};
|
||||
|
||||
// TODO: add aliases
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupCompoundPair(UnitXCModuleAcceleration.GROUP_ID, UnitXCModuleTime.GROUP_ID)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleMetrePerSecondSquared.GROUP_ID, UnitXCModuleSecond.GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
.build()
|
||||
;
|
|
@ -28,7 +28,7 @@ import static net.forwardfire.unitxc.config.builder.UnitXCNumberTypeSetting.toSu
|
|||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleSecond;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -36,27 +36,24 @@ import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 1, 2016
|
||||
*/
|
||||
public class UnitXCModuleAcceleration implements UnitXCConfigModule {
|
||||
public class UnitXCModuleMetrePerSecondSquared implements UnitXCConfigModule {
|
||||
|
||||
private static final int UNIT_COMPOUND_EXPONENT = 2;
|
||||
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+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 = "m"+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID+UNIT_ID_POSTFIX; //UnitXCModuleSpeed.GROUP_BASE_TYPE_ID;
|
||||
public static final String GROUP_ID = "metre_per_second_squared";
|
||||
public static final String GROUP_BASE_TYPE_ID = "m"+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleSecond.GROUP_BASE_TYPE_ID+UNIT_ID_POSTFIX; //UnitXCModuleSpeed.GROUP_BASE_TYPE_ID;
|
||||
private static final String[] GROUP_QUANTITIES = {"acceleration"};
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupCompoundPair(UnitXCModuleSpeed.GROUP_ID, UnitXCModuleTime.GROUP_ID)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
builder.createUnitGroupCompoundPair(GROUP_ID,UnitXCModuleMetrePerSecond.GROUP_ID, UnitXCModuleSecond.GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId(GROUP_BASE_TYPE_ID)
|
||||
.createUnitType()
|
||||
.setAliasOfType("m/s/s")
|
||||
.setId(GROUP_BASE_TYPE_ID)
|
||||
.setName("Meter per second2")
|
||||
.setName("Meter per second squared")
|
||||
.build()
|
||||
.build()
|
||||
;
|
|
@ -1,54 +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.module.derived;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleSubstance;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 12, 2016
|
||||
*/
|
||||
public class UnitXCModuleMolarConcentration implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "molar_concentration";
|
||||
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+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleVolume.GROUP_BASE_TYPE_ID;
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupCompoundPair(UnitXCModuleSubstance.GROUP_ID, UnitXCModuleVolume.GROUP_ID)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
.build()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.module.derived;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleMole;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 12, 2016
|
||||
*/
|
||||
public class UnitXCModuleMolePerCubicMetre implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "mole_per_cubic_metre";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMole.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleCubicMetre.GROUP_BASE_TYPE_ID;
|
||||
private static final String[] GROUP_QUANTITIES = {"molarity"};
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleMole.GROUP_ID, UnitXCModuleCubicMetre.GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId(GROUP_BASE_TYPE_ID)
|
||||
.build()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.module.derived;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleSecond;
|
||||
import net.forwardfire.unitxc.module.named.UnitXCModuleNewton;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 31, 2016
|
||||
*/
|
||||
public class UnitXCModuleNewtonPerSecond implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "newton_per_second";
|
||||
public static final String GROUP_BASE_TYPE_ID = "kg/m/s/s/s"; //FIXME: UnitXCModuleNewton.GROUP_BASE_TYPE_ID+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID;
|
||||
private static final String[] GROUP_QUANTITIES = {"yank"};
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleNewton.GROUP_ID, UnitXCModuleSecond.GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
.build()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@ import static net.forwardfire.unitxc.config.builder.UnitXCNumberTypeSetting.toSu
|
|||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleLength;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleMetre;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -35,16 +35,15 @@ import net.forwardfire.unitxc.module.UnitXCModuleLength;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 26, 2015
|
||||
*/
|
||||
public class UnitXCModuleArea implements UnitXCConfigModule {
|
||||
public class UnitXCModuleSquareMetre implements UnitXCConfigModule {
|
||||
|
||||
private static final int UNIT_COMPOUND_EXPONENT = 2;
|
||||
private static final String UNIT_ID_POSTFIX = toSuperScript(UNIT_COMPOUND_EXPONENT);
|
||||
private static final String UNIT_NAME_PREFIX = "square ";
|
||||
|
||||
public static final String GROUP_ID = "area";
|
||||
public static final String GROUP_NAME = UNIT_NAME_PREFIX+UnitXCModuleLength.GROUP_NAME;
|
||||
public static final String GROUP_DESCRIPTION = "It is defined as the area of a square whose sides measure exactly one metre. The square metre is derived from the SI base unit of the metre,";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleLength.GROUP_BASE_TYPE_ID+UNIT_ID_POSTFIX;
|
||||
public static final String GROUP_ID = "square_metre";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMetre.GROUP_BASE_TYPE_ID+UNIT_ID_POSTFIX;
|
||||
private static final String[] GROUP_QUANTITIES = {"area"};
|
||||
|
||||
public static final String TYPE_CENTIARE_ALIAS = "m²";
|
||||
public static final String TYPE_CENTIARE_ID = "ca";
|
||||
|
@ -63,10 +62,8 @@ public class UnitXCModuleArea implements UnitXCConfigModule {
|
|||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupCompoundExponent(UnitXCModuleLength.GROUP_ID, UNIT_COMPOUND_EXPONENT)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
builder.createUnitGroupCompoundExponent(GROUP_ID, UnitXCModuleMetre.GROUP_ID, UNIT_COMPOUND_EXPONENT)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
.setUnitIdPostfix(UNIT_ID_POSTFIX)
|
||||
.setUnitNamePrefix(UNIT_NAME_PREFIX)
|
||||
|
@ -74,19 +71,19 @@ public class UnitXCModuleArea implements UnitXCConfigModule {
|
|||
.setAliasOfType( TYPE_CENTIARE_ALIAS)
|
||||
.setId( TYPE_CENTIARE_ID)
|
||||
.setName( TYPE_CENTIARE_NAME)
|
||||
.addWebsiteLink( TYPE_CENTIARE_URL)
|
||||
.setWebLink( TYPE_CENTIARE_URL)
|
||||
.build()
|
||||
.createUnitType()
|
||||
.setAliasOfType( TYPE_ARE_ALIAS)
|
||||
.setId( TYPE_ARE_ID)
|
||||
.setName( TYPE_ARE_NAME)
|
||||
.addWebsiteLink( TYPE_ARE_URL)
|
||||
.setWebLink( TYPE_ARE_URL)
|
||||
.build()
|
||||
.createUnitType()
|
||||
.setAliasOfType( TYPE_HECTARE_ALIAS)
|
||||
.setId( TYPE_HECTARE_ID)
|
||||
.setName( TYPE_HECTARE_NAME)
|
||||
.addWebsiteLink( TYPE_HECTARE_URL)
|
||||
.setWebLink( TYPE_HECTARE_URL)
|
||||
.build()
|
||||
.build()
|
||||
;
|
|
@ -26,8 +26,8 @@ package net.forwardfire.unitxc.module.named;
|
|||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupCompoundPair;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleMass;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleAcceleration;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleKilogram;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleMetrePerSecondSquared;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -38,23 +38,21 @@ 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+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"+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleAcceleration.GROUP_BASE_TYPE_ID;
|
||||
public static final String GROUP_BASE_TYPE_ID = "N";
|
||||
private static final String GROUP_BASE_TYPE_ID_ALIAS = "kg"+UnitXCGroupCompoundPair.PER_ID+UnitXCModuleMetrePerSecondSquared.GROUP_BASE_TYPE_ID;
|
||||
private static final String[] GROUP_QUANTITIES = {"force","weight"};
|
||||
|
||||
// TODO: symbol N + fix builder
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroupCompoundPair(UnitXCModuleMass.GROUP_ID, UnitXCModuleAcceleration.GROUP_ID)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
builder.createUnitGroupCompoundPair(GROUP_ID, UnitXCModuleKilogram.GROUP_ID, UnitXCModuleMetrePerSecondSquared.GROUP_ID)
|
||||
.addQuantityIds(GROUP_QUANTITIES)
|
||||
.setBaseTypeId(GROUP_BASE_TYPE_ID)
|
||||
.createUnitType()
|
||||
.setId("N")
|
||||
.setId(GROUP_BASE_TYPE_ID)
|
||||
.setName(GROUP_ID)
|
||||
.setAliasOfType(GROUP_BASE_TYPE_ID)
|
||||
.setAliasOfType(GROUP_BASE_TYPE_ID_ALIAS)
|
||||
.build()
|
||||
.build();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
|
||||
|
||||
group.mole.name = mole
|
||||
group.mole.description = The mole is the amount of substance of a system which contains as many elementary entities as there are atoms in 0.012 kilogram of carbon 12.
|
||||
group.mole.quantity.amount_of_substance.name = amount of substance
|
||||
group.mole.quantity.amount_of_substance.wikiLink = Amount_of_substance
|
||||
|
||||
group.second.name = second
|
||||
group.second.description = The second is the duration of 9192631770 periods of the radiation corresponding to the transition between the two hyperfine levels of the ground state of the caesium 133 atom.
|
||||
group.second.quantity.time.name = time
|
||||
group.second.quantity.time.wikiLink = Time
|
||||
|
||||
group.kelvin.name = kelvin
|
||||
group.kelvin.description = The kelvin, unit of thermodynamic temperature, is the fraction 1/273.16 of the thermodynamic temperature of the triple point of water.
|
||||
group.kelvin.quantity.thermodynamic_temperature.name = thermodynamic temperature
|
||||
group.kelvin.quantity.thermodynamic_temperature.wikiLink = Thermodynamic_temperature
|
||||
|
||||
group.candela.name = candela
|
||||
group.candela.description = The candela is the luminous intensity, in a given direction, of a source that emits monochromatic radiation of frequency 540×1012 hertz and that has a radiant intensity in that direction of 1/683 watt per steradian.
|
||||
group.candela.quantity.luminous_intensity.name = luminous intensity
|
||||
group.candela.quantity.luminous_intensity.wikiLink = Luminous_intensity
|
||||
|
||||
group.ampere.name = ampere
|
||||
group.ampere.description = The ampere is a measure of the amount of electric charge passing a point in an electric circuit per unit time, with 6.241×1018 electrons (or one coulomb) per second constituting one ampere.
|
||||
group.ampere.quantity.electric_current.name = electric current
|
||||
group.ampere.quantity.electric_current.wikiLink = Electric_current
|
||||
|
||||
group.kilogram.name = kilogram
|
||||
group.kilogram.description = The kilogram is the unit of mass; it is equal to the mass of the international prototype of the kilogram.
|
||||
group.kilogram.quantity.mass.name = mass
|
||||
group.kilogram.quantity.mass.wikiLink = Mass
|
||||
|
||||
group.metre.name = metre
|
||||
group.metre.description = The metre is the length of the path travelled by light in vacuum during a time interval of 1/299792458 of a second.
|
||||
group.metre.quantity.length.name = length
|
||||
group.metre.quantity.length.wikiLink = Length
|
||||
|
||||
|
||||
|
||||
group.metre_per_second.name = metre per second
|
||||
group.metre_per_second.description = Speed is the dimensions of a length divided by a time.
|
||||
group.metre_per_second.quantity.speed.name = speed
|
||||
group.metre_per_second.quantity.speed.wikiLink = Speed
|
||||
group.metre_per_second.quantity.velocity.name = velocity
|
||||
group.metre_per_second.quantity.velocity.wikiLink = Velocity
|
||||
|
||||
|
||||
group.cubic_metre.name = cubic metre
|
||||
group.cubic_metre.description = It is the volume of a cube with edges one metre in length.
|
||||
group.cubic_metre.quantity.volume.name = volume
|
||||
group.cubic_metre.quantity.volume.wikiLink = Volume
|
||||
|
||||
group.cubic_metre_per_second.name = cubic metre per second
|
||||
group.cubic_metre_per_second.description = Volumetric flow is the volume of fluid which passes per unit time.
|
||||
group.cubic_metre_per_second.quantity.volumetric_flow.name = volumetric flow
|
||||
group.cubic_metre_per_second.quantity.volumetric_flow.wikiLink = Volumetric_flow
|
||||
|
||||
group.metre_per_second_squared.name = metre per second squared
|
||||
group.metre_per_second_squared.description = Acceleration, is the rate of change of velocity of an object with respect to time.
|
||||
group.metre_per_second_squared.acceleration.volumetric_flow.name = acceleration
|
||||
group.metre_per_second_squared.acceleration.volumetric_flow.wikiLink = Acceleration
|
||||
|
||||
group.metre_per_second_cubed.name = metre per second cubed
|
||||
group.metre_per_second_cubed.description = Jerk, also known as jolt, surge, or lurch, is the rate of change of acceleration, with respect to time.
|
||||
group.metre_per_second_cubed.quantity.jerk.name = jerk
|
||||
group.metre_per_second_cubed.quantity.jerk.wikiLink = Jerk_(physics)
|
||||
group.metre_per_second_cubed.quantity.jolt.name = jolt
|
||||
group.metre_per_second_cubed.quantity.surge.name = surge
|
||||
group.metre_per_second_cubed.quantity.lurch.name = lurch
|
||||
|
||||
group.metre_per_quartic_second.name = metre per quartic second
|
||||
group.metre_per_quartic_second.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.
|
||||
group.metre_per_quartic_second.quantity.jounce.name = jounce
|
||||
group.metre_per_quartic_second.quantity.jounce.wikiLink = Jounce
|
||||
group.metre_per_quartic_second.quantity.snap.name = snap
|
||||
|
||||
group.kilogram_per_square_metre.name = kilogram per square metre
|
||||
group.kilogram_per_square_metre.description = Area density is of a two-dimensional object is calculated as the mass per unit area.
|
||||
group.kilogram_per_square_metre.quantity.area_density.name = area_density
|
||||
group.kilogram_per_square_metre.quantity.area_density.wikiLink = Area_density
|
||||
|
||||
group.kilogram_per_cubic_metre.name = kilogram per cubic metre
|
||||
group.kilogram_per_cubic_metre.description = The volumetric mass density, of a substance is its mass per unit volume.
|
||||
group.kilogram_per_cubic_metre.quantity.density.name = density
|
||||
group.kilogram_per_cubic_metre.quantity.density.wikiLink = Density
|
||||
group.kilogram_per_cubic_metre.quantity.mass_density.name = mass_density
|
||||
|
||||
group.mole_per_cubic_metre.name = mole per cubic metre
|
||||
group.mole_per_cubic_metre.description = Molar concentration is a measure of the concentration of a solute in a solution.
|
||||
group.mole_per_cubic_metre.quantity.molarity.name = molarity
|
||||
group.mole_per_cubic_metre.quantity.molarity.wikiLink = Molarity
|
||||
|
||||
group.cubic_metre_per_mole.name = cubic metre per mole
|
||||
group.cubic_metre_per_mole.description = Molar volume is the volume occupied by one mole of a substance.
|
||||
group.cubic_metre_per_mole.quantity.molar_volume.name = molar volume
|
||||
group.cubic_metre_per_mole.quantity.molar_volume.wikiLink = Molar_volume
|
||||
|
||||
group.newton_per_second.name = newton per second
|
||||
group.newton_per_second.description = Newton per second.
|
||||
group.newton_per_second.quantity.yank.name = yank
|
||||
|
||||
group.cubic_metre_per_kilogram.name = cubic metre per kilogram
|
||||
group.cubic_metre_per_kilogram.description = In thermodynamics, the specific volume of a substance is the ratio of the substance's volume to its mass.
|
||||
group.cubic_metre_per_kilogram.quantity.specific_volume.name = specific volume
|
||||
group.cubic_metre_per_kilogram.quantity.specific_volume.wikiLink = Specific_volume
|
||||
|
||||
group.square_metre.name = square metre
|
||||
group.square_metre.description = It is defined as the area of a square whose sides measure exactly one metre. The square metre is derived from the SI base unit of the metre,
|
||||
group.square_metre.quantity.area.name = area
|
||||
group.square_metre.quantity.area.wikiLink = Area
|
||||
|
||||
group.newton.name = newton
|
||||
group.newton.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.
|
||||
group.newton.quantity.force.name = force
|
||||
group.newton.quantity.force.wikiLink = Force
|
||||
group.newton.quantity.weight.name = weigth
|
||||
group.newton.quantity.weight.wikiLink = Weight
|
||||
|
||||
|
||||
# type.mol.wikiLink = ${general.wiki.base.url}/Mole_(unit)
|
||||
# type.mol.name = Mole
|
||||
|
|
@ -26,17 +26,21 @@ package net.forwardfire.unitxc;
|
|||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import ch.qos.logback.core.util.FileUtil;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import static net.forwardfire.unitxc.UnitXCAssert.convertEquals;
|
||||
|
@ -46,8 +50,14 @@ import net.forwardfire.unitxc.UnitXCManager;
|
|||
import net.forwardfire.unitxc.converter.UnitXConverterParameterValue;
|
||||
import net.forwardfire.unitxc.model.UnitXCType;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroup;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupJump;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupJumpParameter;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupQuantity;
|
||||
import net.forwardfire.unitxc.model.UnitXConverterResult;
|
||||
import net.forwardfire.unitxc.model.UnitXConverterResultStep;
|
||||
import net.forwardfire.unitxc.model.step.RuleStepCodePrinter;
|
||||
import net.forwardfire.unitxc.model.step.RuleStepCodeStyle;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStep;
|
||||
|
||||
public class UnitXCConverterStepTest {
|
||||
|
||||
|
@ -68,12 +78,27 @@ public class UnitXCConverterStepTest {
|
|||
}
|
||||
long tc = typeGroup.getUnitTypeSize();
|
||||
ts += tc;
|
||||
String groupLine = String.format("%-20s %-20d %-10s %s", typeGroup.getId(),tc,type.getId(),typeGroup.getName());
|
||||
String groupLine = String.format("%-40s %-20d %-10s", typeGroup.getName().getValue(""),tc,type.getId());
|
||||
System.out.println(groupLine);
|
||||
}
|
||||
System.out.println("\ntotalTypes: "+ts);
|
||||
System.out.println("");
|
||||
|
||||
Set<String> paraSet = new HashSet<>();
|
||||
for (UnitXCGroup typeGroup:unitManager.getConfig().getUnitGroups()) {
|
||||
for (UnitXCGroupJump jumpGroup:typeGroup.getGroupJumps()) {
|
||||
for (UnitXCGroupJumpParameter jumpPara:jumpGroup.getJumpParameters()) {
|
||||
System.out.println("jumpPara: "+jumpPara.getId()+" as: "+jumpPara.getUnitGroupId());
|
||||
if (paraSet.contains(jumpPara.getId())) {
|
||||
//throw new IllegalStateException("duplicate jump parameter id found: "+jumpPara.getId());
|
||||
}
|
||||
paraSet.add(jumpPara.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("\ntotalTypes: "+ts);
|
||||
System.out.println("");
|
||||
|
||||
UnitXConverterResult result2 = unitManager.getConverter().convertStepped(20.0, "m/s/s", "km/s/s");
|
||||
System.out.println("20m/s = "+result2.getResultValue()+" km/h");
|
||||
|
||||
|
@ -100,8 +125,91 @@ public class UnitXCConverterStepTest {
|
|||
//jaxbDriver.getUnitXCGroup().marshal(unitManager.getUnitGroup("length"), System.out);
|
||||
|
||||
Map<String,UnitXConverterParameterValue> para = new HashMap<>();
|
||||
para.put("speed_time", new UnitXConverterParameterValue(2, unitManager.getUnitType("minute")));
|
||||
para.put("metre_per_second_second", new UnitXConverterParameterValue(2, unitManager.getUnitType("minute")));
|
||||
result = unitManager.getConverter().convertStepped(50, "km/h", "mm",para);
|
||||
System.out.println("CONVERT-RESULT: "+result);
|
||||
//System.out.println("CONVERT-RESULT: "+result);
|
||||
|
||||
int x=0;
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("digraph G {\n");
|
||||
//buf.append("\tsize = \"4,4\"\n");
|
||||
for (UnitXCGroup typeGroup:unitManager.getConfig().getUnitGroups()) {
|
||||
UnitXCType baseType = unitManager.getUnitType(typeGroup.getBaseTypeId());
|
||||
System.out.println("group: "+typeGroup.getId());
|
||||
|
||||
// print info
|
||||
buf.append("\t"+typeGroup.getId());
|
||||
buf.append("[");
|
||||
if (typeGroup.getDerivedFrom().isEmpty()) {
|
||||
buf.append("shape=box,style=filled,color=\".9 0.5 0.9\",");
|
||||
}
|
||||
StringBuilder label = new StringBuilder();
|
||||
label.append("label=\"");
|
||||
label.append(typeGroup.getId()+"\\n");
|
||||
label.append(baseType.getId()+"\\n");
|
||||
label.append(baseType.getName()+"\\n");
|
||||
Iterator<UnitXCGroupQuantity> q = typeGroup.getQuantities().iterator();
|
||||
label.append("(");
|
||||
while (q.hasNext()) {
|
||||
UnitXCGroupQuantity gq = q.next();
|
||||
label.append(gq.getId());
|
||||
//label.append(gq.getName());
|
||||
if (q.hasNext()) {
|
||||
label.append(",");
|
||||
}
|
||||
}
|
||||
label.append(")");
|
||||
label.append("\"");
|
||||
|
||||
buf.append(label+",labelloc=b");
|
||||
buf.append("];\n");
|
||||
|
||||
// print unit per group
|
||||
buf.append("\t"+typeGroup.getId()+" -> "+typeGroup.getId());
|
||||
buf.append("[");
|
||||
buf.append("color=red,label=\""+typeGroup.getUnitTypeSize()+"\"");
|
||||
buf.append("];\n");
|
||||
|
||||
// print relations
|
||||
for (String groupFrom:typeGroup.getDerivedFrom()) {
|
||||
buf.append("\t"+groupFrom+" -> "+typeGroup.getId());
|
||||
buf.append("[");
|
||||
buf.append("dir=none");
|
||||
buf.append("];\n");
|
||||
}
|
||||
|
||||
//for (UnitXCGroupJump jumpGroup:typeGroup.getGroupJumps()) {
|
||||
// System.out.println("jumpGruop: "+jumpGroup.getId()+" to: "+jumpGroup.getUnitGroupId());
|
||||
// buf.append("\t"+typeGroup.getId()+" -> "+jumpGroup.getUnitGroupId());
|
||||
// buf.append("[");
|
||||
// buf.append("];\n");
|
||||
// buf.append("\t"+typeGroup.getId()+" -> "+jumpGroup.getId());
|
||||
// buf.append(";\n");
|
||||
//
|
||||
// buf.append("\t"+jumpGroup.getId()+" -> "+jumpGroup.getUnitGroupId());
|
||||
// buf.append(";\n");
|
||||
|
||||
//for (UnitXCGroupJumpParameter jumpPara:jumpGroup.getJumpParameters()) {
|
||||
|
||||
//buf.append("\t"+jumpPara.getUnitGroupId()+"_"+(x++)+" -> "+jumpGroup.getId());
|
||||
//buf.append(";\n");
|
||||
|
||||
//buf.append("\t"+typeGroup.getId()+" -> "+jumpPara.getId());
|
||||
//buf.append(";\n");
|
||||
|
||||
//buf.append("\t"+jumpPara.getId()+" -> "+jumpGroup.getUnitGroupId());
|
||||
//buf.append(";\n");
|
||||
//}
|
||||
//}
|
||||
}
|
||||
buf.append("}\n");
|
||||
System.out.println("dot: \n"+buf.toString());
|
||||
FileUtils.write(new File("target/groups.dot"), buf.toString(), Charset.forName("UTF-8"), false);
|
||||
|
||||
List<UnitXConverterStep> steps = new ArrayList<>();
|
||||
result.getResultSteps().forEach(v -> steps.add(v.getConvertStep()));
|
||||
|
||||
String code = RuleStepCodePrinter.print(RuleStepCodeStyle.JAVASCRIPT, steps, result.getStartTypeId()+"_to_"+result.getResultTypeId());
|
||||
System.out.println("\n\ncode: \n"+code);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import static org.junit.Assert.assertFalse;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleTemperature;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleKelvin;
|
||||
|
||||
public class UnitXCManagerTest {
|
||||
|
||||
|
@ -20,7 +20,7 @@ public class UnitXCManagerTest {
|
|||
|
||||
@Test
|
||||
public void testGetUnitType() {
|
||||
assertNotNull(test.getUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID));
|
||||
assertNotNull(test.getUnitType(UnitXCModuleKelvin.TYPE_KELVIN_ID));
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
|
@ -35,22 +35,22 @@ public class UnitXCManagerTest {
|
|||
|
||||
@Test
|
||||
public void testGetUnitTypeResultId() {
|
||||
assertNotNull(test.getUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID).getId());
|
||||
assertNotNull(test.getUnitType(UnitXCModuleKelvin.TYPE_KELVIN_ID).getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUnitTypeResultName() {
|
||||
assertNotNull(test.getUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID).getName());
|
||||
assertNotNull(test.getUnitType(UnitXCModuleKelvin.TYPE_KELVIN_ID).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUnitTypeResultTypeFlags() {
|
||||
assertNotNull(test.getUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID).getTypeFlags());
|
||||
assertNotNull(test.getUnitType(UnitXCModuleKelvin.TYPE_KELVIN_ID).getTypeFlags());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUnitTypeGroup() {
|
||||
assertNotNull(test.getUnitGroup(UnitXCModuleTemperature.GROUP_ID));
|
||||
assertNotNull(test.getUnitGroup(UnitXCModuleKelvin.GROUP_ID));
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
|
@ -65,27 +65,22 @@ public class UnitXCManagerTest {
|
|||
|
||||
@Test
|
||||
public void testGetUnitTypeGroupResultId() {
|
||||
assertNotNull(test.getUnitGroup(UnitXCModuleTemperature.GROUP_ID).getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUnitTypeGroupResultName() {
|
||||
assertNotNull(test.getUnitGroup(UnitXCModuleTemperature.GROUP_ID).getName());
|
||||
assertNotNull(test.getUnitGroup(UnitXCModuleKelvin.GROUP_ID).getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUnitTypeGroupResultDescription() {
|
||||
assertNotNull(test.getUnitGroup(UnitXCModuleTemperature.GROUP_ID).getDescription());
|
||||
assertNotNull(test.getUnitGroup(UnitXCModuleKelvin.GROUP_ID).getDescription());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUnitTypeResultTypeBaseTypeID() {
|
||||
assertNotNull(test.getUnitGroup(UnitXCModuleTemperature.GROUP_ID).getBaseTypeId());
|
||||
assertNotNull(test.getUnitGroup(UnitXCModuleKelvin.GROUP_ID).getBaseTypeId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsUnitTypeGroupTrue() {
|
||||
assertTrue(test.isUnitGroup(UnitXCModuleTemperature.GROUP_ID));
|
||||
assertTrue(test.isUnitGroup(UnitXCModuleKelvin.GROUP_ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue