First raw version with unit types on request.

This commit is contained in:
Willem 2016-10-24 17:00:32 +02:00
parent 01cdb0b478
commit aed5d0d03a
16 changed files with 0 additions and 484 deletions

View file

@ -1,85 +0,0 @@
/*
* Copyright (c) 2013-2015, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.unitxc.config;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.Validate;
import net.forwardfire.unitxc.model.UnitXCType;
import net.forwardfire.unitxc.model.UnitXCGroup;
/**
* Config to build unit types and groups.
*
* @author Willem Cazander
* @version 1.0 Oct 17, 2015
*/
public final class UnitXCConfig {
private final Map<String,UnitXCType> unitTypes;
private final Map<String,UnitXCGroup> unitGroups;
public UnitXCConfig() {
unitGroups = new HashMap<>();
unitTypes = new HashMap<>();
}
/**
* @return the unitTypes
*/
public Collection<UnitXCType> getUnitTypes() {
return unitTypes.values();
}
public void addUnitType(UnitXCType unitType) {
putUnitType(validateGroupId(Validate.notNull(unitType).validate()));
}
private UnitXCType validateGroupId(UnitXCType unitType) {
//Validate.isTrue(unitTypeGroups.containsKey(unitType.getTypeGroupId()),"group is missing");
return unitType;
}
private void putUnitType(UnitXCType unitType) {
unitTypes.put(unitType.getId(), unitType);
}
/**
* @return the unitGroups
*/
public Collection<UnitXCGroup> getUnitroups() {
return unitGroups.values();
}
public void addUnitGroup(UnitXCGroup unitTypeGroup) {
putUnitGroup(Validate.notNull(unitTypeGroup).validate());
}
private void putUnitGroup(UnitXCGroup unitTypeGroup) {
unitGroups.put(unitTypeGroup.getId(),unitTypeGroup);
}
}

View file

@ -1,80 +0,0 @@
/*
* Copyright (c) 2013-2015, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.unitxc.converter.step;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.commons.lang3.Validate;
/**
*
*
* @author Willem Cazander
* @version 1.0 Oct 20, 2015
*/
@XmlRootElement
public class UnitXCTypeDevideConverterStep extends AbstractUnitXConverterStep {
private final static String STEP_NAME = "Devide";
private double factor;
public UnitXCTypeDevideConverterStep() {
super(STEP_NAME);
}
public UnitXCTypeDevideConverterStep(double factor) {
this();
setFactor(factor);
}
@Override
protected AbstractUnitXConverterStep createClone() {
return new UnitXCTypeDevideConverterStep(getFactor());
}
@Override
public double convert(double value) {
return value/factor;
}
@Override
protected String toMath() {
return "/"+factor;
}
/**
* @return the factor
*/
public double getFactor() {
return factor;
}
/**
* @param factor the factor to set
*/
public void setFactor(double factor) {
Validate.isTrue(factor != 0);
this.factor = factor;
}
}

View file

