First version with unit types on request.
This commit is contained in:
parent
aed5d0d03a
commit
5076d2be55
|
@ -1,11 +1,12 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>net.forwardfire.unitxc</groupId>
|
||||
<artifactId>ff-unitxc</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>ff-unitxc-converter</artifactId>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>net.forwardfire.unitxc</groupId>
|
||||
<artifactId>ff-unitxc</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>ff-unitxc-converter</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
|
@ -17,5 +18,11 @@
|
|||
<artifactId>commons-lang3</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jettison</groupId>
|
||||
<artifactId>jettison</artifactId>
|
||||
<version>1.3.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -27,19 +27,30 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfig;
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigManager;
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.model.UnitXCConfig;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleSubstance;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleArea;
|
||||
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.UnitXCModuleSpeed;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleTemperature;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleVolume;
|
||||
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.named.UnitXCModuleNewton;
|
||||
|
||||
/**
|
||||
* The unit cross converter factory to create the manager.
|
||||
|
@ -57,9 +68,25 @@ public final class UnitXCFactory {
|
|||
new UnitXCModuleLength(),
|
||||
new UnitXCModuleMass(),
|
||||
new UnitXCModuleTime(),
|
||||
|
||||
// currently ordered here
|
||||
new UnitXCModuleArea(),
|
||||
new UnitXCModuleVolume(),
|
||||
new UnitXCModuleSpeed()
|
||||
new UnitXCModuleSpeed(),
|
||||
new UnitXCModuleVolumetricFlow(),
|
||||
new UnitXCModuleAcceleration(),
|
||||
new UnitXCModuleJerk(),
|
||||
new UnitXCModuleJounce(),
|
||||
|
||||
// named
|
||||
//new UnitXCModuleNewton(),
|
||||
|
||||
// more derived
|
||||
new UnitXCModuleAreaDensity(),
|
||||
new UnitXCModuleMassDensity(),
|
||||
new UnitXCModuleSpecificVolume(),
|
||||
new UnitXCModuleMolarConcentration(),
|
||||
new UnitXCModuleMolarVolume()
|
||||
));
|
||||
|
||||
|
||||
|
@ -67,12 +94,18 @@ public final class UnitXCFactory {
|
|||
}
|
||||
|
||||
|
||||
private static UnitXCConfig buildAll(UnitXCConfig config,List<UnitXCConfigModule> configInit) {
|
||||
UnitXCConfigBuilder builder = new UnitXCConfigBuilder(config);
|
||||
configInit.forEach(ci -> ci.configModule(builder));
|
||||
return config;
|
||||
}
|
||||
|
||||
public static UnitXCConfig createConfig() {
|
||||
return createConfig(DEFAULT_CONFIG_MODULES);
|
||||
}
|
||||
|
||||
public static UnitXCConfig createConfig(List<UnitXCConfigModule> configInit) {
|
||||
return UnitXCConfigModule.buildAll(new UnitXCConfig(), configInit);
|
||||
return buildAll(new UnitXCConfig(), configInit);
|
||||
}
|
||||
|
||||
public static UnitXCManager createManager() {
|
||||
|
|
|
@ -23,10 +23,9 @@
|
|||
|
||||
package net.forwardfire.unitxc;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.forwardfire.unitxc.converter.UnitXConverter;
|
||||
import net.forwardfire.unitxc.model.UnitXCType;
|
||||
import net.forwardfire.unitxc.model.UnitXCConfig;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroup;
|
||||
|
||||
/**
|
||||
|
@ -37,23 +36,13 @@ import net.forwardfire.unitxc.model.UnitXCGroup;
|
|||
*/
|
||||
public interface UnitXCManager {
|
||||
|
||||
/**
|
||||
* @return Returns all unit types.
|
||||
*/
|
||||
Collection<UnitXCType> getUnitTypes();
|
||||
|
||||
UnitXCType getUnitType(String id);
|
||||
|
||||
boolean isUnitType(String id);
|
||||
|
||||
/**
|
||||
* @return Returns all unit groups.
|
||||
*/
|
||||
Collection<UnitXCGroup> getUnitGroups();
|
||||
|
||||
UnitXCGroup getUnitGroup(String id);
|
||||
|
||||
boolean isUnitGroup(String id);
|
||||
|
||||
UnitXConverter getConverter();
|
||||
|
||||
UnitXCConfig getConfig();
|
||||
}
|
||||
|
|
|
@ -32,10 +32,9 @@ import org.apache.commons.lang3.Validate;
|
|||
|
||||
import net.forwardfire.unitxc.UnitXCManager;
|
||||
import net.forwardfire.unitxc.converter.UnitXConverter;
|
||||
import net.forwardfire.unitxc.converter.UnitXConverterEngine;
|
||||
import net.forwardfire.unitxc.model.UnitXCType;
|
||||
import net.forwardfire.unitxc.model.UnitXCConfig;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroup;
|
||||
import net.forwardfire.unitxc.model.UnitXConverterResult;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -46,66 +45,39 @@ import net.forwardfire.unitxc.model.UnitXConverterResult;
|
|||
public class UnitXCConfigManager implements UnitXCManager {
|
||||
|
||||
private final UnitXCConfig config;
|
||||
private final Map<String,UnitXCType> unitTypes;
|
||||
private final Map<String,UnitXCGroup> unitGroups;
|
||||
private final UnitXConverter converter;
|
||||
private final UnitXConverterEngine convertEngine;
|
||||
|
||||
public UnitXCConfigManager(UnitXCConfig config) {
|
||||
this.config = Validate.notNull(config);
|
||||
this.unitTypes = Collections.unmodifiableMap(createUnitTypes(config.getUnitTypes()));
|
||||
this.unitGroups = Collections.unmodifiableMap(createUnitGroups(config.getUnitroups()));
|
||||
|
||||
this.convertEngine = new UnitXConverterEngine(this);
|
||||
this.converter = new UnitXConverterImpl();
|
||||
}
|
||||
|
||||
private static Map<String,UnitXCType> createUnitTypes(Collection<UnitXCType> values) {
|
||||
Map<String,UnitXCType> result = new HashMap<>();
|
||||
values.forEach((value) -> {
|
||||
putValue(result,value.getId(),value);
|
||||
if (!value.getId().equals(value.getName())) { // fix time group
|
||||
putValue(result,value.getName(),value);
|
||||
}
|
||||
if (!value.getName().equals(value.getNamePlural())) { // mmm normal
|
||||
putValue(result,value.getNamePlural(),value);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void putValue(Map<String,UnitXCType> result,String key,UnitXCType value) {
|
||||
if (key == null) {
|
||||
return;
|
||||
}
|
||||
Validate.isTrue(!result.containsKey(key),"Duplicate key: "+key);
|
||||
result.put(key, value);
|
||||
this.unitGroups = Collections.unmodifiableMap(createUnitGroups(config.getUnitGroups()));
|
||||
this.converter = new UnitXConverter(this);
|
||||
}
|
||||
|
||||
private static Map<String,UnitXCGroup> createUnitGroups(Collection<UnitXCGroup> values) {
|
||||
Map<String,UnitXCGroup> result = new HashMap<>();
|
||||
values.forEach((value) -> result.put(value.getId(), value));
|
||||
values.forEach((value) -> {
|
||||
value.setTotalUnitTypes(value.getTypeGenerator().size());
|
||||
result.put(value.getId(), value);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<UnitXCType> getUnitTypes() {
|
||||
return unitTypes.values();
|
||||
public UnitXCConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXCType getUnitType(String id) {
|
||||
return Validate.notNull(unitTypes.get(Validate.notNull(id,"Null is not a validate id.")),"No type for: "+id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnitType(String id) {
|
||||
return unitTypes.containsKey(Validate.notBlank(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<UnitXCGroup> getUnitGroups() {
|
||||
return unitGroups.values();
|
||||
UnitXCType result = null;
|
||||
for (UnitXCGroup group:unitGroups.values()) {
|
||||
result = group.getTypeGenerator().getUnitType(id);
|
||||
if (result != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -122,29 +94,5 @@ public class UnitXCConfigManager implements UnitXCManager {
|
|||
public UnitXConverter getConverter() {
|
||||
return converter;
|
||||
}
|
||||
|
||||
private class UnitXConverterImpl implements UnitXConverter {
|
||||
|
||||
|
||||
@Override
|
||||
public double convert(double value, String fromTypeId, String toTypeId) {
|
||||
return convert(value, getUnitType(fromTypeId), getUnitType(toTypeId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double convert(double value, UnitXCType fromType, UnitXCType toType) {
|
||||
return convertStepped(value,fromType,toType).getResultValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXConverterResult convertStepped(double value, String fromTypeId, String toTypeId) {
|
||||
return convertStepped(value, getUnitType(fromTypeId), getUnitType(toTypeId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXConverterResult convertStepped(double value, UnitXCType fromType, UnitXCType toType) {
|
||||
// TODO: rm casting
|
||||
return convertEngine.convertStepped(value, (UnitXCType)fromType, (UnitXCType)toType);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
package net.forwardfire.unitxc.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
|
||||
|
@ -43,10 +42,4 @@ public interface UnitXCConfigModule {
|
|||
Arrays.asList(flag).forEach(f -> buf.append(f.toUpperCase()).append("_"));
|
||||
return buf.deleteCharAt(buf.length()-1).toString();
|
||||
}
|
||||
|
||||
static UnitXCConfig buildAll(UnitXCConfig config,List<UnitXCConfigModule> configInit) {
|
||||
UnitXCConfigBuilder builder = new UnitXCConfigBuilder(config);
|
||||
configInit.forEach(ci -> ci.configModule(builder));
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@ import java.util.Collection;
|
|||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import net.forwardfire.unitxc.converter.step.UnitXConverterStep;
|
||||
import net.forwardfire.unitxc.model.UnitXCType;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStep;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -76,10 +76,6 @@ public abstract class AbstractUnitXCTypeBuilder<P,B> extends AbstractUnitXCBuild
|
|||
return make((v) -> v.setAliasOfType(aliasOfType));
|
||||
}
|
||||
|
||||
public B setTypeGroupId(String typeGroupId) {
|
||||
return make((v) -> v.setUnitGroupId(typeGroupId));
|
||||
}
|
||||
|
||||
public B addWebsiteWiki(String websiteLink) {
|
||||
return addWebsiteLink("https://en.wikipedia.org/wiki/"+websiteLink);
|
||||
}
|
||||
|
@ -105,11 +101,11 @@ public abstract class AbstractUnitXCTypeBuilder<P,B> extends AbstractUnitXCBuild
|
|||
}
|
||||
|
||||
public UnitXConverterStepBuilder<AbstractUnitXCTypeBuilder<P,B>> createFromBaseConverterSteps() {
|
||||
return new UnitXConverterStepBuilder<>(this,(p,v) -> p.addFromBaseConverterSteps(v));
|
||||
return new UnitXConverterStepBuilder<>(this,(p,v) -> p.addFromBaseConverterSteps(v),() -> "convert "+getValue().getId());
|
||||
}
|
||||
|
||||
public UnitXConverterStepBuilder<AbstractUnitXCTypeBuilder<P,B>> createToBaseConverterSteps() {
|
||||
return new UnitXConverterStepBuilder<>(this,(p,v) -> p.addToBaseConverterSteps(v));
|
||||
return new UnitXConverterStepBuilder<>(this,(p,v) -> p.addToBaseConverterSteps(v),() -> "convert "+getValue().getId());
|
||||
}
|
||||
|
||||
public B addFromBaseConverterStep(UnitXConverterStep unitTypeConverter) {
|
||||
|
|
|
@ -25,7 +25,8 @@ package net.forwardfire.unitxc.config.builder;
|
|||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfig;
|
||||
import net.forwardfire.unitxc.model.UnitXCConfig;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroup;
|
||||
import net.forwardfire.unitxc.model.UnitXCType;
|
||||
|
||||
/**
|
||||
|
@ -51,15 +52,22 @@ public class UnitXCConfigBuilder {
|
|||
}
|
||||
|
||||
public UnitXCGroupBuilder createUnitGroup() {
|
||||
return new UnitXCGroupBuilder(this);
|
||||
return new UnitXCGroupBuilder(this, new UnitXCGroup(), (p,v) -> p.getConfig().addUnitGroup(v));
|
||||
}
|
||||
|
||||
public UnitXCTypeBuilder<UnitXCConfigBuilder> createUnitType() {
|
||||
return new UnitXCTypeBuilder<>(this,new UnitXCType(),(p,v) -> p.getConfig().addUnitType(v));
|
||||
public UnitXCGroupBuilder extendUnitGroup(String groupId) {
|
||||
UnitXCGroup group = findGroup(groupId);
|
||||
return new UnitXCGroupBuilder(this, group, (p,v) -> {});
|
||||
}
|
||||
|
||||
private UnitXCType findType(String id) {
|
||||
for (UnitXCType m:config.getUnitTypes()) {
|
||||
public UnitXCTypeBuilder<UnitXCConfigBuilder> createUnitType(String groupId) {
|
||||
UnitXCGroup group = findGroup(groupId);
|
||||
return new UnitXCTypeBuilder<>(this,new UnitXCType(),(p,v) -> group.addUnitType(v));
|
||||
}
|
||||
|
||||
private UnitXCGroup findGroup(String id) {
|
||||
Validate.notBlank(id,"Can't search blank id.");
|
||||
for (UnitXCGroup m:config.getUnitGroups()) {
|
||||
if (m.getId().equals(id)) {
|
||||
return m;
|
||||
}
|
||||
|
@ -67,7 +75,16 @@ public class UnitXCConfigBuilder {
|
|||
throw new IllegalArgumentException("Could not find: "+id);
|
||||
}
|
||||
|
||||
public UnitXCTypeBuilder<UnitXCConfigBuilder> extendUnitType(String id) {
|
||||
return new UnitXCTypeBuilder<>(this,findType(id),(p,v) -> {});
|
||||
}
|
||||
// private UnitXCType findType(String id) {
|
||||
// for (UnitXCType m:config.getUnitTypes()) {
|
||||
// if (m.getId().equals(id)) {
|
||||
// return m;
|
||||
// }
|
||||
// }
|
||||
// throw new IllegalArgumentException("Could not find: "+id);
|
||||
// }
|
||||
//
|
||||
// public UnitXCTypeBuilder<UnitXCConfigBuilder> extendUnitType(String id) {
|
||||
// return new UnitXCTypeBuilder<>(this,findType(id),(p,v) -> {});
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -23,9 +23,15 @@
|
|||
|
||||
package net.forwardfire.unitxc.config.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import net.forwardfire.unitxc.model.UnitXCGroup;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupLevel;
|
||||
import net.forwardfire.unitxc.model.UnitXCType;
|
||||
import net.forwardfire.unitxc.model.UnitXCTypeGenerator;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -35,8 +41,37 @@ import net.forwardfire.unitxc.model.UnitXCType;
|
|||
*/
|
||||
public class UnitXCGroupBuilder extends AbstractUnitXCBuilder<UnitXCConfigBuilder,UnitXCGroup,UnitXCGroupBuilder> {
|
||||
|
||||
public UnitXCGroupBuilder(UnitXCConfigBuilder parent) {
|
||||
super(parent, new UnitXCGroup(), (p,v) -> p.getConfig().addUnitGroup(v));
|
||||
public UnitXCGroupBuilder(UnitXCConfigBuilder parent, UnitXCGroup model, BiConsumer<UnitXCConfigBuilder, UnitXCGroup> parentBuilder) {
|
||||
super(parent, model, parentBuilder);
|
||||
if (model.getTypeGenerator() == null) {
|
||||
model.setTypeGenerator(new UnitXCTypeGenerator() {
|
||||
|
||||
@Override
|
||||
public long size() {
|
||||
return model.getUnitTypes().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<String> getUnitTypes() {
|
||||
List<String> result = new ArrayList<>();
|
||||
model.getUnitTypes().forEach(t -> result.add(t.getId()));
|
||||
return result.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXCType getUnitType(String id) {
|
||||
for (UnitXCType type:model.getUnitTypes()) {
|
||||
if (type.getId().equals(id)) {
|
||||
return type;
|
||||
}
|
||||
if (type.getName().equals(id)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,20 +79,24 @@ public class UnitXCGroupBuilder extends AbstractUnitXCBuilder<UnitXCConfigBuilde
|
|||
return this;
|
||||
}
|
||||
|
||||
public UnitXCGroupJumpBuilder createGroupJump(String unitGroupId) {
|
||||
return new UnitXCGroupJumpBuilder(getParent(),getValue(),unitGroupId);
|
||||
}
|
||||
|
||||
public UnitXCTypeBuilder<UnitXCGroupBuilder> createUnitType() {
|
||||
return new UnitXCTypeBuilder<>(this,new UnitXCType(),(p,v) -> p.getParent().getConfig().addUnitType(v)).setTypeGroupId(getValue().getId());
|
||||
return new UnitXCTypeBuilder<>(this,new UnitXCType(),(p,v) -> p.getValue().addUnitType(v));
|
||||
}
|
||||
|
||||
public UnitXCTypeSIPrefixBuilder<UnitXCGroupBuilder> createSIUnitTypes() {
|
||||
return new UnitXCTypeSIPrefixBuilder<>(this,getParent()).setTypeGroupId(getValue().getId());
|
||||
return new UnitXCTypeSIPrefixBuilder<>(this,this);
|
||||
}
|
||||
|
||||
public UnitXCTypeCompoundExponentBuilder createCompoundExponentUnitTypes(String unitTypeGroupId,int exponent) {
|
||||
return new UnitXCTypeCompoundExponentBuilder(this,getParent(),unitTypeGroupId,exponent);
|
||||
public UnitXCTypeCompoundExponentBuilder createCompoundExponentUnitTypes(String unitTypeId, int exponent) {
|
||||
return new UnitXCTypeCompoundExponentBuilder(this, unitTypeId, exponent);
|
||||
}
|
||||
|
||||
public UnitXCTypeCompoundPairBuilder createCompoundPairUnitTypes(String groupId,String perGroupId) {
|
||||
return new UnitXCTypeCompoundPairBuilder(this,getParent(),groupId,perGroupId);
|
||||
return new UnitXCTypeCompoundPairBuilder(this,groupId,perGroupId);
|
||||
}
|
||||
|
||||
public UnitXCGroupBuilder setId(String id) {
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.config.builder;
|
||||
|
||||
|
||||
import net.forwardfire.unitxc.model.UnitXCGroup;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupJump;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupJumpParameter;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 1, 2016
|
||||
*/
|
||||
public class UnitXCGroupJumpBuilder extends AbstractUnitXCBuilder<UnitXCConfigBuilder,UnitXCGroupJump,UnitXCGroupJumpBuilder> {
|
||||
|
||||
public UnitXCGroupJumpBuilder(UnitXCConfigBuilder parent, UnitXCGroup forGroup, String unitGroupId) {
|
||||
super(parent, new UnitXCGroupJump(), (b,v) -> forGroup.getGroupJumps().add(v));
|
||||
getValue().setUnitGroupId(unitGroupId);
|
||||
getValue().setId(forGroup.getId()+"_"+unitGroupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UnitXCGroupJumpBuilder getBuilder() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public UnitXCGroupJumpBuilder setId(String id) {
|
||||
return make((v) -> v.setId(id));
|
||||
}
|
||||
|
||||
public UnitXCGroupJumpBuilder addJumpParameter(String id,String unitGroupId) {
|
||||
return make((v) -> v.addJumpParameter(new UnitXCGroupJumpParameter(id, unitGroupId)));
|
||||
}
|
||||
|
||||
public UnitXConverterStepBuilder<UnitXCGroupJumpBuilder> createToGroupConverterSteps() {
|
||||
return new UnitXConverterStepBuilder<>(this,(p,v) -> getValue().getToGroupConverterSteps().addAll(v),() -> "group jump");
|
||||
}
|
||||
}
|
|
@ -23,14 +23,14 @@
|
|||
|
||||
package net.forwardfire.unitxc.config.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.unitxc.converter.step.UnitXConverterStep;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroup;
|
||||
import net.forwardfire.unitxc.model.UnitXCType;
|
||||
import net.forwardfire.unitxc.model.UnitXCTypeGenerator;
|
||||
import net.forwardfire.unitxc.model.step.UnitXCConverterStepReference;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -40,17 +40,75 @@ import net.forwardfire.unitxc.model.UnitXCType;
|
|||
*/
|
||||
public class UnitXCTypeCompoundExponentBuilder extends AbstractUnitXCBuilder<UnitXCGroupBuilder,Object,UnitXCTypeCompoundExponentBuilder> {
|
||||
|
||||
private final UnitXCConfigBuilder builder;
|
||||
private final String unitGroupId;
|
||||
private final int exponent;
|
||||
private String unitIdPostfix;
|
||||
private String unitNamePrefix;
|
||||
|
||||
public UnitXCTypeCompoundExponentBuilder(UnitXCGroupBuilder parent, UnitXCConfigBuilder builder,String unitGroupId,int exponent) {
|
||||
public UnitXCTypeCompoundExponentBuilder(UnitXCGroupBuilder parent, String unitGroupId, int exponent) {
|
||||
super(parent,new Object(), (p,v) -> {});
|
||||
this.builder = builder;
|
||||
this.unitGroupId = unitGroupId;
|
||||
this.exponent = exponent;
|
||||
parent.getValue().setTypeGenerator(new UnitXCTypeGenerator() {
|
||||
|
||||
UnitXCGroup getGroup() {
|
||||
UnitXCGroup group = null;
|
||||
for (UnitXCGroup unitGroup:getParent().getParent().getConfig().getUnitGroups()) {
|
||||
if (unitGroup.getId().equals(unitGroupId)) {
|
||||
group = unitGroup;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long size() {
|
||||
return getGroup().getTypeGenerator().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<String> getUnitTypes() {
|
||||
Iterator<String> g = getGroup().getTypeGenerator().getUnitTypes();
|
||||
return new Iterator<String>() {
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return g.hasNext();
|
||||
}
|
||||
@Override
|
||||
public String next() {
|
||||
return g.next()+unitIdPostfix;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXCType getUnitType(String id) {
|
||||
if (!id.endsWith(unitIdPostfix)) {
|
||||
return null;
|
||||
}
|
||||
String idRaw = id.substring(0, id.length()-unitIdPostfix.length());
|
||||
UnitXCGroup group = getGroup();
|
||||
UnitXCType unitType = group.getTypeGenerator().getUnitType(idRaw);
|
||||
if (unitType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
UnitXCTypeBuilder<Object> typeBuilder = new UnitXCTypeBuilder<>(this,new UnitXCType(),(p,v) -> {});
|
||||
typeBuilder
|
||||
.setId(unitType.getId()+unitIdPostfix)
|
||||
.setName(unitNamePrefix+unitType.getName())
|
||||
.addTypeFlags(unitType.getTypeFlags());
|
||||
|
||||
for (int i=0;i<UnitXCTypeCompoundExponentBuilder.this.exponent;i++) {
|
||||
typeBuilder.addToBaseConverterStep(new UnitXCConverterStepReference(unitType.getId(),true));
|
||||
typeBuilder.addFromBaseConverterStep(new UnitXCConverterStepReference(unitType.getId(),false));
|
||||
}
|
||||
typeBuilder.build();
|
||||
typeBuilder.getValue().setUnitGroup(parent.getValue());
|
||||
return typeBuilder.getValue();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,7 +120,7 @@ public class UnitXCTypeCompoundExponentBuilder extends AbstractUnitXCBuilder<Uni
|
|||
protected void buildPreValue(Object v) {
|
||||
|
||||
UnitXCGroup group = null;
|
||||
for (UnitXCGroup unitGroup:builder.getConfig().getUnitroups()) {
|
||||
for (UnitXCGroup unitGroup:getParent().getParent().getConfig().getUnitGroups()) {
|
||||
if (unitGroup.getId().equals(unitGroupId)) {
|
||||
group = unitGroup;
|
||||
break;
|
||||
|
@ -71,35 +129,6 @@ public class UnitXCTypeCompoundExponentBuilder extends AbstractUnitXCBuilder<Uni
|
|||
Validate.notNull(group,"Could not find group: "+unitGroupId);
|
||||
|
||||
getParent().getValue().getDerivedFrom().add(unitGroupId);
|
||||
|
||||
for (UnitXCType unitType:new ArrayList<>(builder.getConfig().getUnitTypes())) {
|
||||
if (!unitType.getUnitGroupId().equals(group.getId())) {
|
||||
continue;
|
||||
}
|
||||
UnitXCTypeBuilder<UnitXCConfigBuilder> typeBuilder = builder.createUnitType()
|
||||
.setId(unitType.getId()+unitIdPostfix)
|
||||
.setName(unitNamePrefix+unitType.getName())
|
||||
.setTypeGroupId(getParent().getValue().getId())
|
||||
.addTypeFlags(unitType.getTypeFlags());
|
||||
|
||||
for (int i=0;i<exponent;i++) {
|
||||
typeBuilder.addToBaseConverterSteps(cloneSteps(exponent,unitType.getToBaseConverterSteps()));
|
||||
typeBuilder.addFromBaseConverterSteps(cloneSteps(exponent,unitType.getFromBaseConverterSteps()));
|
||||
}
|
||||
typeBuilder.build();
|
||||
}
|
||||
}
|
||||
|
||||
private List<UnitXConverterStep> cloneSteps(int exponent,List<UnitXConverterStep> steps) {
|
||||
List<UnitXConverterStep> result = new ArrayList<>();
|
||||
for (UnitXConverterStep step:steps) {
|
||||
UnitXConverterStep clone = step.clone();
|
||||
if (exponent != 0) {
|
||||
clone.addStepReason("CompoundExponent: "+exponent);
|
||||
}
|
||||
result.add(clone);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public UnitXCTypeCompoundExponentBuilder setUnitIdPostfix(String unitIdPostfix) {
|
||||
|
|
|
@ -23,35 +23,124 @@
|
|||
|
||||
package net.forwardfire.unitxc.config.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.unitxc.converter.step.UnitXConverterStep;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroup;
|
||||
import net.forwardfire.unitxc.model.UnitXCType;
|
||||
import net.forwardfire.unitxc.model.UnitXCTypeGenerator;
|
||||
import net.forwardfire.unitxc.model.step.UnitXCConverterStepReference;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueNamedParameter;
|
||||
|
||||
/**
|
||||
*
|
||||
* Build compound pair units.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 26, 2015
|
||||
*/
|
||||
public class UnitXCTypeCompoundPairBuilder extends AbstractUnitXCBuilder<UnitXCGroupBuilder,Object,UnitXCTypeCompoundPairBuilder> {
|
||||
public class UnitXCTypeCompoundPairBuilder extends AbstractUnitXCBuilder<UnitXCGroupBuilder,UnitXCGroup,UnitXCTypeCompoundPairBuilder> {
|
||||
|
||||
public static final String PER_ID = "/";
|
||||
public static final String PER_NAME = " per ";
|
||||
|
||||
private final UnitXCConfigBuilder builder;
|
||||
private final String groupId;
|
||||
private final String perGroupId;
|
||||
|
||||
public UnitXCTypeCompoundPairBuilder(UnitXCGroupBuilder parent, UnitXCConfigBuilder builder,String groupId,String perGroupId) {
|
||||
super(parent,new Object(), (p,v) -> {});
|
||||
this.builder = builder;
|
||||
public UnitXCTypeCompoundPairBuilder(UnitXCGroupBuilder parent,String groupId,String perGroupId) {
|
||||
super(parent,parent.getValue(), (p,v) -> {});
|
||||
this.groupId = groupId;
|
||||
this.perGroupId = perGroupId;
|
||||
|
||||
parent.getValue().setTypeGenerator(new UnitXCTypeGenerator() {
|
||||
|
||||
UnitXCGroup getGroup(String id) {
|
||||
UnitXCGroup perGroup = null;
|
||||
for (UnitXCGroup unitGroup:getParent().getParent().getConfig().getUnitGroups()) {
|
||||
if (unitGroup.getId().equals(id)) {
|
||||
perGroup = unitGroup;
|
||||
}
|
||||
}
|
||||
return perGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long size() {
|
||||
UnitXCGroup group = getGroup(groupId);
|
||||
UnitXCGroup perGroup = getGroup(perGroupId);
|
||||
return group.getTypeGenerator().size()*perGroup.getTypeGenerator().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<String> getUnitTypes() {
|
||||
UnitXCGroup group = getGroup(groupId);
|
||||
UnitXCGroup perGroup = getGroup(perGroupId);
|
||||
Iterator<String> groupIt = group.getTypeGenerator().getUnitTypes();
|
||||
return new Iterator<String>() {
|
||||
|
||||
String groupId2;
|
||||
Iterator<String> perGroupIt;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if (perGroupIt!=null && perGroupIt.hasNext()) {
|
||||
return true;
|
||||
}
|
||||
if (groupIt.hasNext()) {
|
||||
groupId2 = groupIt.next();
|
||||
perGroupIt = perGroup.getTypeGenerator().getUnitTypes();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String next() {
|
||||
return groupId2+PER_ID+perGroupIt.next();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXCType getUnitType(String id) {
|
||||
if (!id.contains(PER_ID)) {
|
||||
return null;
|
||||
}
|
||||
UnitXCGroup group = getGroup(groupId);
|
||||
UnitXCGroup perGroup = getGroup(perGroupId);
|
||||
Validate.notNull(group,"Could not find group: "+groupId);
|
||||
Validate.notNull(perGroup,"Could not find group: "+perGroupId);
|
||||
|
||||
String idGroup = id.substring(0,id.lastIndexOf(PER_ID)); // FIXME parse correctly see newton
|
||||
String idGroupPer = id.substring(id.lastIndexOf(PER_ID)+1);
|
||||
|
||||
UnitXCType unitType = group.getTypeGenerator().getUnitType(idGroup);
|
||||
if (unitType == null) {
|
||||
return null;
|
||||
}
|
||||
UnitXCType perUnitType = perGroup.getTypeGenerator().getUnitType(idGroupPer);
|
||||
if (perUnitType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO: add name/name alias
|
||||
UnitXCTypeBuilder<Object> typeBuilder = new UnitXCTypeBuilder<>(this,new UnitXCType(),(p,v) -> {});
|
||||
typeBuilder
|
||||
.setId(id)
|
||||
.setName(unitType.getName()+PER_NAME+perUnitType.getName())
|
||||
.addTypeFlags(unitType.getTypeFlags())
|
||||
.addTypeFlags(perUnitType.getTypeFlags());
|
||||
|
||||
typeBuilder.addToBaseConverterStep(new UnitXCConverterStepReference(unitType.getId(),true));
|
||||
typeBuilder.addToBaseConverterStep(new UnitXCConverterStepReference(perUnitType.getId(),false));
|
||||
typeBuilder.addFromBaseConverterStep(new UnitXCConverterStepReference(perUnitType.getId(),true));
|
||||
typeBuilder.addFromBaseConverterStep(new UnitXCConverterStepReference(unitType.getId(),false));
|
||||
typeBuilder.build();
|
||||
typeBuilder.getValue().setUnitGroup(parent.getValue());
|
||||
return typeBuilder.getValue();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,11 +149,11 @@ public class UnitXCTypeCompoundPairBuilder extends AbstractUnitXCBuilder<UnitXCG
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void buildPreValue(Object v) {
|
||||
protected void buildPreValue(UnitXCGroup value) {
|
||||
|
||||
UnitXCGroup group = null;
|
||||
UnitXCGroup perGroup = null;
|
||||
for (UnitXCGroup unitGroup:builder.getConfig().getUnitroups()) {
|
||||
for (UnitXCGroup unitGroup:getParent().getParent().getConfig().getUnitGroups()) {
|
||||
if (unitGroup.getId().equals(groupId)) {
|
||||
group = unitGroup;
|
||||
}
|
||||
|
@ -77,46 +166,38 @@ public class UnitXCTypeCompoundPairBuilder extends AbstractUnitXCBuilder<UnitXCG
|
|||
|
||||
getParent().getValue().getDerivedFrom().add(groupId);
|
||||
getParent().getValue().getDerivedFrom().add(perGroupId);
|
||||
//
|
||||
// UnitXCGroupJump toGroupJump = new UnitXCGroupJump();
|
||||
// toGroupJump.setId("to_"+group.getId());
|
||||
// toGroupJump.setUnitGroup(group);
|
||||
// toGroupJump.addJumpParameter(new UnitXCGroupJumpParameter("to_"+perGroup.getId(),"",perGroup.getId()));
|
||||
//
|
||||
// UnitXCGroupJump perGroupJump = new UnitXCGroupJump();
|
||||
// perGroupJump.setId("to_"+group.getId());
|
||||
// perGroupJump.setUnitGroup(group);
|
||||
|
||||
List<UnitXCType> types = new ArrayList<>(builder.getConfig().getUnitTypes());
|
||||
//getValue().getGroupJumps().add(toGroupJump); // m/s -> m
|
||||
//getValue().getGroupJumps().add(perGroupJump); // m/s -> h
|
||||
|
||||
for (UnitXCType unitType:types) {
|
||||
if (!unitType.getUnitGroupId().equals(group.getId())) {
|
||||
continue;
|
||||
}
|
||||
for (UnitXCType perUnitType:types) {
|
||||
if (!perUnitType.getUnitGroupId().equals(perGroup.getId())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: add name/name alias
|
||||
UnitXCTypeBuilder<UnitXCConfigBuilder> typeBuilder = builder.createUnitType()
|
||||
.setId(unitType.getId()+PER_ID+perUnitType.getId())
|
||||
.setName(unitType.getName()+PER_NAME+perUnitType.getName())
|
||||
.setTypeGroupId(getParent().getValue().getId())
|
||||
.addTypeFlags(unitType.getTypeFlags())
|
||||
.addTypeFlags(perUnitType.getTypeFlags());
|
||||
|
||||
typeBuilder.addToBaseConverterSteps(cloneSteps(unitType.getToBaseConverterSteps(),true));
|
||||
typeBuilder.addToBaseConverterSteps(cloneSteps(perUnitType.getFromBaseConverterSteps(),false));
|
||||
typeBuilder.addFromBaseConverterSteps(cloneSteps(perUnitType.getToBaseConverterSteps(),true));
|
||||
typeBuilder.addFromBaseConverterSteps(cloneSteps(unitType.getFromBaseConverterSteps(),false));
|
||||
typeBuilder.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<UnitXConverterStep> cloneSteps(List<UnitXConverterStep> steps,boolean pairBase) {
|
||||
List<UnitXConverterStep> result = new ArrayList<>();
|
||||
for (UnitXConverterStep step:steps) {
|
||||
UnitXConverterStep clone = step.clone();
|
||||
if (pairBase) {
|
||||
clone.addStepReason("CompoundPair base");
|
||||
} else {
|
||||
clone.addStepReason("CompoundPair reverse");
|
||||
}
|
||||
result.add(clone);
|
||||
}
|
||||
return result;
|
||||
//group.getGroupJumps().add(toGroupJump); // m -> m/s
|
||||
//perGroup.getGroupJumps().add(perGroupJump); // s -> m/s
|
||||
|
||||
// m/s -> m
|
||||
getParent()
|
||||
.createGroupJump(group.getId())
|
||||
.addJumpParameter(value.getId()+"_"+perGroup.getId(),perGroup.getId())
|
||||
.createToGroupConverterSteps()
|
||||
.multiply(new UnitXConverterStepValueNamedParameter(value.getId()+"_"+perGroup.getId()))
|
||||
.build()
|
||||
.build();
|
||||
|
||||
// m -> m/s
|
||||
getParent().getParent().extendUnitGroup(group.getId())
|
||||
.createGroupJump(value.getId())
|
||||
.addJumpParameter(value.getId()+"_"+perGroup.getId(),perGroup.getId())
|
||||
.createToGroupConverterSteps()
|
||||
.divide(new UnitXConverterStepValueNamedParameter(value.getId()+"_"+perGroup.getId()))
|
||||
.build()
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,8 +28,9 @@ import java.util.Arrays;
|
|||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.forwardfire.unitxc.converter.step.UnitXCTypePowerOfTenConverterStep;
|
||||
import net.forwardfire.unitxc.model.UnitXCType;
|
||||
import net.forwardfire.unitxc.model.step.UnitXCConverterStepPowerOfTen;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -39,10 +40,10 @@ import net.forwardfire.unitxc.model.UnitXCType;
|
|||
*/
|
||||
public class UnitXCTypeSIPrefixBuilder<P> extends AbstractUnitXCTypeBuilder<P,UnitXCTypeSIPrefixBuilder<P>> {
|
||||
|
||||
private final UnitXCConfigBuilder builder;
|
||||
private final UnitXCGroupBuilder builder;
|
||||
private final List<UnitXCTypeSIPrefix> commonSIPrefixes;
|
||||
|
||||
public UnitXCTypeSIPrefixBuilder(P parent, UnitXCConfigBuilder builder) {
|
||||
public UnitXCTypeSIPrefixBuilder(P parent, UnitXCGroupBuilder builder) {
|
||||
super(parent,new UnitXCType(), (p,v) -> {});
|
||||
this.builder = builder;
|
||||
this.commonSIPrefixes = new ArrayList<>();
|
||||
|
@ -60,7 +61,6 @@ public class UnitXCTypeSIPrefixBuilder<P> extends AbstractUnitXCTypeBuilder<P,Un
|
|||
.setName(v.getName())
|
||||
.setNamePlural(v.getNamePlural())
|
||||
.addWebsiteLinks(v.getWebsiteLinks())
|
||||
.setTypeGroupId(v.getUnitGroupId())
|
||||
.addTypeFlags(v.getTypeFlags())
|
||||
.addFromBaseConverterSteps(v.getFromBaseConverterSteps())
|
||||
.addToBaseConverterSteps(v.getToBaseConverterSteps())
|
||||
|
@ -77,13 +77,12 @@ public class UnitXCTypeSIPrefixBuilder<P> extends AbstractUnitXCTypeBuilder<P,Un
|
|||
.setId(sim.getPrefixId()+v.getId())
|
||||
.setName(sim.getPrefixName()+v.getName())
|
||||
.setNamePlural(sim.getPrefixName()+v.getNamePlural())
|
||||
.setTypeGroupId(v.getUnitGroupId())
|
||||
.addTypeFlags(typeFlags)
|
||||
//.addWebsiteLinks(v.getWebsiteLinks())
|
||||
.addToBaseConverterStep(new UnitXCTypePowerOfTenConverterStep(sim.getExponent(),false).buildReason("Move dot for SI"))
|
||||
.addToBaseConverterStep(new UnitXCConverterStepPowerOfTen(sim.getExponent(),false,UnitXConverterStepContext.createStepValue(),UnitXConverterStepContext.createStepValue()).buildReason("Move dot for SI"))
|
||||
.addToBaseConverterSteps(v.getToBaseConverterSteps())
|
||||
.addFromBaseConverterSteps(v.getFromBaseConverterSteps())
|
||||
.addFromBaseConverterStep(new UnitXCTypePowerOfTenConverterStep(sim.getExponent(),true).buildReason("Move dot for SI"))
|
||||
.addFromBaseConverterStep(new UnitXCConverterStepPowerOfTen(sim.getExponent(),true,UnitXConverterStepContext.createStepValue(),UnitXConverterStepContext.createStepValue()).buildReason("Move dot for SI"))
|
||||
.build();
|
||||
|
||||
//for (String typeAlias:sim.getNameAliases()) {
|
||||
|
|
|
@ -26,16 +26,19 @@ package net.forwardfire.unitxc.config.builder;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.math.Fraction;
|
||||
|
||||
import net.forwardfire.unitxc.converter.step.UnitXCTypeDevideConverterStep;
|
||||
import net.forwardfire.unitxc.converter.step.UnitXCTypePowerOfTenConverterStep;
|
||||
import net.forwardfire.unitxc.converter.step.UnitXCTypeMultiplyConverterStep;
|
||||
import net.forwardfire.unitxc.converter.step.UnitXCTypeMultiplyFractionConverterStep;
|
||||
import net.forwardfire.unitxc.converter.step.UnitXCTypeOffsetConverterStep;
|
||||
import net.forwardfire.unitxc.converter.step.UnitXCTypePowerConverterStep;
|
||||
import net.forwardfire.unitxc.converter.step.UnitXConverterStep;
|
||||
import net.forwardfire.unitxc.model.step.UnitXCConverterStepOperation;
|
||||
import net.forwardfire.unitxc.model.step.UnitXCConverterStepOperationOperator;
|
||||
import net.forwardfire.unitxc.model.step.UnitXCConverterStepPowerOfTen;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStep;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReferenceDouble;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReferenceDoubleFraction;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -43,11 +46,13 @@ import net.forwardfire.unitxc.converter.step.UnitXConverterStep;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 23, 2015
|
||||
*/
|
||||
public class UnitXConverterStepBuilder<P extends AbstractUnitXCTypeBuilder<?,?>> extends AbstractUnitXCBuilder<P,List<UnitXConverterStep>,UnitXConverterStepBuilder<P>> {
|
||||
public class UnitXConverterStepBuilder<P extends AbstractUnitXCBuilder<?,?,?>> extends AbstractUnitXCBuilder<P,List<UnitXConverterStep>,UnitXConverterStepBuilder<P>> {
|
||||
|
||||
public UnitXConverterStepBuilder(P parent, BiConsumer<P, List<UnitXConverterStep>> parentBuilder) {
|
||||
private final Supplier<String> stepReason;
|
||||
|
||||
public UnitXConverterStepBuilder(P parent, BiConsumer<P, List<UnitXConverterStep>> parentBuilder, Supplier<String> stepReason) {
|
||||
super(parent, new ArrayList<>(), parentBuilder);
|
||||
this.getParent().getValue().getId();
|
||||
this.stepReason = Validate.notNull(stepReason);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,17 +61,19 @@ public class UnitXConverterStepBuilder<P extends AbstractUnitXCTypeBuilder<?,?>>
|
|||
}
|
||||
|
||||
private String createStepReason() {
|
||||
return "convert "+getParent().getValue().getId();
|
||||
return stepReason.get();
|
||||
//return "convert "+getParent().getValue().getId();
|
||||
}
|
||||
|
||||
private UnitXConverterStepBuilder<P> offset(double offset,boolean offsetPositive,String stepReason) {
|
||||
return make(v -> v.add(new UnitXCTypeOffsetConverterStep(offset,offsetPositive).buildReason(stepReason)));
|
||||
private UnitXCConverterStepOperation createStepOperation(UnitXCConverterStepOperationOperator op,UnitXConverterStepValueRead opB) {
|
||||
return new UnitXCConverterStepOperation(op,UnitXConverterStepContext.createStepValue(),opB,UnitXConverterStepContext.createStepValue());
|
||||
}
|
||||
|
||||
public UnitXConverterStepBuilder<P> offsetUp(double offset,String stepReason) {
|
||||
return offset(offset,true,stepReason);
|
||||
return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.ADD,new UnitXConverterStepValueReferenceDouble(offset))));
|
||||
}
|
||||
public UnitXConverterStepBuilder<P> offsetDown(double offset,String stepReason) {
|
||||
return offset(offset,false,stepReason);
|
||||
return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.SUBTRACT,new UnitXConverterStepValueReferenceDouble(offset))));
|
||||
}
|
||||
public UnitXConverterStepBuilder<P> offsetUp(double offset) {
|
||||
return offsetUp(offset,createStepReason());
|
||||
|
@ -77,10 +84,10 @@ public class UnitXConverterStepBuilder<P extends AbstractUnitXCTypeBuilder<?,?>>
|
|||
|
||||
|
||||
public UnitXConverterStepBuilder<P> multiply(Fraction fraction,String stepReason) {
|
||||
return make(v -> v.add(new UnitXCTypeMultiplyFractionConverterStep(fraction.getNumerator(),fraction.getDenominator()).buildReason(stepReason)));
|
||||
return multiply(fraction.getNumerator(),fraction.getDenominator(),stepReason);
|
||||
}
|
||||
public UnitXConverterStepBuilder<P> multiply(int numerator,int denominator,String stepReason) {
|
||||
return make(v -> v.add(new UnitXCTypeMultiplyFractionConverterStep(numerator,denominator).buildReason(stepReason)));
|
||||
return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.MULTIPLY,new UnitXConverterStepValueReferenceDoubleFraction(numerator,denominator))));
|
||||
}
|
||||
public UnitXConverterStepBuilder<P> multiply(Fraction fraction) {
|
||||
return multiply(fraction,createStepReason());
|
||||
|
@ -89,29 +96,41 @@ public class UnitXConverterStepBuilder<P extends AbstractUnitXCTypeBuilder<?,?>>
|
|||
return multiply(numerator,denominator,createStepReason());
|
||||
}
|
||||
|
||||
public UnitXConverterStepBuilder<P> multiply(UnitXConverterStepValueRead factor,String stepReason) {
|
||||
return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.MULTIPLY,factor)));
|
||||
}
|
||||
public UnitXConverterStepBuilder<P> multiply(double factor,String stepReason) {
|
||||
return make(v -> v.add(new UnitXCTypeMultiplyConverterStep(factor).buildReason(stepReason)));
|
||||
return multiply(new UnitXConverterStepValueReferenceDouble(factor),stepReason);
|
||||
}
|
||||
public UnitXConverterStepBuilder<P> divide(UnitXConverterStepValueRead factor,String stepReason) {
|
||||
return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.DIVIDE,factor)));
|
||||
}
|
||||
public UnitXConverterStepBuilder<P> divide(double factor,String stepReason) {
|
||||
return make(v -> v.add(new UnitXCTypeDevideConverterStep(factor).buildReason(stepReason)));
|
||||
return divide(new UnitXConverterStepValueReferenceDouble(factor),stepReason);
|
||||
}
|
||||
public UnitXConverterStepBuilder<P> multiply(double factor) {
|
||||
return multiply(factor,createStepReason());
|
||||
}
|
||||
public UnitXConverterStepBuilder<P> divide(double factor) {
|
||||
public UnitXConverterStepBuilder<P> multiply(UnitXConverterStepValueRead factor) {
|
||||
return multiply(factor,createStepReason());
|
||||
}
|
||||
public UnitXConverterStepBuilder<P> divide(UnitXConverterStepValueRead factor) {
|
||||
return divide(factor,createStepReason());
|
||||
}
|
||||
public UnitXConverterStepBuilder<P> divide(double factor) {
|
||||
return divide(factor,createStepReason());
|
||||
}
|
||||
|
||||
public UnitXConverterStepBuilder<P> power(int exponent,String stepReason) {
|
||||
return make(v -> v.add(new UnitXCTypePowerConverterStep(exponent).buildReason(stepReason)));
|
||||
public UnitXConverterStepBuilder<P> power(double exponent,String stepReason) {
|
||||
return make(v -> v.add(createStepOperation(UnitXCConverterStepOperationOperator.POWER,new UnitXConverterStepValueReferenceDouble(exponent))));
|
||||
}
|
||||
public UnitXConverterStepBuilder<P> power(int exponent) {
|
||||
public UnitXConverterStepBuilder<P> power(double exponent) {
|
||||
return power(exponent,createStepReason());
|
||||
}
|
||||
|
||||
|
||||
private UnitXConverterStepBuilder<P> powerOfTen(int exponent,boolean rev,String stepReason) {
|
||||
return make(v -> v.add(new UnitXCTypePowerOfTenConverterStep(exponent,rev).buildReason(stepReason)));
|
||||
return make(v -> v.add(new UnitXCConverterStepPowerOfTen(exponent,rev,UnitXConverterStepContext.createStepValue(),UnitXConverterStepContext.createStepValue()).buildReason(stepReason)));
|
||||
}
|
||||
public UnitXConverterStepBuilder<P> power10Up(UnitXCTypeSIPrefix exponent,String stepReason) {
|
||||
return powerOfTen(exponent.getExponent(), true,stepReason);
|
||||
|
|
|
@ -23,6 +23,13 @@
|
|||
|
||||
package net.forwardfire.unitxc.converter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.unitxc.UnitXCManager;
|
||||
import net.forwardfire.unitxc.model.UnitXCType;
|
||||
import net.forwardfire.unitxc.model.UnitXConverterResult;
|
||||
|
||||
|
@ -32,13 +39,45 @@ import net.forwardfire.unitxc.model.UnitXConverterResult;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 8, 2015
|
||||
*/
|
||||
public interface UnitXConverter {
|
||||
public class UnitXConverter {
|
||||
|
||||
double convert(double value,String fromTypeId,String toTypeId);
|
||||
private final UnitXCManager unitManager;
|
||||
private final UnitXConverterEngine convertEngine;
|
||||
|
||||
double convert(double value,UnitXCType fromType,UnitXCType toType);
|
||||
public UnitXConverter(UnitXCManager unitManager) {
|
||||
this.unitManager = Validate.notNull(unitManager);
|
||||
this.convertEngine = new UnitXConverterEngine(unitManager);
|
||||
}
|
||||
|
||||
UnitXConverterResult convertStepped(double value,String fromTypeId,String toTypeId);
|
||||
private UnitXCType getUnitType(String id) {
|
||||
return unitManager.getUnitType(id);
|
||||
}
|
||||
|
||||
UnitXConverterResult convertStepped(double value,UnitXCType fromType,UnitXCType toType);
|
||||
public double convert(double value, String fromTypeId, String toTypeId) {
|
||||
return convert(value, getUnitType(fromTypeId), getUnitType(toTypeId));
|
||||
}
|
||||
|
||||
public double convert(double value, UnitXCType fromType, UnitXCType toType) {
|
||||
return convertStepped(value,fromType,toType).getResultValue();
|
||||
}
|
||||
|
||||
public UnitXConverterResult convertStepped(double value, String fromTypeId, String toTypeId) {
|
||||
return convertStepped(value, getUnitType(fromTypeId), getUnitType(toTypeId));
|
||||
}
|
||||
|
||||
public UnitXConverterResult convertStepped(double value, String fromTypeId, String toTypeId,Map<String, UnitXConverterParameterValue> parameters) {
|
||||
return convertStepped(value, getUnitType(fromTypeId), getUnitType(toTypeId), parameters);
|
||||
}
|
||||
|
||||
public UnitXConverterResult convertStepped(double value, UnitXCType fromType, UnitXCType toType) {
|
||||
return convertStepped(value, fromType, toType, Collections.emptyMap());
|
||||
}
|
||||
|
||||
public UnitXConverterResult convertStepped(double value, UnitXCType fromType, UnitXCType toType, Map<String,UnitXConverterParameterValue> parameters) {
|
||||
return convertStepped(BigDecimal.valueOf(value), fromType, toType, parameters);
|
||||
}
|
||||
|
||||
public UnitXConverterResult convertStepped(BigDecimal value, UnitXCType fromType, UnitXCType toType, Map<String,UnitXConverterParameterValue> parameters) {
|
||||
return convertEngine.convertStepped(value, fromType, toType, parameters);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,18 +23,30 @@
|
|||
|
||||
package net.forwardfire.unitxc.converter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.forwardfire.unitxc.UnitXCManager;
|
||||
import net.forwardfire.unitxc.converter.step.UnitXConverterStep;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroup;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupJump;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroupJumpParameter;
|
||||
import net.forwardfire.unitxc.model.UnitXCType;
|
||||
import net.forwardfire.unitxc.model.UnitXConverterResult;
|
||||
import net.forwardfire.unitxc.model.UnitXConverterResultStep;
|
||||
import net.forwardfire.unitxc.model.step.UnitXCConverterStepAutoRounding;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStep;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReadWrite;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReferenceDouble;
|
||||
|
||||
/**
|
||||
* Runs requested convert steps and builds result models.
|
||||
|
@ -46,100 +58,149 @@ public final class UnitXConverterEngine {
|
|||
|
||||
private final static Logger LOG = LoggerFactory.getLogger(UnitXConverterEngine.class);
|
||||
private final UnitXCManager manager;
|
||||
private final UnitXConverterStep roundingStep;
|
||||
|
||||
public UnitXConverterEngine(UnitXCManager manager) {
|
||||
this.manager = manager;
|
||||
this.roundingStep = new UnitXCConverterStepAutoRounding(UnitXConverterStepContext.createStepValue(),UnitXConverterStepContext.createStepValue());
|
||||
}
|
||||
|
||||
public UnitXConverterResult convertStepped(double value,UnitXCType fromType,UnitXCType toType) {
|
||||
public UnitXConverterResult convertStepped(BigDecimal valueConvert2,UnitXCType fromType,UnitXCType toType, Map<String,UnitXConverterParameterValue> parameters) {
|
||||
double valueConvert = valueConvert2.doubleValue();
|
||||
long startTime = System.currentTimeMillis();
|
||||
double startValue = value;
|
||||
List<UnitXConverterResultStep> resultSteps = new ArrayList<>();
|
||||
MathContext mathContext = MathContext.DECIMAL128;
|
||||
UnitXConverterStepContextImpl ctx = new UnitXConverterStepContextImpl(mathContext,valueConvert);
|
||||
|
||||
UnitXCGroup fromTypeGroup = manager.getUnitGroup(fromType.getUnitGroupId());
|
||||
UnitXCGroup toTypeGroup = manager.getUnitGroup(toType.getUnitGroupId());
|
||||
UnitXCGroup fromTypeGroup = fromType.getUnitGroup();
|
||||
UnitXCGroup toTypeGroup = toType.getUnitGroup();
|
||||
UnitXCGroupJump crossGroupJump = null; // List<> after multi level search
|
||||
|
||||
if (!fromTypeGroup.getId().equals(toTypeGroup.getId())) {
|
||||
for (UnitXCGroupJump groupJump:fromTypeGroup.getGroupJumps()) { // FIXME
|
||||
if (toTypeGroup.getId().equals(groupJump.getUnitGroupId())) {
|
||||
crossGroupJump = groupJump;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (crossGroupJump == null) {
|
||||
throw new IllegalArgumentException("from and to groups are not equals: "+fromTypeGroup.getId()+" != "+toTypeGroup.getId());
|
||||
}
|
||||
for (UnitXCGroupJumpParameter jumpPara:crossGroupJump.getJumpParameters()) {
|
||||
if (!parameters.containsKey(jumpPara.getId())) {
|
||||
throw new IllegalArgumentException("Missing required convert parameter: "+jumpPara.getId());
|
||||
}
|
||||
UnitXConverterParameterValue convPara = parameters.get(jumpPara.getId());
|
||||
if (convPara.getValueType() == null) {
|
||||
throw new IllegalArgumentException("Convert parameter has not type: "+jumpPara.getId());
|
||||
}
|
||||
if (!jumpPara.getUnitGroupId().equals(convPara.getValueType().getUnitGroup().getId())) {
|
||||
throw new IllegalArgumentException("Convert parameter is wrong group required: "+jumpPara.getUnitGroupId()+" got: "+convPara.getValueType().getUnitGroup().getId());
|
||||
}
|
||||
boolean paraToBase = convPara.getValueType().getUnitGroup().getBaseTypeId().equals(convPara.getValueType().getId());
|
||||
double paraValue = convPara.getValue();
|
||||
if (!paraToBase) {
|
||||
System.out.println("--- cont para");;
|
||||
UnitXConverterResult res = convertStepped(BigDecimal.valueOf(paraValue), convPara.getValueType(), manager.getUnitType(convPara.getValueType().getUnitGroup().getBaseTypeId()), parameters); // FIXME rm parameters ?
|
||||
paraValue = res.getResultValue();
|
||||
//ctx.resultSteps.addAll(res.getResultSteps());
|
||||
}
|
||||
ctx.namedParameter.put(jumpPara.getId(), new UnitXConverterStepValueReferenceDouble(paraValue));
|
||||
}
|
||||
}
|
||||
|
||||
boolean fromTypeBase = fromTypeGroup.getBaseTypeId().equals(fromType.getId());
|
||||
if (!fromTypeBase) {
|
||||
value = runConverter(resultSteps,fromType, value, true);
|
||||
}
|
||||
boolean toTypeBase = toTypeGroup.getBaseTypeId().equals(toType.getId());
|
||||
if (!toTypeBase) {
|
||||
value = runConverter(resultSteps, toType, value, false);
|
||||
ctx.runSteps(fromType.getToBaseConverterSteps());
|
||||
}
|
||||
|
||||
if (crossGroupJump != null) {
|
||||
ctx.runSteps(crossGroupJump.getToGroupConverterSteps());
|
||||
}
|
||||
|
||||
boolean toTypeBase = toTypeGroup.getBaseTypeId().equals(toType.getId());
|
||||
if (!toTypeBase) {
|
||||
ctx.runSteps(toType.getFromBaseConverterSteps());
|
||||
}
|
||||
|
||||
long convertTime = System.currentTimeMillis()-startTime;
|
||||
UnitXConverterResult result = new UnitXConverterResult();
|
||||
result.setStartValue(startValue);
|
||||
result.setStartValueType(fromType);
|
||||
result.setResultValue(value);
|
||||
result.setResultValueType(toType);
|
||||
// result.setStartValue(ctx.getStartValue());
|
||||
result.setStartTypeId(fromType.getId());
|
||||
result.setResultValue(ctx.getValue());
|
||||
result.setResultTypeId(toType.getId());
|
||||
result.setConvertTime(convertTime);
|
||||
result.setResultSteps(resultSteps);
|
||||
result.setResultSteps(ctx.resultSteps);
|
||||
return result;
|
||||
}
|
||||
|
||||
private double runConverter(List<UnitXConverterResultStep> resultSteps,UnitXCType type,double value,boolean toBase) {
|
||||
double valueOld = value;
|
||||
List<UnitXConverterStep> steps = toBase?type.getToBaseConverterSteps():type.getFromBaseConverterSteps();
|
||||
for (UnitXConverterStep step:steps) {
|
||||
valueOld = value;
|
||||
class UnitXConverterStepContextImpl implements UnitXConverterStepContext {
|
||||
|
||||
final MathContext mathContext;
|
||||
List<UnitXConverterResultStep> resultSteps = new ArrayList<>();
|
||||
Map<String,UnitXConverterStepValueReadWrite> namedVariables = new HashMap<>();
|
||||
Map<String,UnitXConverterStepValueRead> namedParameter = new HashMap<>();
|
||||
|
||||
public UnitXConverterStepContextImpl(MathContext mathContext, double startValue) {
|
||||
this.mathContext = Validate.notNull(mathContext);
|
||||
setNamedVariable(VALUE, new UnitXConverterStepValueReferenceDouble(startValue));
|
||||
setNamedVariable(VALUE_START, new UnitXConverterStepValueReferenceDouble(startValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNamedVariable(String name,UnitXConverterStepValueReadWrite variable) {
|
||||
namedVariables.put(Validate.notBlank(name,"name is blank"),Validate.notNull(variable,"variable is null"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXConverterStepValueReadWrite getNamedVariable(String name) {
|
||||
return Validate.notNull(namedVariables.get(Validate.notBlank(name,"name is blank")),"named variable not found: "+name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXConverterStepValueRead getNamedParameter(String name) {
|
||||
return Validate.notNull(namedParameter.get(Validate.notBlank(name,"name is blank")),"named parameter not found: "+name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runSteps(List<UnitXConverterStep> steps) {
|
||||
for (UnitXConverterStep step:steps) {
|
||||
runStep(step);
|
||||
if (roundingStep != null) {
|
||||
runStep(roundingStep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void runStep(UnitXConverterStep step) {
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
value = step.convert(value);
|
||||
double valueOld = getValue();
|
||||
step.runStep(this);
|
||||
long convertTime = System.currentTimeMillis()-startTime;
|
||||
|
||||
System.out.println("runStep: "+step+" res: "+step.getStepReasons());
|
||||
|
||||
UnitXConverterResultStep resultStep = new UnitXConverterResultStep();
|
||||
resultStep.setName(step.getName()+(toBase?"-toBase":"-fromBase")+" = "+step.getMathExpression());
|
||||
resultStep.setStartValue(valueOld);
|
||||
resultStep.setResultValue(value);
|
||||
resultStep.setResultValue(getValue());
|
||||
resultStep.setConvertTime(convertTime);
|
||||
resultStep.setConvertStep(step);
|
||||
resultSteps.add(resultStep);
|
||||
|
||||
value = runRounding(resultSteps,value,valueOld);
|
||||
|
||||
// previousValue = valueOld;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
// TODO: redo this
|
||||
private double runRounding(List<UnitXConverterResultStep> resultSteps,double value,double valueOrg) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
String valueStr = Double.toString(value);
|
||||
String valueOrgStr = Double.toString(valueOrg);
|
||||
int valueDotIndex = valueStr.indexOf(".");
|
||||
int valueOrgDotIndex = valueOrgStr.indexOf(".");
|
||||
int valueDotSize = valueStr.length() - valueDotIndex;
|
||||
int valueOrgDotSize = valueOrgStr.length() - valueOrgDotIndex;
|
||||
|
||||
if (valueDotSize<10) {
|
||||
return value;
|
||||
private Double getValue() {
|
||||
return (Double)(getNamedVariable(VALUE).valueRead(this));
|
||||
}
|
||||
if (valueDotSize<=valueOrgDotSize) {
|
||||
return value;
|
||||
|
||||
@Override
|
||||
public MathContext getMathContext() {
|
||||
return mathContext;
|
||||
}
|
||||
int valueEIndex = valueStr.indexOf("E");
|
||||
String valueShortStr = null;
|
||||
if (valueEIndex>0) {
|
||||
int sub = valueOrgStr.length();
|
||||
if (sub > valueEIndex) {
|
||||
sub = valueEIndex;
|
||||
}
|
||||
valueShortStr = valueStr.substring(0, sub)+ valueStr.substring(valueEIndex);
|
||||
} else {
|
||||
valueShortStr = valueStr.substring(0, valueOrgStr.length());
|
||||
|
||||
@Override
|
||||
public UnitXCManager getUnitManager() {
|
||||
return manager;
|
||||
}
|
||||
Double result = new Double(valueShortStr);
|
||||
long roundTime = System.currentTimeMillis()-startTime;
|
||||
|
||||
UnitXConverterResultStep resultStep = new UnitXConverterResultStep();
|
||||
resultStep.setName("rounding");
|
||||
resultStep.setStartValue(value);
|
||||
resultStep.setResultValue(result);
|
||||
resultStep.setConvertTime(roundTime);
|
||||
|
||||
resultSteps.add(resultStep);
|
||||
|
||||
return result.doubleValue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.converter;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.unitxc.model.UnitXCType;
|
||||
|
||||
/**
|
||||
* Holds the parameter value and type.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 18, 2016
|
||||
*/
|
||||
public final class UnitXConverterParameterValue {
|
||||
|
||||
private double value;
|
||||
private UnitXCType valueType;
|
||||
|
||||
public UnitXConverterParameterValue() {
|
||||
}
|
||||
|
||||
public UnitXConverterParameterValue(double value,UnitXCType valueType) {
|
||||
setValue(value);
|
||||
setValueType(Validate.notNull(valueType));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
public double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value the value to set
|
||||
*/
|
||||
public void setValue(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the valueType
|
||||
*/
|
||||
public UnitXCType getValueType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param valueType the valueType to set
|
||||
*/
|
||||
public void setValueType(UnitXCType valueType) {
|
||||
this.valueType = valueType;
|
||||
}
|
||||
}
|
|
@ -28,11 +28,9 @@ package net.forwardfire.unitxc.model;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 16, 2015
|
||||
*/
|
||||
public class ModelXMLInfoSet {
|
||||
public class ModelJAXBInfoSet {
|
||||
|
||||
protected static final String XML_ENCODING = "UTF-8";
|
||||
|
||||
protected ModelXMLInfoSet() {
|
||||
protected ModelJAXBInfoSet() {
|
||||
}
|
||||
|
||||
protected static class Meta {
|
||||
|
@ -42,19 +40,36 @@ public class ModelXMLInfoSet {
|
|||
}
|
||||
|
||||
public static class Element {
|
||||
protected static final String UNIT_CONFIG = "unitConfig";
|
||||
protected static final String UNIT_GROUP = "unitGroup";
|
||||
protected static final String UNIT_TYPE = "unitType";
|
||||
protected static final String DESCRIPTION = "description";
|
||||
protected static final String CONVERTER_RESULT = "converterResult";
|
||||
protected static final String CONVERTER_RESULT_STEP = "converterResultStep";
|
||||
protected static final String START_VALUE_TYPE = "startValueType";
|
||||
protected static final String RESULT_VALUE_TYPE = "resultValueType";
|
||||
protected static final String DERIVED_FROM = "derivedFrom";
|
||||
protected static final String TYPE_FLAG = "typeFlag";
|
||||
protected static final String TYPE_FLAGS = "typeFlags";
|
||||
protected static final String WEBSITE_LINK = "websiteLink";
|
||||
protected static final String WEBSITE_LINKS = "websiteLinks";
|
||||
protected static final String GROUP_JUMP = "groupJump";
|
||||
protected static final String GROUP_JUMP_PARAMETER = "groupJumpParameter";
|
||||
public static final String STEP_REASON = "stepReason";
|
||||
public static final String STEP_REASONS = "stepReasons";
|
||||
|
||||
public static final String OPERATION = "operation";
|
||||
public static final String CONDITION = "condition";
|
||||
public static final String REFERENCE = "reference";
|
||||
public static final String POWER_10 = "power10";
|
||||
public static final String ROUNDING = "rounding";
|
||||
|
||||
public static final String NAMED_VARIABLE = "namedVariable";
|
||||
public static final String NAMED_PARAMETER = "namedParameter";
|
||||
|
||||
public static final String VALUE_DOUBLE = "valueDouble";
|
||||
public static final String VALUE_DOUBLE_FRACTION = "valueDoubleFraction";
|
||||
public static final String VALUE_INTEGER = "valueInteger";
|
||||
public static final String VALUE_STRING = "valueString";
|
||||
|
||||
protected Element() {
|
||||
}
|
||||
}
|
||||
|
@ -63,17 +78,20 @@ public class ModelXMLInfoSet {
|
|||
protected static final String ID = "id";
|
||||
public static final String NAME = "name";
|
||||
protected static final String NAME_PLURAL = "namePlural";
|
||||
protected static final String UNIT_GROUP_ID = "unitGroupId";
|
||||
|
||||
protected static final String START_VALUE = "startValue";
|
||||
protected static final String RESULT_VALUE = "resultValue";
|
||||
protected static final String CONVERT_TIME = "convertTime";
|
||||
protected static final String START_TYPE_ID = "startTypeId";
|
||||
protected static final String RESULT_TYPE_ID = "resultTypeId";
|
||||
|
||||
protected static final String BASE_TYPE_ID = "baseTypeId";
|
||||
protected static final String GROUP_LEVEL = "groupLevel";
|
||||
|
||||
protected static final String ALIAS_OF_TYPE = "aliasOfType";
|
||||
protected static final String UNIT_GROUP_ID = "unitGroupId";
|
||||
|
||||
protected static final String ROUNDING = "rounding";
|
||||
|
||||
protected Attribute() {
|
||||
}
|
||||
|
|
|
@ -22,22 +22,24 @@
|
|||
*/
|
||||
package net.forwardfire.unitxc.model;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import net.forwardfire.unitxc.converter.step.UnitXCTypeDevideConverterStep;
|
||||
import net.forwardfire.unitxc.converter.step.UnitXCTypeMultiplyConverterStep;
|
||||
import net.forwardfire.unitxc.converter.step.UnitXCTypeMultiplyFractionConverterStep;
|
||||
import net.forwardfire.unitxc.converter.step.UnitXCTypeOffsetConverterStep;
|
||||
import net.forwardfire.unitxc.converter.step.UnitXCTypePowerConverterStep;
|
||||
import net.forwardfire.unitxc.converter.step.UnitXCTypePowerOfTenConverterStep;
|
||||
import net.forwardfire.unitxc.model.step.UnitXCConverterStepAutoRounding;
|
||||
import net.forwardfire.unitxc.model.step.UnitXCConverterStepCondition;
|
||||
import net.forwardfire.unitxc.model.step.UnitXCConverterStepOperation;
|
||||
import net.forwardfire.unitxc.model.step.UnitXCConverterStepPowerOfTen;
|
||||
import net.forwardfire.unitxc.model.step.UnitXCConverterStepReference;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueNamedParameter;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueNamedVariable;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReferenceDouble;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReferenceDoubleFraction;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReferenceInteger;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReferenceString;
|
||||
|
||||
/**
|
||||
* Jaxb marshaller of the query sets.
|
||||
|
@ -45,59 +47,71 @@ import net.forwardfire.unitxc.converter.step.UnitXCTypePowerOfTenConverterStep;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2015
|
||||
*/
|
||||
public class ModelXMLMarshaller {
|
||||
public class ModelJAXBMarshaller {
|
||||
|
||||
private final JAXBContext jaxbContext;
|
||||
private final ModelJAXBTypedMarshaller<UnitXCConfig> configModelMarshaller;
|
||||
private final ModelJAXBTypedMarshaller<UnitXCGroup> groupModelMarshaller;
|
||||
private final ModelJAXBTypedMarshaller<UnitXCType> typeModelMarshaller;
|
||||
private final ModelJAXBTypedMarshaller<UnitXConverterResult> resultModelMarshaller;
|
||||
|
||||
/**
|
||||
* Creates a query set xml marshaller.
|
||||
* @throws JAXBException When context could not be build.
|
||||
*/
|
||||
public ModelXMLMarshaller() throws JAXBException {
|
||||
this(JAXBContext.newInstance(UnitXConverterResult.class,
|
||||
UnitXCTypeDevideConverterStep.class,
|
||||
UnitXCTypeMultiplyConverterStep.class,
|
||||
UnitXCTypeMultiplyFractionConverterStep.class,
|
||||
UnitXCTypeOffsetConverterStep.class,
|
||||
UnitXCTypePowerConverterStep.class,
|
||||
UnitXCTypePowerOfTenConverterStep.class
|
||||
));
|
||||
}
|
||||
private final static Class<?>[] JAXB_TYPES = new Class<?>[] {
|
||||
UnitXCConfig.class,
|
||||
UnitXCGroup.class,
|
||||
UnitXConverterResult.class,
|
||||
UnitXCConverterStepReference.class,
|
||||
UnitXCConverterStepOperation.class,
|
||||
UnitXCConverterStepCondition.class,
|
||||
UnitXCConverterStepPowerOfTen.class,
|
||||
UnitXCConverterStepAutoRounding.class,
|
||||
UnitXConverterStepValueNamedParameter.class,
|
||||
UnitXConverterStepValueNamedVariable.class,
|
||||
UnitXConverterStepValueReferenceDouble.class,
|
||||
UnitXConverterStepValueReferenceDoubleFraction.class,
|
||||
UnitXConverterStepValueReferenceInteger.class,
|
||||
UnitXConverterStepValueReferenceString.class,
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a query set xml marshaller.
|
||||
* @param querySetContext The jaxb query set context.
|
||||
*/
|
||||
public ModelXMLMarshaller(JAXBContext querySetContext) {
|
||||
this.jaxbContext = Validate.notNull(querySetContext,"querySetContext is null.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Marshal the UnitXConverterResult to xml.
|
||||
* @param querySet The UnitXConverterResult to marshal.
|
||||
* @param output The xml output of the query set.
|
||||
* @throws JAXBException When error.
|
||||
*/
|
||||
public void marshal(UnitXConverterResult converterResult, OutputStream output) throws JAXBException {
|
||||
Validate.notNull(converterResult,"converterResult is null.");
|
||||
Validate.notNull(output,"OutputStream is null.");
|
||||
|
||||
Marshaller marshaller = jaxbContext.createMarshaller();
|
||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
||||
marshaller.setProperty(Marshaller.JAXB_ENCODING, ModelXMLInfoSet.XML_ENCODING);
|
||||
marshaller.marshal(converterResult, output);
|
||||
public ModelJAXBMarshaller() throws JAXBException {
|
||||
this(new Class<?>[]{});
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmarshals xml to UnitXConverterResult objects.
|
||||
* @param input The xml input stream.
|
||||
* @return The UnitXConverterResult.
|
||||
* @throws JAXBException When error.
|
||||
*/
|
||||
public UnitXConverterResult unmarshal(InputStream input) throws JAXBException {
|
||||
Validate.notNull(input,"InputStream is null.");
|
||||
|
||||
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
||||
return (UnitXConverterResult) unmarshaller.unmarshal(input);
|
||||
public ModelJAXBMarshaller(Class<?>[] extraTypes) throws JAXBException {
|
||||
this(JAXBContext.newInstance(ArrayUtils.addAll(getJAXBTypes(), extraTypes)));
|
||||
}
|
||||
|
||||
public ModelJAXBMarshaller(JAXBContext jaxbContext) throws JAXBException {
|
||||
this(XMLInputFactory.newInstance(),XMLOutputFactory.newInstance(),jaxbContext);
|
||||
}
|
||||
|
||||
public ModelJAXBMarshaller(XMLInputFactory xmlInputFactory,XMLOutputFactory xmlOutputFactory, JAXBContext jaxbContext) {
|
||||
this.configModelMarshaller = buildTypedMarshaller(UnitXCConfig.class, xmlInputFactory, xmlOutputFactory, jaxbContext);
|
||||
this.groupModelMarshaller = buildTypedMarshaller(UnitXCGroup.class, xmlInputFactory, xmlOutputFactory, jaxbContext);
|
||||
this.typeModelMarshaller = buildTypedMarshaller(UnitXCType.class, xmlInputFactory, xmlOutputFactory, jaxbContext);
|
||||
this.resultModelMarshaller = buildTypedMarshaller(UnitXConverterResult.class, xmlInputFactory, xmlOutputFactory, jaxbContext);
|
||||
}
|
||||
|
||||
public static Class<?>[] getJAXBTypes() {
|
||||
return JAXB_TYPES;
|
||||
}
|
||||
|
||||
public ModelJAXBTypedMarshaller<UnitXCConfig> getUnitXCConfig() {
|
||||
return configModelMarshaller;
|
||||
}
|
||||
|
||||
public ModelJAXBTypedMarshaller<UnitXCGroup> getUnitXCGroup() {
|
||||
return groupModelMarshaller;
|
||||
}
|
||||
|
||||
public ModelJAXBTypedMarshaller<UnitXCType> getUnitXCType() {
|
||||
return typeModelMarshaller;
|
||||
}
|
||||
|
||||
public ModelJAXBTypedMarshaller<UnitXConverterResult> getUnitXConverterResult() {
|
||||
return resultModelMarshaller;
|
||||
}
|
||||
|
||||
private static <T> ModelJAXBTypedMarshaller<T> buildTypedMarshaller(Class<T> typeClass,XMLInputFactory xmlInputFactory,XMLOutputFactory xmlOutputFactory, JAXBContext jaxbContext) {
|
||||
return new ModelJAXBTypedMarshaller<T>(typeClass,xmlInputFactory,xmlOutputFactory,jaxbContext);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 javax.xml.bind.annotation.XmlAnyElement;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 3, 2016
|
||||
*/
|
||||
public class ModelJAXBObjectWrap<T> {
|
||||
|
||||
private T value;
|
||||
|
||||
public ModelJAXBObjectWrap() {
|
||||
}
|
||||
|
||||
public ModelJAXBObjectWrap(T value) {
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
@XmlAnyElement
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value the value to set
|
||||
*/
|
||||
public void setValue(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -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 javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||
|
||||
/**
|
||||
* Adds extra wrap tag to any object.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 3, 2016
|
||||
*/
|
||||
public class ModelJAXBObjectWrapAdapter extends XmlAdapter<ModelJAXBObjectWrap<?>, Object> {
|
||||
|
||||
@Override
|
||||
public Object unmarshal(ModelJAXBObjectWrap<?> v) throws Exception {
|
||||
return v.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelJAXBObjectWrap<?> marshal(Object v) throws Exception {
|
||||
return new ModelJAXBObjectWrap<Object>(v);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
package net.forwardfire.unitxc.model;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
public class ModelJAXBTypedMarshaller<T> {
|
||||
|
||||
private final Class<T> typeClass;
|
||||
private final XMLInputFactory xmlInputFactory;
|
||||
private final XMLOutputFactory xmlOutputFactory;
|
||||
private final JAXBContext jaxbContext;
|
||||
|
||||
public ModelJAXBTypedMarshaller(Class<T> typeClass, XMLInputFactory xmlInputFactory,
|
||||
XMLOutputFactory xmlOutputFactory, JAXBContext jaxbContext) {
|
||||
this.typeClass = Validate.notNull(typeClass);
|
||||
this.xmlInputFactory = Validate.notNull(xmlInputFactory);
|
||||
this.xmlOutputFactory = Validate.notNull(xmlOutputFactory);
|
||||
this.jaxbContext = Validate.notNull(jaxbContext);
|
||||
}
|
||||
|
||||
protected Unmarshaller createUnmarshaller() throws JAXBException {
|
||||
return jaxbContext.createUnmarshaller();
|
||||
}
|
||||
|
||||
protected Marshaller createMarshaller(String encoding) throws JAXBException {
|
||||
Validate.notNull(encoding, "encoding is null.");
|
||||
Marshaller marshaller = jaxbContext.createMarshaller();
|
||||
//marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // done by stax proxy now
|
||||
marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);
|
||||
return marshaller;
|
||||
}
|
||||
|
||||
public void marshal(T jaxbElement, XMLStreamWriter writer) throws JAXBException {
|
||||
marshal(jaxbElement, writer, StandardCharsets.UTF_8.name());
|
||||
}
|
||||
|
||||
public void marshal(T jaxbElement, XMLStreamWriter writer, String encoding) throws JAXBException {
|
||||
Validate.notNull(jaxbElement, "jaxbElement is null.");
|
||||
Validate.notNull(writer, "reader is null.");
|
||||
Validate.notNull(encoding, "encoding is null.");
|
||||
createMarshaller(encoding).marshal(jaxbElement, writer);
|
||||
}
|
||||
|
||||
public void marshal(T jaxbElement, OutputStream output) throws JAXBException, XMLStreamException {
|
||||
marshal(jaxbElement, output, StandardCharsets.UTF_8.name());
|
||||
}
|
||||
|
||||
public void marshal(T jaxbElement, OutputStream output, String encoding) throws JAXBException, XMLStreamException {
|
||||
Validate.notNull(jaxbElement, "jaxbElement is null.");
|
||||
Validate.notNull(output, "ouput is null.");
|
||||
Validate.notNull(encoding, "encoding is null.");
|
||||
marshal(jaxbElement, IndentingXMLStreamWriterProxy.wrap(xmlOutputFactory.createXMLStreamWriter(output, encoding)), encoding);
|
||||
}
|
||||
|
||||
public T unmarshal(XMLStreamReader reader) throws JAXBException {
|
||||
Validate.notNull(reader, "reader is null.");
|
||||
return createUnmarshaller().unmarshal(reader, typeClass).getValue();
|
||||
}
|
||||
|
||||
public T unmarshal(InputStream input, String encoding) throws JAXBException, XMLStreamException {
|
||||
Validate.notNull(input, "input is null.");
|
||||
Validate.notNull(encoding, "encoding is null.");
|
||||
return unmarshal(xmlInputFactory.createXMLStreamReader(input, encoding));
|
||||
}
|
||||
|
||||
public T unmarshal(InputStream input) throws JAXBException, XMLStreamException {
|
||||
return unmarshal(input, StandardCharsets.UTF_8.name());
|
||||
}
|
||||
|
||||
static class IndentingXMLStreamWriterProxy implements InvocationHandler {
|
||||
|
||||
private final XMLStreamWriter target;
|
||||
private int depth = 0;
|
||||
private boolean firstLine = true;
|
||||
private final Map<Integer, Boolean> hasChildElement = new HashMap<>();
|
||||
|
||||
public IndentingXMLStreamWriterProxy(XMLStreamWriter target) {
|
||||
this.target = Validate.notNull(target);
|
||||
}
|
||||
|
||||
public static XMLStreamWriter wrap(XMLStreamWriter writer) {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
if (cl == null) {
|
||||
IndentingXMLStreamWriterProxy.class.getClassLoader();
|
||||
}
|
||||
return (XMLStreamWriter) Proxy.newProxyInstance(cl, new Class<?>[]{XMLStreamWriter.class}, new IndentingXMLStreamWriterProxy(writer));
|
||||
}
|
||||
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
String m = method.getName();
|
||||
// Needs to be BEFORE the actual event, so that for instance the
|
||||
// sequence writeStartElem, writeAttr, writeStartElem, writeEndElem,writeEndElem
|
||||
// is correctly handled
|
||||
if ("writeStartElement".equals(m)) {
|
||||
// update state of parent node
|
||||
if (depth > 0) {
|
||||
hasChildElement.put(depth - 1, true);
|
||||
}
|
||||
// reset state of current node
|
||||
hasChildElement.put(depth, false);
|
||||
// indent for current depth
|
||||
if (!firstLine) {
|
||||
writeLineWrap();
|
||||
}
|
||||
depth++;
|
||||
} else if ("writeEndElement".equals(m)) {
|
||||
depth--;
|
||||
if (hasChildElement.get(depth) == true) {
|
||||
writeLineWrap();
|
||||
}
|
||||
} else if ("writeEmptyElement".equals(m)) {
|
||||
// update state of parent node
|
||||
if (depth > 0) {
|
||||
hasChildElement.put(depth - 1, true);
|
||||
}
|
||||
writeLineWrap();
|
||||
} else if ("writeComment".equals(m)) {
|
||||
writeLineWrap();
|
||||
} else if ("writeEndDocument".equals(m)) {
|
||||
target.writeCharacters(StringUtils.LF);
|
||||
}
|
||||
method.invoke(target, args);
|
||||
firstLine = false;
|
||||
return null;
|
||||
}
|
||||
|
||||
private void writeLineWrap() throws XMLStreamException {
|
||||
target.writeCharacters(StringUtils.LF);
|
||||
// indent for current depth
|
||||
target.writeCharacters(StringUtils.repeat(StringUtils.SPACE, depth));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* The unit config.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 17, 2015
|
||||
*/
|
||||
@XmlRootElement(name=ModelJAXBInfoSet.Element.UNIT_CONFIG)
|
||||
public class UnitXCConfig {
|
||||
|
||||
private UnitXCRounding rounding;
|
||||
private final List<UnitXCGroup> unitGroups;
|
||||
|
||||
public UnitXCConfig() {
|
||||
unitGroups = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the rounding
|
||||
*/
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.ROUNDING)
|
||||
public UnitXCRounding getRounding() {
|
||||
return rounding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rounding the rounding to set
|
||||
*/
|
||||
public void setRounding(UnitXCRounding rounding) {
|
||||
this.rounding = rounding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the unit groups.
|
||||
*/
|
||||
@XmlElement(name=ModelJAXBInfoSet.Element.UNIT_GROUP)
|
||||
public List<UnitXCGroup> getUnitGroups() {
|
||||
return unitGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unitGroups the groups to set.
|
||||
*/
|
||||
public void setUnitGroups(List<UnitXCGroup> groups) {
|
||||
this.unitGroups.clear();
|
||||
groups.forEach(group -> addUnitGroup(group));
|
||||
}
|
||||
|
||||
public void addUnitGroup(UnitXCGroup group) {
|
||||
Validate.notNull(group);
|
||||
group.validate();
|
||||
unitGroups.add(group);
|
||||
}
|
||||
}
|
|
@ -28,8 +28,12 @@ import java.util.List;
|
|||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||
|
||||
/**
|
||||
* The unit group.
|
||||
|
@ -37,17 +41,24 @@ import org.apache.commons.lang3.Validate;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 10, 2015
|
||||
*/
|
||||
@XmlRootElement(name=ModelJAXBInfoSet.Element.UNIT_GROUP)
|
||||
public class UnitXCGroup {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String baseTypeId;
|
||||
private long totalUnitTypes = 0L;
|
||||
private UnitXCGroupLevel groupLevel;
|
||||
private UnitXCTypeGenerator typeGenerator;
|
||||
private final List<String> derivedFrom;
|
||||
private final List<UnitXCType> unitTypes;
|
||||
private final List<UnitXCGroupJump> groupJumps;
|
||||
|
||||
public UnitXCGroup() {
|
||||
derivedFrom = new ArrayList<>();
|
||||
unitTypes = new ArrayList<>();
|
||||
groupJumps = new ArrayList<>();
|
||||
}
|
||||
|
||||
public UnitXCGroup(String id,String name,String description,String baseTypeId) {
|
||||
|
@ -70,7 +81,7 @@ public class UnitXCGroup {
|
|||
/**
|
||||
* @return the id
|
||||
*/
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.ID)
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.ID)
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -84,7 +95,7 @@ public class UnitXCGroup {
|
|||
/**
|
||||
* @return the name
|
||||
*/
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.NAME)
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.NAME)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -99,7 +110,7 @@ public class UnitXCGroup {
|
|||
/**
|
||||
* @return the description
|
||||
*/
|
||||
@XmlElement(name=ModelXMLInfoSet.Element.DESCRIPTION)
|
||||
@XmlElement(name=ModelJAXBInfoSet.Element.DESCRIPTION)
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
@ -114,7 +125,7 @@ public class UnitXCGroup {
|
|||
/**
|
||||
* @return the baseTypeId
|
||||
*/
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.BASE_TYPE_ID)
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.BASE_TYPE_ID)
|
||||
public String getBaseTypeId() {
|
||||
return baseTypeId;
|
||||
}
|
||||
|
@ -129,7 +140,7 @@ public class UnitXCGroup {
|
|||
/**
|
||||
* @return the groupLevel
|
||||
*/
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.GROUP_LEVEL)
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.GROUP_LEVEL)
|
||||
public UnitXCGroupLevel getGroupLevel() {
|
||||
return groupLevel;
|
||||
}
|
||||
|
@ -144,7 +155,8 @@ public class UnitXCGroup {
|
|||
/**
|
||||
* @return the derivedFrom
|
||||
*/
|
||||
@XmlElement(name=ModelXMLInfoSet.Element.DERIVED_FROM)
|
||||
@XmlElement(name=ModelJAXBInfoSet.Element.DERIVED_FROM)
|
||||
@XmlElementWrapper
|
||||
public List<String> getDerivedFrom() {
|
||||
return derivedFrom;
|
||||
}
|
||||
|
@ -156,4 +168,79 @@ public class UnitXCGroup {
|
|||
this.derivedFrom.clear();
|
||||
this.derivedFrom.addAll(derivedFrom);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the unit types.
|
||||
*/
|
||||
@XmlElement(name=ModelJAXBInfoSet.Element.UNIT_TYPE)
|
||||
@XmlElementWrapper
|
||||
public List<UnitXCType> getUnitTypes() {
|
||||
return unitTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unitTypes the types to set.
|
||||
*/
|
||||
public void setUnitTypes(List<UnitXCType> types) {
|
||||
this.unitTypes.clear();
|
||||
types.forEach(type -> addUnitType(type));
|
||||
}
|
||||
|
||||
public void addUnitType(UnitXCType type) {
|
||||
Validate.notNull(type);
|
||||
type.setUnitGroup(this);
|
||||
type.validate();
|
||||
unitTypes.add(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the groupJumps
|
||||
*/
|
||||
@XmlElement(name=ModelJAXBInfoSet.Element.GROUP_JUMP)
|
||||
@XmlElementWrapper
|
||||
public List<UnitXCGroupJump> getGroupJumps() {
|
||||
return groupJumps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param groupJumps the groupJumps to set
|
||||
*/
|
||||
public void setGroupJumps(List<UnitXCGroupJump> groupJumps) {
|
||||
this.groupJumps.clear();
|
||||
this.groupJumps.addAll(groupJumps);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the typeGenerator
|
||||
*/
|
||||
@XmlTransient
|
||||
public UnitXCTypeGenerator getTypeGenerator() {
|
||||
return typeGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param typeGenerator the typeGenerator to set
|
||||
*/
|
||||
public void setTypeGenerator(UnitXCTypeGenerator typeGenerator) {
|
||||
this.typeGenerator = typeGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the totalUnitTypes
|
||||
*/
|
||||
public long getTotalUnitTypes() {
|
||||
return totalUnitTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param totalUnitTypes the totalUnitTypes to set
|
||||
*/
|
||||
public void setTotalUnitTypes(long totalUnitTypes) {
|
||||
this.totalUnitTypes = totalUnitTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ReflectionToStringBuilder.toString(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAnyElement;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStep;
|
||||
|
||||
/**
|
||||
* The unit group jump.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 1, 2016
|
||||
*/
|
||||
public class UnitXCGroupJump {
|
||||
|
||||
private String id;
|
||||
private String unitGroupId;
|
||||
private final List<UnitXConverterStep> toGroupConverterSteps;
|
||||
private final List<UnitXCGroupJumpParameter> jumpParameters;
|
||||
|
||||
public UnitXCGroupJump() {
|
||||
toGroupConverterSteps = new ArrayList<>();
|
||||
jumpParameters = new ArrayList<>();
|
||||
}
|
||||
|
||||
public UnitXCGroupJump validate() {
|
||||
Validate.notBlank(id,"The id is blank");
|
||||
Validate.notBlank(unitGroupId,"The unitGroupId is blank of: "+id);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.ID)
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the toGroupId
|
||||
*/
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.UNIT_GROUP_ID)
|
||||
public String getUnitGroupId() {
|
||||
return unitGroupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unitGroupId the unitGroupId to set
|
||||
*/
|
||||
public void setUnitGroupId(String unitGroupId) {
|
||||
this.unitGroupId = unitGroupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the toGroupConverterSteps
|
||||
*/
|
||||
@XmlElementWrapper
|
||||
@XmlAnyElement
|
||||
public List<UnitXConverterStep> getToGroupConverterSteps() {
|
||||
return toGroupConverterSteps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param toGroupConverterSteps the toGroupConverterSteps to set
|
||||
*/
|
||||
public void setToBaseConverterSteps(List<UnitXConverterStep> toGroupConverterSteps) {
|
||||
this.toGroupConverterSteps.clear();
|
||||
this.toGroupConverterSteps.addAll(toGroupConverterSteps);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the jumpParameters
|
||||
*/
|
||||
@XmlElementWrapper
|
||||
@XmlElement(name=ModelJAXBInfoSet.Element.GROUP_JUMP_PARAMETER)
|
||||
public List<UnitXCGroupJumpParameter> getJumpParameters() {
|
||||
return jumpParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param jumpParameters the jumpParameters to set
|
||||
*/
|
||||
public void setJumpParameters(List<UnitXCGroupJumpParameter> jumpParameters) {
|
||||
this.jumpParameters.clear();
|
||||
this.jumpParameters.addAll(jumpParameters);
|
||||
}
|
||||
|
||||
public void addJumpParameter(UnitXCGroupJumpParameter jumpParameter) {
|
||||
this.jumpParameters.add(Validate.notNull(jumpParameter));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.model;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
|
||||
/**
|
||||
* The unit group jump.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 1, 2016
|
||||
*/
|
||||
public class UnitXCGroupJumpParameter {
|
||||
|
||||
private String id;
|
||||
private String unitGroupId;
|
||||
|
||||
public UnitXCGroupJumpParameter() {
|
||||
}
|
||||
|
||||
public UnitXCGroupJumpParameter(String id,String unitGroupId) {
|
||||
setId(id);
|
||||
setUnitGroupId(unitGroupId);
|
||||
}
|
||||
|
||||
public UnitXCGroupJumpParameter validate() {
|
||||
Validate.notBlank(id,"The id is blank");
|
||||
Validate.notBlank(unitGroupId,"The unitGroup is blank of: "+id);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.ID)
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the unitGroupId
|
||||
*/
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.UNIT_GROUP_ID)
|
||||
public String getUnitGroupId() {
|
||||
return unitGroupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unitGroupId the unitGroupId to set
|
||||
*/
|
||||
public void setUnitGroupId(String unitGroupId) {
|
||||
this.unitGroupId = unitGroupId;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package net.forwardfire.unitxc.model;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 23, 2016
|
||||
*/
|
||||
public enum UnitXCRounding {
|
||||
|
||||
OFF,
|
||||
PRE_STEP;
|
||||
/* PER_CONVERT */
|
||||
}
|
|
@ -33,8 +33,9 @@ import javax.xml.bind.annotation.XmlElementWrapper;
|
|||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||
|
||||
import net.forwardfire.unitxc.converter.step.UnitXConverterStep;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStep;
|
||||
|
||||
/**
|
||||
* The unit type.
|
||||
|
@ -48,7 +49,7 @@ public class UnitXCType {
|
|||
private String name;
|
||||
private String namePlural;
|
||||
private String aliasOfType;
|
||||
private String unitGroupId;
|
||||
private UnitXCGroup unitGroup;
|
||||
private final List<UnitXConverterStep> toBaseConverterSteps;
|
||||
private final List<UnitXConverterStep> fromBaseConverterSteps;
|
||||
private final List<String> typeFlags;
|
||||
|
@ -65,14 +66,14 @@ public class UnitXCType {
|
|||
Validate.notBlank(id,"The id is blank");
|
||||
Validate.notBlank(name,"The name is blank of: "+id);
|
||||
Validate.notBlank(namePlural,"The namePlural is blank of: "+id);
|
||||
Validate.notBlank(unitGroupId,"The unitGroupId is blank of: "+id);
|
||||
Validate.notNull(unitGroup,"The unitGroup is null of: "+id);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.ID)
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.ID)
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -86,7 +87,7 @@ public class UnitXCType {
|
|||
/**
|
||||
* @return the name
|
||||
*/
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.NAME)
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.NAME)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -101,7 +102,7 @@ public class UnitXCType {
|
|||
/**
|
||||
* @return the namePlural
|
||||
*/
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.NAME_PLURAL)
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.NAME_PLURAL)
|
||||
public String getNamePlural() {
|
||||
return namePlural;
|
||||
}
|
||||
|
@ -116,7 +117,7 @@ public class UnitXCType {
|
|||
/**
|
||||
* @return the aliasOfType
|
||||
*/
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.ALIAS_OF_TYPE)
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.ALIAS_OF_TYPE)
|
||||
public String getAliasOfType() {
|
||||
return aliasOfType;
|
||||
}
|
||||
|
@ -129,18 +130,18 @@ public class UnitXCType {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the unitGroupId
|
||||
* @return the unitGroup
|
||||
*/
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.UNIT_GROUP_ID)
|
||||
public String getUnitGroupId() {
|
||||
return unitGroupId;
|
||||
@XmlTransient
|
||||
public UnitXCGroup getUnitGroup() {
|
||||
return unitGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unitGroupId the unitGroupId to set
|
||||
* @param unitGroup the unitGroup to set
|
||||
*/
|
||||
public void setUnitGroupId(String unitGroupId) {
|
||||
this.unitGroupId = unitGroupId;
|
||||
public void setUnitGroup(UnitXCGroup unitGroup) {
|
||||
this.unitGroup = unitGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,8 +181,8 @@ public class UnitXCType {
|
|||
/**
|
||||
* @return the typeFlags
|
||||
*/
|
||||
@XmlElement(name=ModelXMLInfoSet.Element.TYPE_FLAG)
|
||||
@XmlElementWrapper(name=ModelXMLInfoSet.Element.TYPE_FLAGS)
|
||||
@XmlElement(name=ModelJAXBInfoSet.Element.TYPE_FLAG)
|
||||
@XmlElementWrapper(name=ModelJAXBInfoSet.Element.TYPE_FLAGS)
|
||||
public List<String> getTypeFlags() {
|
||||
return typeFlags;
|
||||
}
|
||||
|
@ -197,8 +198,8 @@ public class UnitXCType {
|
|||
/**
|
||||
* @return the websiteLinks
|
||||
*/
|
||||
@XmlElement(name=ModelXMLInfoSet.Element.WEBSITE_LINK)
|
||||
@XmlElementWrapper(name=ModelXMLInfoSet.Element.WEBSITE_LINKS)
|
||||
@XmlElement(name=ModelJAXBInfoSet.Element.WEBSITE_LINK)
|
||||
@XmlElementWrapper(name=ModelJAXBInfoSet.Element.WEBSITE_LINKS)
|
||||
public List<String> getWebsiteLinks() {
|
||||
return websiteLinks;
|
||||
}
|
||||
|
@ -210,4 +211,9 @@ public class UnitXCType {
|
|||
this.websiteLinks.clear();
|
||||
this.websiteLinks.addAll(websiteLinks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ReflectionToStringBuilder.toString(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package net.forwardfire.unitxc.model;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public interface UnitXCTypeGenerator {
|
||||
|
||||
long size();
|
||||
|
||||
Iterator<String> getUnitTypes();
|
||||
|
||||
UnitXCType getUnitType(String id);
|
||||
}
|
|
@ -35,20 +35,20 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 17, 2015
|
||||
*/
|
||||
@XmlRootElement(name=ModelXMLInfoSet.Element.CONVERTER_RESULT)
|
||||
@XmlRootElement(name=ModelJAXBInfoSet.Element.CONVERTER_RESULT)
|
||||
public class UnitXConverterResult {
|
||||
|
||||
private Double startValue;
|
||||
private List<UnitXConverterResultStep> resultSteps;
|
||||
private Double resultValue;
|
||||
private Long convertTime;
|
||||
private UnitXCType startValueType;
|
||||
private UnitXCType resultValueType;
|
||||
private String startTypeId;
|
||||
private String resultTypeId;
|
||||
|
||||
/**
|
||||
* @return the startValue
|
||||
*/
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.START_VALUE)
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.START_VALUE)
|
||||
public Double getStartValue() {
|
||||
return startValue;
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class UnitXConverterResult {
|
|||
/**
|
||||
* @return the resultSteps
|
||||
*/
|
||||
@XmlElement(name=ModelXMLInfoSet.Element.CONVERTER_RESULT_STEP)
|
||||
@XmlElement(name=ModelJAXBInfoSet.Element.CONVERTER_RESULT_STEP)
|
||||
public List<UnitXConverterResultStep> getResultSteps() {
|
||||
return resultSteps;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public class UnitXConverterResult {
|
|||
/**
|
||||
* @return the resultValue
|
||||
*/
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.RESULT_VALUE)
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.RESULT_VALUE)
|
||||
public Double getResultValue() {
|
||||
return resultValue;
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public class UnitXConverterResult {
|
|||
/**
|
||||
* @return the convertTime
|
||||
*/
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.CONVERT_TIME)
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.CONVERT_TIME)
|
||||
public Long getConvertTime() {
|
||||
return convertTime;
|
||||
}
|
||||
|
@ -106,32 +106,32 @@ public class UnitXConverterResult {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the startValueType
|
||||
* @return the startTypeId
|
||||
*/
|
||||
@XmlElement(name=ModelXMLInfoSet.Element.START_VALUE_TYPE)
|
||||
public UnitXCType getStartValueType() {
|
||||
return startValueType;
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.START_TYPE_ID)
|
||||
public String getStartTypeId() {
|
||||
return startTypeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param startValueType the startValueType to set
|
||||
* @param startTypeId the startTypeId to set
|
||||
*/
|
||||
public void setStartValueType(UnitXCType startValueType) {
|
||||
this.startValueType = startValueType;
|
||||
public void setStartTypeId(String startTypeId) {
|
||||
this.startTypeId = startTypeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the resultValueType
|
||||
* @return the resultTypeId
|
||||
*/
|
||||
@XmlElement(name=ModelXMLInfoSet.Element.RESULT_VALUE_TYPE)
|
||||
public UnitXCType getResultValueType() {
|
||||
return resultValueType;
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.RESULT_TYPE_ID)
|
||||
public String getResultTypeId() {
|
||||
return resultTypeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resultValueType the resultValueType to set
|
||||
* @param resultTypeId the resultTypeId to set
|
||||
*/
|
||||
public void setResultValueType(UnitXCType resultValueType) {
|
||||
this.resultValueType = resultValueType;
|
||||
public void setResultTypeId(String resultTypeId) {
|
||||
this.resultTypeId = resultTypeId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,11 @@
|
|||
|
||||
package net.forwardfire.unitxc.model;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAnyElement;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStep;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
@ -33,30 +36,15 @@ import javax.xml.bind.annotation.XmlAttribute;
|
|||
*/
|
||||
public class UnitXConverterResultStep {
|
||||
|
||||
private String name;
|
||||
private Double startValue;
|
||||
private Double resultValue;
|
||||
private Long convertTime;
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.NAME)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
private UnitXConverterStep convertStep;
|
||||
|
||||
/**
|
||||
* @return the startValue
|
||||
*/
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.START_VALUE)
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.START_VALUE)
|
||||
public Double getStartValue() {
|
||||
return startValue;
|
||||
}
|
||||
|
@ -71,7 +59,7 @@ public class UnitXConverterResultStep {
|
|||
/**
|
||||
* @return the resultValue
|
||||
*/
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.RESULT_VALUE)
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.RESULT_VALUE)
|
||||
public Double getResultValue() {
|
||||
return resultValue;
|
||||
}
|
||||
|
@ -86,7 +74,7 @@ public class UnitXConverterResultStep {
|
|||
/**
|
||||
* @return the convertTime
|
||||
*/
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.CONVERT_TIME)
|
||||
@XmlAttribute(name=ModelJAXBInfoSet.Attribute.CONVERT_TIME)
|
||||
public Long getConvertTime() {
|
||||
return convertTime;
|
||||
}
|
||||
|
@ -97,4 +85,19 @@ public class UnitXConverterResultStep {
|
|||
public void setConvertTime(Long convertTime) {
|
||||
this.convertTime = convertTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the convertStep
|
||||
*/
|
||||
@XmlAnyElement
|
||||
public UnitXConverterStep getConvertStep() {
|
||||
return convertStep;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param convertStep the convertStep to set
|
||||
*/
|
||||
public void setConvertStep(UnitXConverterStep convertStep) {
|
||||
this.convertStep = convertStep;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,18 +21,17 @@
|
|||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.converter.step;
|
||||
package net.forwardfire.unitxc.model.step;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.unitxc.model.ModelXMLInfoSet;
|
||||
import net.forwardfire.unitxc.model.ModelJAXBInfoSet;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -42,12 +41,10 @@ import net.forwardfire.unitxc.model.ModelXMLInfoSet;
|
|||
*/
|
||||
public abstract class AbstractUnitXConverterStep implements UnitXConverterStep {
|
||||
|
||||
private String name;
|
||||
private final List<String> stepReasons;
|
||||
|
||||
protected AbstractUnitXConverterStep(String name) {
|
||||
protected AbstractUnitXConverterStep() {
|
||||
this.stepReasons = new ArrayList<>();
|
||||
this.setName(name);
|
||||
}
|
||||
|
||||
public AbstractUnitXConverterStep buildReason(String reason) {
|
||||
|
@ -55,19 +52,8 @@ public abstract class AbstractUnitXConverterStep implements UnitXConverterStep {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@XmlAttribute(name=ModelXMLInfoSet.Attribute.NAME)
|
||||
public final String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = Validate.notBlank(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@XmlElement(name=ModelXMLInfoSet.Element.STEP_REASON)
|
||||
@XmlElementWrapper(name=ModelXMLInfoSet.Element.STEP_REASONS)
|
||||
@XmlElement(name=ModelJAXBInfoSet.Element.STEP_REASON)
|
||||
@XmlElementWrapper(name=ModelJAXBInfoSet.Element.STEP_REASONS)
|
||||
public final List<String> getStepReasons() {
|
||||
return stepReasons;
|
||||
}
|
||||
|
@ -77,28 +63,7 @@ public abstract class AbstractUnitXConverterStep implements UnitXConverterStep {
|
|||
this.stepReasons.addAll(stepReasons);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void addStepReason(String stepReason) {
|
||||
stepReasons.add(Validate.notBlank(stepReason));
|
||||
}
|
||||
|
||||
abstract protected String toMath();
|
||||
|
||||
@Override
|
||||
public final String getMathExpression() {
|
||||
return toMath();
|
||||
}
|
||||
|
||||
public void setMathExpression(String notUsed) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXConverterStep clone() {
|
||||
AbstractUnitXConverterStep clone = createClone();
|
||||
clone.setName(getName());
|
||||
clone.setStepReasons(getStepReasons());
|
||||
return clone;
|
||||
}
|
||||
|
||||
abstract protected AbstractUnitXConverterStep createClone();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
package net.forwardfire.unitxc.model.step;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import net.forwardfire.unitxc.model.ModelJAXBInfoSet;
|
||||
import net.forwardfire.unitxc.model.ModelJAXBObjectWrapAdapter;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueNamedVariable;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReadWrite;
|
||||
|
||||
@XmlRootElement(name=ModelJAXBInfoSet.Element.ROUNDING)
|
||||
public class UnitXCConverterStepAutoRounding extends AbstractUnitXConverterStep {
|
||||
|
||||
private UnitXConverterStepValueRead operand;
|
||||
private UnitXConverterStepValueReadWrite result;
|
||||
|
||||
public UnitXCConverterStepAutoRounding() {
|
||||
}
|
||||
|
||||
public UnitXCConverterStepAutoRounding(UnitXConverterStepValueRead operand,UnitXConverterStepValueReadWrite result) {
|
||||
setOperand(operand);
|
||||
setResult(result);
|
||||
}
|
||||
|
||||
private double round(double value,double prevValue) {
|
||||
String valueStr = Double.toString(value);
|
||||
String valueOrgStr = Double.toString(prevValue);
|
||||
int valueDotIndex = valueStr.indexOf(".");
|
||||
int valueOrgDotIndex = valueOrgStr.indexOf(".");
|
||||
int valueDotSize = valueStr.length() - valueDotIndex;
|
||||
int valueOrgDotSize = valueOrgStr.length() - valueOrgDotIndex;
|
||||
|
||||
if (valueDotSize<10) {
|
||||
return value;
|
||||
}
|
||||
if (valueDotSize<=valueOrgDotSize) {
|
||||
return value;
|
||||
}
|
||||
int valueEIndex = valueStr.indexOf("E");
|
||||
String valueShortStr = null;
|
||||
if (valueEIndex>0) {
|
||||
int sub = valueOrgStr.length();
|
||||
if (sub > valueEIndex) {
|
||||
sub = valueEIndex;
|
||||
}
|
||||
valueShortStr = valueStr.substring(0, sub)+ valueStr.substring(valueEIndex);
|
||||
} else {
|
||||
valueShortStr = valueStr.substring(0, valueOrgStr.length());
|
||||
}
|
||||
Double result = new Double(valueShortStr);
|
||||
return result.doubleValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runStep(UnitXConverterStepContext ctx) {
|
||||
// FIXME: rm obj and casting
|
||||
UnitXConverterStepValueReadWrite startValue = new UnitXConverterStepValueNamedVariable(Double.class,UnitXConverterStepContext.VALUE_START);
|
||||
getResult().valueWrite(ctx, round((Double)getOperand().valueRead(ctx),(Double)startValue.valueRead(ctx)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the operand
|
||||
*/
|
||||
@XmlJavaTypeAdapter(value=ModelJAXBObjectWrapAdapter.class)
|
||||
public UnitXConverterStepValueRead getOperand() {
|
||||
return operand;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param operand the operand to set
|
||||
*/
|
||||
public void setOperand(UnitXConverterStepValueRead operand) {
|
||||
this.operand = operand;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the result
|
||||
*/
|
||||
@XmlJavaTypeAdapter(value=ModelJAXBObjectWrapAdapter.class)
|
||||
public UnitXConverterStepValueReadWrite getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param result the result to set
|
||||
*/
|
||||
public void setResult(UnitXConverterStepValueReadWrite result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* 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.step;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAnyElement;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import net.forwardfire.unitxc.model.ModelJAXBInfoSet;
|
||||
import net.forwardfire.unitxc.model.ModelJAXBObjectWrapAdapter;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 17, 2015
|
||||
*/
|
||||
@XmlRootElement(name=ModelJAXBInfoSet.Element.CONDITION)
|
||||
public class UnitXCConverterStepCondition extends AbstractUnitXConverterStep {
|
||||
|
||||
private UnitXCConverterStepConditionEquality equality;
|
||||
private UnitXConverterStepValueRead operandA;
|
||||
private UnitXConverterStepValueRead operandB;
|
||||
private final List<UnitXConverterStep> conditionalSteps;
|
||||
|
||||
public UnitXCConverterStepCondition() {
|
||||
this.conditionalSteps = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runStep(UnitXConverterStepContext ctx) {
|
||||
if (equality.execute(operandA.valueRead(ctx),operandB.valueRead(ctx))) {
|
||||
ctx.runSteps(conditionalSteps);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the equality
|
||||
*/
|
||||
@XmlAttribute
|
||||
public UnitXCConverterStepConditionEquality getEquality() {
|
||||
return equality;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param equality the equality to set
|
||||
*/
|
||||
public void setEquality(UnitXCConverterStepConditionEquality equality) {
|
||||
this.equality = equality;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the operandA
|
||||
*/
|
||||
@XmlJavaTypeAdapter(value=ModelJAXBObjectWrapAdapter.class)
|
||||
public UnitXConverterStepValueRead getOperandA() {
|
||||
return operandA;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param operandA the operandA to set
|
||||
*/
|
||||
public void setOperandA(UnitXConverterStepValueRead operandA) {
|
||||
this.operandA = operandA;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the operandB
|
||||
*/
|
||||
@XmlJavaTypeAdapter(value=ModelJAXBObjectWrapAdapter.class)
|
||||
public UnitXConverterStepValueRead getOperandB() {
|
||||
return operandB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param operandB the operandB to set
|
||||
*/
|
||||
public void setOperandB(UnitXConverterStepValueRead operandB) {
|
||||
this.operandB = operandB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the conditionalSteps
|
||||
*/
|
||||
@XmlElementWrapper
|
||||
@XmlAnyElement
|
||||
public List<UnitXConverterStep> getConditionalSteps() {
|
||||
return conditionalSteps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param conditionalSteps the conditionalSteps to set
|
||||
*/
|
||||
public void setConditionalSteps(List<UnitXConverterStep> conditionalSteps) {
|
||||
this.conditionalSteps.clear();
|
||||
this.conditionalSteps.addAll(conditionalSteps);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package net.forwardfire.unitxc.model.step;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
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),
|
||||
;
|
||||
|
||||
private final BiFunction<Double,Double,Boolean> opertionDouble;
|
||||
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) {
|
||||
this.opertionDouble = opertionDouble;
|
||||
this.opertionInteger = opertionInteger;
|
||||
this.opertionString = opertionString;
|
||||
}
|
||||
|
||||
public boolean execute(Object left, Object right) {
|
||||
if (Double.class.equals(left.getClass())) {
|
||||
return opertionDouble.apply(Double.class.cast(left), Double.class.cast(right));
|
||||
}
|
||||
if (Integer.class.equals(left.getClass())) {
|
||||
return opertionInteger.apply(Integer.class.cast(left), Integer.class.cast(right));
|
||||
}
|
||||
if (String.class.equals(left.getClass())) {
|
||||
return opertionString.apply(String.class.cast(left), String.class.cast(right));
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown typeClass: "+left.getClass());
|
||||
}
|
||||
}
|
|
@ -21,9 +21,16 @@
|
|||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.converter.step;
|
||||
package net.forwardfire.unitxc.model.step;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import net.forwardfire.unitxc.model.ModelJAXBInfoSet;
|
||||
import net.forwardfire.unitxc.model.ModelJAXBObjectWrapAdapter;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReadWrite;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -31,47 +38,86 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 17, 2015
|
||||
*/
|
||||
@XmlRootElement
|
||||
public class UnitXCTypeMultiplyConverterStep extends AbstractUnitXConverterStep {
|
||||
@XmlRootElement(name=ModelJAXBInfoSet.Element.OPERATION)
|
||||
public class UnitXCConverterStepOperation extends AbstractUnitXConverterStep {
|
||||
|
||||
private final static String STEP_NAME = "Multiply";
|
||||
private double factor;
|
||||
private UnitXCConverterStepOperationOperator operator;
|
||||
private UnitXConverterStepValueRead operandA;
|
||||
private UnitXConverterStepValueRead operandB;
|
||||
private UnitXConverterStepValueReadWrite result;
|
||||
|
||||
public UnitXCTypeMultiplyConverterStep() {
|
||||
super(STEP_NAME);
|
||||
public UnitXCConverterStepOperation() {
|
||||
}
|
||||
|
||||
public UnitXCTypeMultiplyConverterStep(double factor) {
|
||||
this();
|
||||
setFactor(factor);
|
||||
public UnitXCConverterStepOperation(UnitXCConverterStepOperationOperator operator,UnitXConverterStepValueRead operandA,UnitXConverterStepValueRead operandB,UnitXConverterStepValueReadWrite result) {
|
||||
setOperator(operator);
|
||||
setOperandA(operandA);
|
||||
setOperandB(operandB);
|
||||
setResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractUnitXConverterStep createClone() {
|
||||
return new UnitXCTypeMultiplyConverterStep(getFactor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double convert(double value) {
|
||||
return value*factor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toMath() {
|
||||
return "*"+factor;
|
||||
public void runStep(UnitXConverterStepContext ctx) {
|
||||
result.valueWrite(ctx, operator.execute(operandA.valueRead(ctx),operandB.valueRead(ctx)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the factor
|
||||
* @return the operator
|
||||
*/
|
||||
public double getFactor() {
|
||||
return factor;
|
||||
@XmlAttribute
|
||||
public UnitXCConverterStepOperationOperator getOperator() {
|
||||
return operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param factor the factor to set
|
||||
* @param operator the operator to set
|
||||
*/
|
||||
public void setFactor(double factor) {
|
||||
this.factor = factor;
|
||||
public void setOperator(UnitXCConverterStepOperationOperator operator) {
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the operandA
|
||||
*/
|
||||
@XmlJavaTypeAdapter(value=ModelJAXBObjectWrapAdapter.class)
|
||||
public UnitXConverterStepValueRead getOperandA() {
|
||||
return operandA;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param operandA the operandA to set
|
||||
*/
|
||||
public void setOperandA(UnitXConverterStepValueRead operandA) {
|
||||
this.operandA = operandA;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the operandB
|
||||
*/
|
||||
@XmlJavaTypeAdapter(value=ModelJAXBObjectWrapAdapter.class)
|
||||
public UnitXConverterStepValueRead getOperandB() {
|
||||
return operandB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param operandB the operandB to set
|
||||
*/
|
||||
public void setOperandB(UnitXConverterStepValueRead operandB) {
|
||||
this.operandB = operandB;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the result
|
||||
*/
|
||||
@XmlJavaTypeAdapter(value=ModelJAXBObjectWrapAdapter.class)
|
||||
public UnitXConverterStepValueReadWrite getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param result the result to set
|
||||
*/
|
||||
public void setResult(UnitXConverterStepValueReadWrite result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package net.forwardfire.unitxc.model.step;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.util.function.BinaryOperator;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
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),
|
||||
;
|
||||
|
||||
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) {
|
||||
this.opertionDouble = opertionDouble;
|
||||
this.opertionInteger = opertionInteger;
|
||||
this.opertionString = opertionString;
|
||||
}
|
||||
|
||||
private static BigDecimal p(BigDecimal l,BigDecimal r) {
|
||||
return l.pow(r.intValueExact(), MathContext.UNLIMITED);
|
||||
}
|
||||
|
||||
private static double p(double l,double r) {
|
||||
return Math.pow(l, r);
|
||||
}
|
||||
|
||||
private static int p(int l,int r) {
|
||||
for (int i=0;i<r;i++) {
|
||||
l = l * l;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
public Object execute(Object left, Object right) {
|
||||
if (Double.class.equals(left.getClass())) {
|
||||
return opertionDouble.apply(Double.class.cast(left), Double.class.cast(right));
|
||||
}
|
||||
if (Integer.class.equals(left.getClass())) {
|
||||
return opertionInteger.apply(Integer.class.cast(left), Integer.class.cast(right));
|
||||
}
|
||||
if (String.class.equals(left.getClass())) {
|
||||
return opertionString.apply(String.class.cast(left), String.class.cast(right));
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown typeClass: "+left.getClass());
|
||||
}
|
||||
}
|
|
@ -21,9 +21,16 @@
|
|||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.converter.step;
|
||||
package net.forwardfire.unitxc.model.step;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import net.forwardfire.unitxc.model.ModelJAXBInfoSet;
|
||||
import net.forwardfire.unitxc.model.ModelJAXBObjectWrapAdapter;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReadWrite;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -31,29 +38,30 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 17, 2015
|
||||
*/
|
||||
@XmlRootElement
|
||||
public class UnitXCTypePowerOfTenConverterStep extends AbstractUnitXConverterStep {
|
||||
@XmlRootElement(name=ModelJAXBInfoSet.Element.POWER_10)
|
||||
public class UnitXCConverterStepPowerOfTen extends AbstractUnitXConverterStep {
|
||||
|
||||
private final static String STEP_NAME = "power(10)";
|
||||
private UnitXConverterStepValueRead operand;
|
||||
private UnitXConverterStepValueReadWrite result;
|
||||
private int exponent;
|
||||
private boolean exponentReverse;
|
||||
|
||||
public UnitXCTypePowerOfTenConverterStep() {
|
||||
super(STEP_NAME);
|
||||
public UnitXCConverterStepPowerOfTen() {
|
||||
}
|
||||
|
||||
public UnitXCTypePowerOfTenConverterStep(int exponent,boolean exponentReverse) {
|
||||
public UnitXCConverterStepPowerOfTen(int exponent,boolean exponentReverse,UnitXConverterStepValueRead operand,UnitXConverterStepValueReadWrite result) {
|
||||
this();
|
||||
setExponent(exponent);
|
||||
setExponentReverse(exponentReverse);
|
||||
setOperand(operand);
|
||||
setResult(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractUnitXConverterStep createClone() {
|
||||
return new UnitXCTypePowerOfTenConverterStep(getExponent(),isExponentReverse());
|
||||
public void runStep(UnitXConverterStepContext ctx) {
|
||||
result.valueWrite(ctx, convert((Double)operand.valueRead(ctx)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double convert(double value) {
|
||||
int exponentShift = exponent<0?0-exponent:exponent;
|
||||
for (int i=0;i<exponentShift;i++) {
|
||||
|
@ -62,12 +70,6 @@ public class UnitXCTypePowerOfTenConverterStep extends AbstractUnitXConverterSte
|
|||
return value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String toMath() {
|
||||
return "*10^"+exponent;
|
||||
}
|
||||
|
||||
private double shiftDotStatic(double value,boolean up) {
|
||||
String valueStr = ""+value;
|
||||
int dotIdx = valueStr.indexOf('.');
|
||||
|
@ -83,28 +85,30 @@ public class UnitXCTypePowerOfTenConverterStep extends AbstractUnitXConverterSte
|
|||
Double result = new Double(buf.toString());
|
||||
return result.doubleValue();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the exponent
|
||||
*/
|
||||
@XmlAttribute
|
||||
public int getExponent() {
|
||||
return exponent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param exponent the exponent to set
|
||||
*/
|
||||
public void setExponent(int exponent) {
|
||||
this.exponent = exponent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the exponentReverse
|
||||
*/
|
||||
@XmlAttribute
|
||||
public boolean isExponentReverse() {
|
||||
return exponentReverse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param exponentReverse the exponentReverse to set
|
||||
*/
|
||||
|
@ -112,5 +116,33 @@ public class UnitXCTypePowerOfTenConverterStep extends AbstractUnitXConverterSte
|
|||
this.exponentReverse = exponentReverse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the operand
|
||||
*/
|
||||
@XmlJavaTypeAdapter(value=ModelJAXBObjectWrapAdapter.class)
|
||||
public UnitXConverterStepValueRead getOperand() {
|
||||
return operand;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param operand the operand to set
|
||||
*/
|
||||
public void setOperand(UnitXConverterStepValueRead operand) {
|
||||
this.operand = operand;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the result
|
||||
*/
|
||||
@XmlJavaTypeAdapter(value=ModelJAXBObjectWrapAdapter.class)
|
||||
public UnitXConverterStepValueReadWrite getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param result the result to set
|
||||
*/
|
||||
public void setResult(UnitXConverterStepValueReadWrite result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* 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.step;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import net.forwardfire.unitxc.model.ModelJAXBInfoSet;
|
||||
import net.forwardfire.unitxc.model.UnitXCType;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 7, 2016
|
||||
*/
|
||||
@XmlRootElement(name=ModelJAXBInfoSet.Element.REFERENCE)
|
||||
public class UnitXCConverterStepReference extends AbstractUnitXConverterStep {
|
||||
|
||||
private String unitTypeId;
|
||||
private Boolean toBaseSteps;
|
||||
|
||||
public UnitXCConverterStepReference() {
|
||||
}
|
||||
|
||||
public UnitXCConverterStepReference(String unitTypeId,Boolean toBaseSteps) {
|
||||
setUnitTypeId(unitTypeId);
|
||||
setToBaseSteps(toBaseSteps);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runStep(UnitXConverterStepContext ctx) {
|
||||
UnitXCType type = ctx.getUnitManager().getUnitType(getUnitTypeId());
|
||||
List<UnitXConverterStep> steps = Boolean.TRUE.equals(toBaseSteps)?type.getToBaseConverterSteps():type.getFromBaseConverterSteps();
|
||||
ctx.runSteps(steps);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the unitTypeId
|
||||
*/
|
||||
@XmlAttribute
|
||||
public String getUnitTypeId() {
|
||||
return unitTypeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unitTypeId the unitTypeId to set
|
||||
*/
|
||||
public void setUnitTypeId(String unitTypeId) {
|
||||
this.unitTypeId = unitTypeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the toBaseSteps
|
||||
*/
|
||||
@XmlAttribute
|
||||
public Boolean getToBaseSteps() {
|
||||
return toBaseSteps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param toBaseSteps the toBaseSteps to set
|
||||
*/
|
||||
public void setToBaseSteps(Boolean toBaseSteps) {
|
||||
this.toBaseSteps = toBaseSteps;
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@
|
|||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.converter.step;
|
||||
package net.forwardfire.unitxc.model.step;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -31,17 +31,11 @@ import java.util.List;
|
|||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 10, 2015
|
||||
*/
|
||||
public interface UnitXConverterStep extends Cloneable {
|
||||
public interface UnitXConverterStep {
|
||||
|
||||
String getName();
|
||||
void runStep(UnitXConverterStepContext ctx);
|
||||
|
||||
List<String> getStepReasons();
|
||||
|
||||
void addStepReason(String stepReason); // TODO: rm : fix builder
|
||||
|
||||
String getMathExpression();
|
||||
|
||||
double convert(double value);
|
||||
|
||||
UnitXConverterStep clone();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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.step;
|
||||
|
||||
import java.math.MathContext;
|
||||
import java.util.List;
|
||||
|
||||
import net.forwardfire.unitxc.UnitXCManager;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueNamedVariable;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueRead;
|
||||
import net.forwardfire.unitxc.model.step.value.UnitXConverterStepValueReadWrite;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 10, 2015
|
||||
*/
|
||||
public interface UnitXConverterStepContext {
|
||||
|
||||
static final String VALUE = "value";
|
||||
static final String VALUE_START = "valueStart";
|
||||
|
||||
MathContext getMathContext();
|
||||
|
||||
void setNamedVariable(String name,UnitXConverterStepValueReadWrite variable);
|
||||
|
||||
UnitXConverterStepValueReadWrite getNamedVariable(String name);
|
||||
|
||||
UnitXConverterStepValueRead getNamedParameter(String name);
|
||||
|
||||
void runSteps(List<UnitXConverterStep> steps);
|
||||
|
||||
UnitXCManager getUnitManager();
|
||||
|
||||
public static UnitXConverterStepValueReadWrite createStepValue() {
|
||||
return new UnitXConverterStepValueNamedVariable(Double.class,VALUE);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
|
||||
/**
|
||||
* @author willemc
|
||||
*
|
||||
*/
|
||||
package net.forwardfire.unitxc.model.step;
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* 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.step.value;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import net.forwardfire.unitxc.model.ModelJAXBInfoSet;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 1, 2016
|
||||
*/
|
||||
@XmlRootElement(name=ModelJAXBInfoSet.Element.NAMED_PARAMETER)
|
||||
public class UnitXConverterStepValueNamedParameter implements UnitXConverterStepValueRead {
|
||||
|
||||
private String parameterName;
|
||||
|
||||
public UnitXConverterStepValueNamedParameter() {
|
||||
}
|
||||
|
||||
public UnitXConverterStepValueNamedParameter(String parameterName) {
|
||||
setParameterName(parameterName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object valueRead(UnitXConverterStepContext ctx) {
|
||||
return ctx.getNamedParameter(parameterName).valueRead(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXConverterStepValueRead clone() {
|
||||
UnitXConverterStepValueNamedParameter clone = new UnitXConverterStepValueNamedParameter();
|
||||
clone.setParameterName(getParameterName());
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parameterName
|
||||
*/
|
||||
@XmlAttribute
|
||||
public String getParameterName() {
|
||||
return parameterName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parameterName the parameterName to set
|
||||
*/
|
||||
public void setParameterName(String parameterName) {
|
||||
this.parameterName = parameterName;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* 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.step.value;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import net.forwardfire.unitxc.model.ModelJAXBInfoSet;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 1, 2016
|
||||
*/
|
||||
@XmlRootElement(name=ModelJAXBInfoSet.Element.NAMED_VARIABLE)
|
||||
public class UnitXConverterStepValueNamedVariable implements UnitXConverterStepValueReadWrite {
|
||||
|
||||
private Class<?> valueType;
|
||||
private String variableName;
|
||||
|
||||
public UnitXConverterStepValueNamedVariable() {
|
||||
}
|
||||
|
||||
public UnitXConverterStepValueNamedVariable(Class<?> valueType,String variableName) {
|
||||
setValueType(valueType);
|
||||
setVariableName(variableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object valueRead(UnitXConverterStepContext ctx) {
|
||||
return ctx.getNamedVariable(variableName).valueRead(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueWrite(UnitXConverterStepContext ctx,Object value) {
|
||||
ctx.getNamedVariable(variableName).valueWrite(ctx,value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXConverterStepValueReadWrite clone() {
|
||||
UnitXConverterStepValueNamedVariable clone = new UnitXConverterStepValueNamedVariable();
|
||||
clone.setValueType(getValueType());
|
||||
clone.setVariableName(getVariableName());
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the variableName
|
||||
*/
|
||||
@XmlAttribute
|
||||
public String getVariableName() {
|
||||
return variableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param variableName the variableName to set
|
||||
*/
|
||||
public void setVariableName(String variableName) {
|
||||
this.variableName = variableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the valueType
|
||||
*/
|
||||
@XmlAttribute
|
||||
public Class<?> getValueType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param valueType the valueType to set
|
||||
*/
|
||||
public void setValueType(Class<?> valueType) {
|
||||
this.valueType = valueType;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.model.step.value;
|
||||
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 1, 2016
|
||||
*/
|
||||
public interface UnitXConverterStepValueRead extends Cloneable {
|
||||
|
||||
Object valueRead(UnitXConverterStepContext ctx);
|
||||
|
||||
UnitXConverterStepValueRead clone();
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.model.step.value;
|
||||
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 1, 2016
|
||||
*/
|
||||
public interface UnitXConverterStepValueReadWrite extends UnitXConverterStepValueRead {
|
||||
|
||||
void valueWrite(UnitXConverterStepContext ctx,Object value);
|
||||
|
||||
UnitXConverterStepValueReadWrite clone();
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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.step.value;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
|
||||
import net.forwardfire.unitxc.model.ModelJAXBInfoSet;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
* Holds an Double value.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 1, 2016
|
||||
*/
|
||||
@XmlRootElement(name=ModelJAXBInfoSet.Element.VALUE_DOUBLE)
|
||||
public class UnitXConverterStepValueReferenceDouble implements UnitXConverterStepValueReadWrite {
|
||||
|
||||
private Double value;
|
||||
|
||||
public UnitXConverterStepValueReferenceDouble() {
|
||||
}
|
||||
|
||||
public UnitXConverterStepValueReferenceDouble(Double value) {
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object valueRead(UnitXConverterStepContext ctx) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueWrite(UnitXConverterStepContext ctx,Object value) {
|
||||
this.value = Double.class.cast(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXConverterStepValueReadWrite clone() {
|
||||
return new UnitXConverterStepValueReferenceDouble(getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
//@XmlAttribute
|
||||
@XmlValue
|
||||
public Double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value the value to set
|
||||
*/
|
||||
public void setValue(Double value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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.step.value;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import net.forwardfire.unitxc.model.ModelJAXBInfoSet;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
* Holds an Double value as a Fraction.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 1, 2016
|
||||
*/
|
||||
@XmlRootElement(name=ModelJAXBInfoSet.Element.VALUE_DOUBLE_FRACTION)
|
||||
public class UnitXConverterStepValueReferenceDoubleFraction implements UnitXConverterStepValueRead {
|
||||
|
||||
private int numerator;
|
||||
private int denominator;
|
||||
|
||||
public UnitXConverterStepValueReferenceDoubleFraction() {
|
||||
}
|
||||
|
||||
public UnitXConverterStepValueReferenceDoubleFraction(int numerator,int denominator) {
|
||||
setNumerator(numerator);
|
||||
setDenominator(denominator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object valueRead(UnitXConverterStepContext ctx) {
|
||||
//new BigDecimal(numerator).divide(new BigDecimal(denominator));
|
||||
return (Double)(((Integer)numerator).doubleValue()/((Integer)denominator).doubleValue()); // FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXConverterStepValueRead clone() {
|
||||
return new UnitXConverterStepValueReferenceDoubleFraction(getNumerator(),getDenominator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the numerator
|
||||
*/
|
||||
@XmlAttribute
|
||||
public int getNumerator() {
|
||||
return numerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param numerator the numerator to set
|
||||
*/
|
||||
public void setNumerator(int numerator) {
|
||||
this.numerator = numerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the denominator
|
||||
*/
|
||||
@XmlAttribute
|
||||
public int getDenominator() {
|
||||
return denominator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param denominator the denominator to set
|
||||
*/
|
||||
public void setDenominator(int denominator) {
|
||||
this.denominator = denominator;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.model.step.value;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import net.forwardfire.unitxc.model.ModelJAXBInfoSet;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
* Holds an Integer value.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 1, 2016
|
||||
*/
|
||||
@XmlRootElement(name=ModelJAXBInfoSet.Element.VALUE_INTEGER)
|
||||
public class UnitXConverterStepValueReferenceInteger implements UnitXConverterStepValueReadWrite {
|
||||
|
||||
private Integer value;
|
||||
|
||||
public UnitXConverterStepValueReferenceInteger() {
|
||||
}
|
||||
|
||||
public UnitXConverterStepValueReferenceInteger(Integer value) {
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object valueRead(UnitXConverterStepContext ctx) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueWrite(UnitXConverterStepContext ctx,Object value) {
|
||||
this.value = Integer.class.cast(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXConverterStepValueReadWrite clone() {
|
||||
return new UnitXConverterStepValueReferenceInteger(getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
@XmlAttribute
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value the value to set
|
||||
*/
|
||||
public void setValue(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.model.step.value;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import net.forwardfire.unitxc.model.ModelJAXBInfoSet;
|
||||
import net.forwardfire.unitxc.model.step.UnitXConverterStepContext;
|
||||
|
||||
/**
|
||||
* Holds an String value.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Apr 1, 2016
|
||||
*/
|
||||
@XmlRootElement(name=ModelJAXBInfoSet.Element.VALUE_STRING)
|
||||
public class UnitXConverterStepValueReferenceString implements UnitXConverterStepValueReadWrite {
|
||||
|
||||
private String value;
|
||||
|
||||
public UnitXConverterStepValueReferenceString() {
|
||||
}
|
||||
|
||||
public UnitXConverterStepValueReferenceString(String value) {
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object valueRead(UnitXConverterStepContext ctx) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueWrite(UnitXConverterStepContext ctx,Object value) {
|
||||
this.value = String.class.cast(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitXConverterStepValueReadWrite clone() {
|
||||
return new UnitXConverterStepValueReferenceString(getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
@XmlAttribute
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value the value to set
|
||||
*/
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
/**
|
||||
* @author willemc
|
||||
*
|
||||
*/
|
||||
package net.forwardfire.unitxc.model.step.value;
|
|
@ -38,10 +38,13 @@ import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix;
|
|||
*/
|
||||
public class UnitXCModuleElectricCurrent implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "current";
|
||||
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 TYPE_AMPERE_ID = "A";
|
||||
public static final String TYPE_AMPERE_NAME = "ampere";
|
||||
public static final String GROUP_BASE_TYPE_ID = "A";
|
||||
|
||||
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_FLAG = buildFlag(GROUP_ID,TYPE_AMPERE_NAME);
|
||||
private static final String TYPE_AMPERE_WIKI = "Ampere";
|
||||
|
||||
|
|
|
@ -38,10 +38,13 @@ import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix;
|
|||
*/
|
||||
public class UnitXCModuleLength implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "length";
|
||||
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 TYPE_METRE_ID = "m";
|
||||
public static final String TYPE_METRE_NAME = "metre";
|
||||
public static final String GROUP_BASE_TYPE_ID = "m";
|
||||
|
||||
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_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);
|
||||
|
|
|
@ -37,11 +37,14 @@ import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
|||
*/
|
||||
public class UnitXCModuleLuminousIntensity implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "light";
|
||||
public static final String GROUP_DESCRIPTION = "The candela is the luminous intensity, in a given direction, of a source that emits monochromatic radiation of frequency 540×1012 hertz and that has a radiant intensity in that direction of 1/683 watt per steradian.";
|
||||
public static final String TYPE_CANDELA_ID = "cd";
|
||||
public static final String TYPE_CANDELA_NAME = "candela";
|
||||
public static final String TYPE_CANDELA_FLAG = buildFlag(GROUP_ID,TYPE_CANDELA_NAME);
|
||||
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_BASE_TYPE_ID = "cd";
|
||||
|
||||
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_FLAG = buildFlag(GROUP_ID,TYPE_CANDELA_NAME);
|
||||
private static final String TYPE_CANDELA_WIKI = "Candela";
|
||||
|
||||
@Override
|
||||
|
|
|
@ -41,7 +41,9 @@ public class UnitXCModuleMass 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 TYPE_GRAM_ID = "g";
|
||||
public static final String GROUP_BASE_TYPE_ID = "g";
|
||||
|
||||
public static final String TYPE_GRAM_ID = GROUP_BASE_TYPE_ID;
|
||||
public static final String TYPE_GRAM_NAME = "gram";
|
||||
public static final String TYPE_GRAM_FLAG = buildFlag(GROUP_ID,TYPE_GRAM_NAME);
|
||||
private static final String TYPE_GRAM_WIKI = "Kilogram";
|
||||
|
|
|
@ -38,18 +38,21 @@ import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix;
|
|||
*/
|
||||
public class UnitXCModuleSubstance implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "substance";
|
||||
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 TYPE_MOLE_ID = "mol";
|
||||
public static final String TYPE_MOLE_NAME = "mole";
|
||||
public static final String TYPE_MOLE_FLAG = buildFlag(GROUP_ID,TYPE_MOLE_NAME);
|
||||
public static final String GROUP_BASE_TYPE_ID = "mol";
|
||||
|
||||
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_POUND_MOLE_ID = "lbmol";
|
||||
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);
|
||||
public static final String TYPE_POUND_MOLE_ID = "lbmol";
|
||||
public static final String TYPE_POUND_MOLE_NAME = "pound-mole";
|
||||
public static final String TYPE_POUND_MOLE_FLAG = buildFlag(GROUP_ID,TYPE_POUND_MOLE_NAME);
|
||||
private static final double TYPE_POUND_MOLE_FACTOR = 453.59237;
|
||||
private static final String TYPE_POUND_MOLE_WIKI = "Mole_(unit)#Other_units_called_.22mole.22";
|
||||
private static final String TYPE_POUND_MOLE_WIKI = "Mole_(unit)#Other_units_called_.22mole.22";
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
|
|
|
@ -39,11 +39,13 @@ import org.apache.commons.lang3.math.Fraction;
|
|||
*/
|
||||
public class UnitXCModuleTemperature implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "temperature";
|
||||
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_BASE_TYPE_ID = "K";
|
||||
|
||||
public static final String TYPE_KELVIN_ID = "K";
|
||||
public static final String TYPE_KELVIN_NAME = "kelvin";
|
||||
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_FLAG = buildFlag(GROUP_ID,TYPE_KELVIN_NAME);
|
||||
private static final String TYPE_KELVIN_WIKI = "Kelvin";
|
||||
|
||||
|
|
|
@ -39,9 +39,12 @@ import net.forwardfire.unitxc.config.builder.UnitXCTypeSIPrefix;
|
|||
public class UnitXCModuleTime 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 TYPE_SECOND_ID = "s";
|
||||
public static final String TYPE_SECOND_NAME = "second";
|
||||
public static final String GROUP_BASE_TYPE_ID = "s";
|
||||
|
||||
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_NAMES = TYPE_SECOND_NAME+TYPE_SECOND_ID;
|
||||
public static final String TYPE_SECOND_FLAG = buildFlag(GROUP_ID,TYPE_SECOND_NAME);
|
||||
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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 static net.forwardfire.unitxc.config.builder.UnitXCNumberTypeSetting.toSuperScript;
|
||||
import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 1, 2016
|
||||
*/
|
||||
public class UnitXCModuleAcceleration 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+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleTime.GROUP_NAME;
|
||||
public static final String GROUP_DESCRIPTION = "Acceleration, is the rate of change of velocity of an object with respect to time.";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleSpeed.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID;
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroup()
|
||||
.setGroupLevel( SI_DERIVED)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
.createCompoundPairUnitTypes(UnitXCModuleSpeed.GROUP_ID, UnitXCModuleTime.GROUP_ID)
|
||||
.build()
|
||||
.build()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -21,14 +21,14 @@
|
|||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.module;
|
||||
package net.forwardfire.unitxc.module.derived;
|
||||
|
||||
import static net.forwardfire.unitxc.config.UnitXCConfigModule.buildFlag;
|
||||
import static net.forwardfire.unitxc.config.builder.UnitXCNumberTypeSetting.toSuperScript;
|
||||
import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleLength;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -43,9 +43,9 @@ public class UnitXCModuleArea implements UnitXCConfigModule {
|
|||
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.TYPE_METRE_NAME;
|
||||
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.TYPE_METRE_ID+UNIT_ID_POSTFIX;
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleLength.GROUP_BASE_TYPE_ID+UNIT_ID_POSTFIX;
|
||||
|
||||
public static final String TYPE_CENTIARE_ALIAS = "m²";
|
||||
public static final String TYPE_CENTIARE_ID = "ca";
|
||||
|
|
|
@ -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.module.derived;
|
||||
|
||||
import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleMass;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 12, 2016
|
||||
*/
|
||||
public class UnitXCModuleAreaDensity implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "area_density";
|
||||
public static final String GROUP_NAME = UnitXCModuleMass.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleArea.GROUP_NAME;
|
||||
public static final String GROUP_DESCRIPTION = "Area density is of a two-dimensional object is calculated as the mass per unit area.";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMass.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleArea.GROUP_BASE_TYPE_ID;
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroup()
|
||||
.setGroupLevel( SI_DERIVED)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
.createCompoundPairUnitTypes(UnitXCModuleMass.GROUP_ID, UnitXCModuleArea.GROUP_ID)
|
||||
.build()
|
||||
.build()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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 static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 1, 2016
|
||||
*/
|
||||
public class UnitXCModuleJerk implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "jerk";
|
||||
public static final String GROUP_NAME = UnitXCModuleAcceleration.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleTime.GROUP_NAME;
|
||||
public static final String GROUP_DESCRIPTION = "Jerk, also known as jolt, surge, or lurch, is the rate of change of acceleration, with respect to time.";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleAcceleration.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID;
|
||||
|
||||
// TODO: add aliases
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroup()
|
||||
.setGroupLevel( SI_DERIVED)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
.createCompoundPairUnitTypes(UnitXCModuleAcceleration.GROUP_ID, UnitXCModuleTime.GROUP_ID)
|
||||
.build()
|
||||
.build()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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 static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 1, 2016
|
||||
*/
|
||||
public class UnitXCModuleJounce implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "jounce";
|
||||
public static final String GROUP_NAME = UnitXCModuleJerk.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleTime.GROUP_NAME;
|
||||
public static final String GROUP_DESCRIPTION = "Is the fourth derivative of the position vector with respect to time or the rate of change of the jerk with respect to time.";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleJerk.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID;
|
||||
|
||||
// TODO: add aliases
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroup()
|
||||
.setGroupLevel( SI_DERIVED)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
.createCompoundPairUnitTypes(UnitXCModuleJerk.GROUP_ID, UnitXCModuleTime.GROUP_ID)
|
||||
.build()
|
||||
.build()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -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.module.derived;
|
||||
|
||||
import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleMass;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 12, 2016
|
||||
*/
|
||||
public class UnitXCModuleMassDensity implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "mass_density";
|
||||
public static final String GROUP_NAME = UnitXCModuleMass.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleVolume.GROUP_NAME;
|
||||
public static final String GROUP_DESCRIPTION = "The volumetric mass density, of a substance is its mass per unit volume.";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleMass.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleVolume.GROUP_BASE_TYPE_ID;
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroup()
|
||||
.setGroupLevel( SI_DERIVED)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
.createCompoundPairUnitTypes(UnitXCModuleMass.GROUP_ID, UnitXCModuleVolume.GROUP_ID)
|
||||
.build()
|
||||
.build()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -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.module.derived;
|
||||
|
||||
import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder;
|
||||
import net.forwardfire.unitxc.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+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleVolume.GROUP_NAME;
|
||||
public static final String GROUP_DESCRIPTION = "Molar concentration is a measure of the concentration of a solute in a solution.";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleSubstance.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleVolume.GROUP_BASE_TYPE_ID;
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroup()
|
||||
.setGroupLevel( SI_DERIVED)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
.createCompoundPairUnitTypes(UnitXCModuleSubstance.GROUP_ID, UnitXCModuleVolume.GROUP_ID)
|
||||
.build()
|
||||
.build()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -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.module.derived;
|
||||
|
||||
import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleSubstance;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 12, 2016
|
||||
*/
|
||||
public class UnitXCModuleMolarVolume implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "molar_volume";
|
||||
public static final String GROUP_NAME = UnitXCModuleVolume.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleSubstance.GROUP_NAME;
|
||||
public static final String GROUP_DESCRIPTION = "Molar volume is the volume occupied by one mole of a substance.";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleVolume.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleSubstance.GROUP_BASE_TYPE_ID;
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroup()
|
||||
.setGroupLevel( SI_DERIVED)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
.createCompoundPairUnitTypes(UnitXCModuleVolume.GROUP_ID, UnitXCModuleSubstance.GROUP_ID)
|
||||
.build()
|
||||
.build()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -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.module.derived;
|
||||
|
||||
import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleMass;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 12, 2016
|
||||
*/
|
||||
public class UnitXCModuleSpecificVolume implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "specific_volume";
|
||||
public static final String GROUP_NAME = UnitXCModuleVolume.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleMass.GROUP_NAME;
|
||||
public static final String GROUP_DESCRIPTION = "In thermodynamics, the specific volume of a substance is the ratio of the substance's volume to its mass.";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleVolume.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleMass.GROUP_BASE_TYPE_ID;
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroup()
|
||||
.setGroupLevel( SI_DERIVED)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
.createCompoundPairUnitTypes(UnitXCModuleVolume.GROUP_ID, UnitXCModuleMass.GROUP_ID)
|
||||
.build()
|
||||
.build()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -21,13 +21,15 @@
|
|||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.module;
|
||||
package net.forwardfire.unitxc.module.derived;
|
||||
|
||||
import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleLength;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -38,9 +40,9 @@ import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder;
|
|||
public class UnitXCModuleSpeed implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "speed";
|
||||
public static final String GROUP_NAME = UnitXCModuleLength.TYPE_METRE_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleTime.TYPE_SECOND_NAME;;
|
||||
public static final String GROUP_NAME = UnitXCModuleLength.GROUP_NAME+UnitXCTypeCompoundPairBuilder.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.TYPE_METRE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleTime.TYPE_SECOND_ID;
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleLength.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID;
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
|
|
|
@ -21,13 +21,14 @@
|
|||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.forwardfire.unitxc.module;
|
||||
package net.forwardfire.unitxc.module.derived;
|
||||
|
||||
import static net.forwardfire.unitxc.config.builder.UnitXCNumberTypeSetting.toSuperScript;
|
||||
import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleLength;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -42,9 +43,9 @@ public class UnitXCModuleVolume implements UnitXCConfigModule {
|
|||
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.TYPE_METRE_NAME;
|
||||
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.TYPE_METRE_ID+UNIT_ID_POSTFIX;
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleLength.GROUP_BASE_TYPE_ID+UNIT_ID_POSTFIX;
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
|
|
|
@ -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.module.derived;
|
||||
|
||||
import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 1, 2016
|
||||
*/
|
||||
public class UnitXCModuleVolumetricFlow implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "volumetric_flow";
|
||||
public static final String GROUP_NAME = UnitXCModuleVolume.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleTime.GROUP_NAME;
|
||||
public static final String GROUP_DESCRIPTION = "Volumetric flow is the volume of fluid which passes per unit time.";
|
||||
public static final String GROUP_BASE_TYPE_ID = UnitXCModuleVolume.GROUP_BASE_TYPE_ID+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleTime.GROUP_BASE_TYPE_ID;
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroup()
|
||||
.setGroupLevel( SI_DERIVED)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
.createCompoundPairUnitTypes(UnitXCModuleVolume.GROUP_ID, UnitXCModuleTime.GROUP_ID)
|
||||
.build()
|
||||
.build()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* @author willemc
|
||||
*
|
||||
*/
|
||||
package net.forwardfire.unitxc.module.derived;
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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.named;
|
||||
|
||||
import static net.forwardfire.unitxc.model.UnitXCGroupLevel.SI_DERIVED;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfigModule;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCConfigBuilder;
|
||||
import net.forwardfire.unitxc.config.builder.UnitXCTypeCompoundPairBuilder;
|
||||
import net.forwardfire.unitxc.module.UnitXCModuleMass;
|
||||
import net.forwardfire.unitxc.module.derived.UnitXCModuleAcceleration;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Oct 12, 2016
|
||||
*/
|
||||
public class UnitXCModuleNewton implements UnitXCConfigModule {
|
||||
|
||||
public static final String GROUP_ID = "newton";
|
||||
public static final String GROUP_NAME = UnitXCModuleMass.GROUP_NAME+UnitXCTypeCompoundPairBuilder.PER_NAME+UnitXCModuleAcceleration.GROUP_NAME;
|
||||
public static final String GROUP_DESCRIPTION = "One newton is the force needed to accelerate one kilogram of mass at the rate of one metre per second squared in direction of the applied force.";
|
||||
public static final String GROUP_BASE_TYPE_ID = "kg"+UnitXCTypeCompoundPairBuilder.PER_ID+UnitXCModuleAcceleration.GROUP_BASE_TYPE_ID;
|
||||
|
||||
// TODO: symbol N + fix builder
|
||||
|
||||
@Override
|
||||
public void configModule(UnitXCConfigBuilder builder) {
|
||||
builder.createUnitGroup()
|
||||
.setGroupLevel( SI_DERIVED)
|
||||
.setId( GROUP_ID)
|
||||
.setName( GROUP_NAME)
|
||||
.setDescription ( GROUP_DESCRIPTION)
|
||||
.setBaseTypeId( GROUP_BASE_TYPE_ID)
|
||||
.createCompoundPairUnitTypes(UnitXCModuleMass.GROUP_ID, UnitXCModuleAcceleration.GROUP_ID)
|
||||
.build()
|
||||
.build()
|
||||
;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @author willemc
|
||||
*
|
||||
*/
|
||||
package net.forwardfire.unitxc.module.named;
|
|
@ -26,6 +26,18 @@ package net.forwardfire.unitxc;
|
|||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.codehaus.jettison.mapped.Configuration;
|
||||
import org.codehaus.jettison.mapped.MappedNamespaceConvention;
|
||||
import org.codehaus.jettison.mapped.MappedXMLStreamWriter;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -34,8 +46,9 @@ import static net.forwardfire.unitxc.UnitXCAssert.convertEquals;
|
|||
|
||||
import net.forwardfire.unitxc.UnitXCFactory;
|
||||
import net.forwardfire.unitxc.UnitXCManager;
|
||||
import net.forwardfire.unitxc.converter.UnitXConverterParameterValue;
|
||||
import net.forwardfire.unitxc.model.UnitXCType;
|
||||
import net.forwardfire.unitxc.model.ModelXMLMarshaller;
|
||||
import net.forwardfire.unitxc.model.ModelJAXBMarshaller;
|
||||
import net.forwardfire.unitxc.model.UnitXCGroup;
|
||||
import net.forwardfire.unitxc.model.UnitXConverterResult;
|
||||
import net.forwardfire.unitxc.model.UnitXConverterResultStep;
|
||||
|
@ -44,77 +57,124 @@ public class UnitXCConverterStepTest {
|
|||
|
||||
@Test
|
||||
public void testFac() throws Exception {
|
||||
ModelXMLMarshaller xmlDriver = new ModelXMLMarshaller();
|
||||
ModelJAXBMarshaller jaxbDriver = new ModelJAXBMarshaller();
|
||||
UnitXCManager unitManager = UnitXCFactory.createManager();
|
||||
|
||||
assertNotNull(unitManager);
|
||||
assertNotNull(unitManager.getUnitTypes());
|
||||
assertNotNull(unitManager.getUnitGroups());
|
||||
assertFalse(unitManager.getUnitTypes().isEmpty());
|
||||
assertFalse(unitManager.getUnitGroups().isEmpty());
|
||||
|
||||
assertNotNull(unitManager.getUnitTypes());
|
||||
|
||||
for (UnitXCGroup typeGroup:unitManager.getUnitGroups()) {
|
||||
assertNotNull(unitManager.getConfig());
|
||||
assertNotNull(unitManager.getConfig().getUnitGroups());
|
||||
assertFalse(unitManager.getConfig().getUnitGroups().isEmpty());
|
||||
|
||||
long ts = 0l;
|
||||
for (UnitXCGroup typeGroup:unitManager.getConfig().getUnitGroups()) {
|
||||
UnitXCType type = unitManager.getUnitType(typeGroup.getBaseTypeId());
|
||||
System.out.println("TypeGroup: "+typeGroup.getId()+"\t name: "+typeGroup.getName()+"\t\t baseType: "+typeGroup.getBaseTypeId()+" id: "+type.getId());
|
||||
|
||||
int total = 0;
|
||||
for (UnitXCType t:unitManager.getUnitTypes()) {
|
||||
if (!t.getUnitGroupId().equals(typeGroup.getId())) {
|
||||
continue;
|
||||
}
|
||||
total++;
|
||||
if (type == null) {
|
||||
throw new IllegalStateException("No base type for: "+typeGroup);
|
||||
}
|
||||
System.out.println("typeInGroup: "+total);
|
||||
long tc = typeGroup.getTotalUnitTypes();
|
||||
ts += tc;
|
||||
System.out.println("TypeGroup: "+typeGroup.getId()+"\tunits:"+tc+"\t name: "+typeGroup.getName()+"\t\t baseType: "+type.getId());
|
||||
}
|
||||
int ts = unitManager.getUnitTypes().size();
|
||||
System.out.println("\ntotalTypes: "+ts);
|
||||
System.out.println("totalConv: "+(ts*ts-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");
|
||||
|
||||
UnitXConverterResult result = unitManager.getConverter().convertStepped(211.0, "k°F", "m°C");
|
||||
System.out.println("Convert from: "+result.getStartValueType().getName()+" to: "+result.getResultValueType().getName());
|
||||
System.out.println("startValue: "+result.getStartValue());
|
||||
System.out.println("resultValue: "+result.getResultValue());
|
||||
System.out.println("convertTime: "+result.getConvertTime());
|
||||
for (UnitXConverterResultStep step:result.getResultSteps()) {
|
||||
System.out.println("step: "+step.getName()+" in: "+step.getStartValue()+" out: "+step.getResultValue()+" time: "+step.getConvertTime());
|
||||
}
|
||||
|
||||
xmlDriver.marshal(result, System.out);
|
||||
jaxbDriver.getUnitXConverterResult().marshal(result, System.out);
|
||||
System.out.println("");
|
||||
|
||||
result = unitManager.getConverter().convertStepped(10.763, "ft²", "in²");
|
||||
System.out.println("Convert from: "+result.getStartValueType().getName()+" to: "+result.getResultValueType().getName());
|
||||
System.out.println("startValue: "+result.getStartValue());
|
||||
System.out.println("resultValue: "+result.getResultValue());
|
||||
System.out.println("convertTime: "+result.getConvertTime());
|
||||
for (UnitXConverterResultStep step:result.getResultSteps()) {
|
||||
System.out.println("step: "+step.getName()+" in: "+step.getStartValue()+" out: "+step.getResultValue()+" time: "+step.getConvertTime());
|
||||
}
|
||||
//result = unitManager.getConverter().convertStepped(10.763, "ft²", "in²");
|
||||
//xmlDriver.marshal(result, System.out);
|
||||
//System.out.println("");
|
||||
|
||||
System.out.println("");
|
||||
|
||||
result = unitManager.getConverter().convertStepped(10.763, "ft³", "in³");
|
||||
System.out.println("Convert from: "+result.getStartValueType().getName()+" to: "+result.getResultValueType().getName());
|
||||
System.out.println("startValue: "+result.getStartValue());
|
||||
System.out.println("resultValue: "+result.getResultValue());
|
||||
System.out.println("convertTime: "+result.getConvertTime());
|
||||
for (UnitXConverterResultStep step:result.getResultSteps()) {
|
||||
System.out.println("step: "+step.getName()+" in: "+step.getStartValue()+" out: "+step.getResultValue()+" time: "+step.getConvertTime());
|
||||
}
|
||||
//result = unitManager.getConverter().convertStepped(10.763, "ft³", "in³");
|
||||
//xmlDriver.marshal(result, System.out);
|
||||
|
||||
|
||||
result = unitManager.getConverter().convertStepped(1079000000, "km/h", "m/s");
|
||||
System.out.println("Convert from: "+result.getStartValueType().getName()+" to: "+result.getResultValueType().getName());
|
||||
System.out.println("startValue: "+result.getStartValue());
|
||||
System.out.println("resultValue: "+result.getResultValue());
|
||||
System.out.println("convertTime: "+result.getConvertTime());
|
||||
for (UnitXConverterResultStep step:result.getResultSteps()) {
|
||||
System.out.println("step: "+step.getName()+" in: "+step.getStartValue()+" out: "+step.getResultValue()+" time: "+step.getConvertTime());
|
||||
}
|
||||
xmlDriver.marshal(result, System.out);
|
||||
//result = unitManager.getConverter().convertStepped(1079000000, "km/h", "m/s");
|
||||
//xmlDriver.marshal(result, System.out);
|
||||
|
||||
|
||||
//try (OutputStream out = new FileOutputStream("/tmp/unitxc.conf.xml")) {
|
||||
// jaxbDriver.getUnitXCConfig().marshal(unitManager.getConfig(), out);
|
||||
//}
|
||||
|
||||
//System.out.println("GROUP:");
|
||||
//jaxbDriver.getUnitXCGroup().marshal(unitManager.getUnitGroup("length"), System.out);
|
||||
|
||||
Map<String,UnitXConverterParameterValue> para = new HashMap<>();
|
||||
para.put("speed_time", new UnitXConverterParameterValue(2, unitManager.getUnitType("minute")));
|
||||
result = unitManager.getConverter().convertStepped(50, "km/h", "mm",para);
|
||||
System.out.println("CONVERT-RESULT:");
|
||||
jaxbDriver.getUnitXConverterResult().marshal(result, System.out);
|
||||
|
||||
|
||||
Configuration config = new Configuration();
|
||||
|
||||
MappedNamespaceConvention con = new MappedNamespaceConvention(config);
|
||||
Writer writer = new OutputStreamWriter(System.out);
|
||||
|
||||
XMLStreamWriter xmlStreamWriter = new MappedXMLStreamWriter(con, new IndentedJSONWriter(writer));
|
||||
|
||||
//jaxbDriver.getUnitXConverterResult().marshal(result, xmlStreamWriter);
|
||||
}
|
||||
|
||||
class IndentedJSONWriter extends Writer {
|
||||
|
||||
private final Writer writer;
|
||||
private int depth = 0;
|
||||
private boolean firstLine = true;
|
||||
|
||||
public IndentedJSONWriter(Writer writer) {
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
private void writeLineWrap() throws IOException {
|
||||
writer.write(StringUtils.LF);
|
||||
writer.write(StringUtils.repeat(StringUtils.SPACE, depth));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int c) throws IOException {
|
||||
if (c == '{') {
|
||||
if (!firstLine) {
|
||||
writer.write(StringUtils.SPACE);
|
||||
}
|
||||
writer.write(c);
|
||||
depth++;
|
||||
writeLineWrap();
|
||||
} else if (c == '}') {
|
||||
writer.write(c);
|
||||
depth--;
|
||||
writeLineWrap();
|
||||
} else if (c == ',') {
|
||||
writer.write(c);
|
||||
writeLineWrap();
|
||||
} else if (c == '[') {
|
||||
writer.write(StringUtils.SPACE);
|
||||
writer.write(c);
|
||||
writeLineWrap();
|
||||
} else {
|
||||
writer.write(c);
|
||||
}
|
||||
firstLine = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(char[] cbuf, int off, int len) throws IOException {
|
||||
writer.write(cbuf, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package net.forwardfire.unitxc;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.forwardfire.unitxc.config.UnitXCConfig;
|
||||
import net.forwardfire.unitxc.model.UnitXCConfig;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
|
|
|
@ -47,11 +47,6 @@ public class UnitXCManagerTest {
|
|||
assertNotNull(test.getUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID).getTypeFlags());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUnitTypeResultTypeGroupId() {
|
||||
assertNotNull(test.getUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID).getUnitGroupId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUnitTypeGroup() {
|
||||
assertNotNull(test.getUnitGroup(UnitXCModuleTemperature.GROUP_ID));
|
||||
|
@ -107,20 +102,20 @@ public class UnitXCManagerTest {
|
|||
assertTrue(test.isUnitGroup(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsUnitTypeTrue() {
|
||||
assertTrue(test.isUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsUnitTypeFalse() {
|
||||
assertFalse(test.isUnitType(getClass().getName()));
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
public void testIsUnitTypeNull() {
|
||||
assertTrue(test.isUnitType(null));
|
||||
}
|
||||
// @Test
|
||||
// public void testIsUnitTypeTrue() {
|
||||
// assertTrue(test.isUnitType(UnitXCModuleTemperature.TYPE_KELVIN_ID));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testIsUnitTypeFalse() {
|
||||
// assertFalse(test.isUnitType(getClass().getName()));
|
||||
// }
|
||||
//
|
||||
// @Test(expected=NullPointerException.class)
|
||||
// public void testIsUnitTypeNull() {
|
||||
// assertTrue(test.isUnitType(null));
|
||||
// }
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testIsUnitTypeEmpty() {
|
||||
|
|
Loading…
Reference in a new issue