@ -1,111 +0,0 @@
/*
* Copyright (c) 2013-2015, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.unitxc.converter.step;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.math.Fraction;
/**
*
*
* @author Willem Cazander
* @version 1.0 Oct 20, 2015
*/
@XmlRootElement
public class UnitXCTypeMultiplyFractionConverterStep extends AbstractUnitXConverterStep {
private final static String STEP_NAME = "MultiplyFaction";
//private Fraction fraction;
//private final String fractionMath;
private int numerator;
private int denominator;
public UnitXCTypeMultiplyFractionConverterStep() {
super(STEP_NAME);
}
public UnitXCTypeMultiplyFractionConverterStep(int numerator,int denominator) {
this();
setNumerator(numerator);
setDenominator(denominator);
}
@Override
protected AbstractUnitXConverterStep createClone() {
return new UnitXCTypeMultiplyFractionConverterStep(getNumerator(),getDenominator());
}
/*
public UnitXCTypeMultiplyFractionConverterStep(int numerator,int denominator,String stepReason) {
this(Fraction.getFraction(numerator, denominator),stepReason);
}
public UnitXCTypeMultiplyFractionConverterStep(Fraction fraction,String stepReason) {
super(STEP_NAME,stepReason);
this.fraction = Validate.notNull(fraction);
this.fractionMath = String.format("*(%1s/%2s)", fraction.getNumerator(),fraction.getDenominator());
}
*/
@Override
public double convert(double value) {
//return value*fraction.doubleValue();
return value*(numerator/denominator);
}
@Override
protected String toMath() {
//return String.format("*(%1s/%2s)", fraction.getNumerator(),fraction.getDenominator());
return String.format("*(%1s/%2s)", numerator,denominator);
}
/**
* @return the numerator
*/
public int getNumerator() {
return numerator;
}
/**
* @param numerator the numerator to set
*/
public void setNumerator(int numerator) {
this.numerator = numerator;
}
/**
* @return the denominator
*/
public int getDenominator() {
return denominator;
}
/**
* @param denominator the denominator to set
*/
public void setDenominator(int denominator) {
this.denominator = denominator;
}
}

View file

@ -1,104 +0,0 @@
/*
* Copyright (c) 2013-2015, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.unitxc.converter.step;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
*
* @author Willem Cazander
* @version 1.0 Oct 17, 2015
*/
@XmlRootElement
public class UnitXCTypeOffsetConverterStep extends AbstractUnitXConverterStep {
private final static String STEP_NAME = "Offset";
private double offset;
private boolean offsetPositive;
public UnitXCTypeOffsetConverterStep() {
super(STEP_NAME);
}
public UnitXCTypeOffsetConverterStep(double offset,boolean offsetPositive) {
this();
setOffset(offset);
setOffsetPositive(offsetPositive);
}
@Override
protected AbstractUnitXConverterStep createClone() {
return new UnitXCTypeOffsetConverterStep(getOffset(),isOffsetPositive());
}
@Override
public double convert(double value) {
if (offsetPositive) {
return value+offset;
} else {
return value-offset;
}
}
@Override
protected String toMath() {
if (offsetPositive) {
return "+"+offset;
} else {
return "-"+offset;
}
}
/**
* @return the offset
*/
public double getOffset() {
return offset;
}
/**
* @param offset the offset to set
*/
public void setOffset(double offset) {
this.offset = offset;
}
/**
* @return the offsetPositive
*/
public boolean isOffsetPositive() {
return offsetPositive;
}
/**
* @param offsetPositive the offsetPositive to set
*/
public void setOffsetPositive(boolean offsetPositive) {
this.offsetPositive = offsetPositive;
}
}

View file

@ -1,77 +0,0 @@
/*
* Copyright (c) 2013-2015, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.unitxc.converter.step;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
*
* @author Willem Cazander
* @version 1.0 Oct 26, 2015
*/
@XmlRootElement
public class UnitXCTypePowerConverterStep extends AbstractUnitXConverterStep {
private final static String STEP_NAME = "power";
private int exponent;
public UnitXCTypePowerConverterStep() {
super(STEP_NAME);
}
public UnitXCTypePowerConverterStep(int exponent) {
this();
setExponent(exponent);
}
@Override
protected AbstractUnitXConverterStep createClone() {
return new UnitXCTypePowerConverterStep(getExponent());
}
@Override
public double convert(double value) {
return Math.pow(value, exponent);
}
@Override
protected String toMath() {
return "/"+exponent;
}
/**
* @return the exponent
*/
public int getExponent() {
return exponent;
}
/**
* @param exponent the exponent to set
*/
public void setExponent(int exponent) {
this.exponent = exponent;
}
}

View file

@ -1,27 +0,0 @@
/*
* Copyright (c) 2013-2015, Willem Cazander
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author willemc
*
*/
package net.forwardfire.unitxc.converter.step;