Improve formatting

Remove trailing whitespace. Replace tabs with spaces.

Refs #345
This commit is contained in:
Derek Bankieris 2016-11-04 15:48:29 -05:00
parent 245389182d
commit de69363cbd

View File

@ -1,7 +1,3 @@
//========================================
// Package
//========================================
package trick.common.utils;
import java.util.ArrayList;
@ -209,17 +205,17 @@ public enum UnitType {
* @throws IllegalUnitConversionException IllegalUnitConversionException
*/
public static double convertUnits(double fromValue, String fromUnitStr, String toUnitStr) throws IllegalUnitConversionException {
Unit fromUnit = getExpressionUnit(fromUnitStr);
Unit toUnit = getExpressionUnit(toUnitStr);
Unit fromUnit = getExpressionUnit(fromUnitStr);
Unit toUnit = getExpressionUnit(toUnitStr);
if (!isConvertible(fromUnitStr, toUnitStr)) {
throw new IllegalUnitConversionException(fromUnitStr, toUnitStr);
}
if (!isConvertible(fromUnitStr, toUnitStr)) {
throw new IllegalUnitConversionException(fromUnitStr, toUnitStr);
}
double derivedFactor1 = fromUnit.factor1 - toUnit.factor1 / toUnit.factor2;
double derivedFactor2 = fromUnit.factor2 / toUnit.factor2;
double derivedFactor1 = fromUnit.factor1 - toUnit.factor1 / toUnit.factor2;
double derivedFactor2 = fromUnit.factor2 / toUnit.factor2;
return (fromValue * derivedFactor2 + derivedFactor1);
return (fromValue * derivedFactor2 + derivedFactor1);
}
/**
@ -249,36 +245,36 @@ public enum UnitType {
* @return an instance of {@link Unit}
*/
public static Unit getExpressionUnit(String expression) {
Unit ret = null;
Unit ret = null;
ret = getPrimitiveUnit(expression);
if (ret != null) {
return ret;
}
ret = getPrimitiveUnit(expression);
if (ret != null) {
return ret;
}
UnitInfixExpression unitExpression = new UnitInfixExpression(expression);
UnitInfixExpression unitExpression = new UnitInfixExpression(expression);
ret = unitExpression.getUnit();
ret = unitExpression.getUnit();
return ret;
return ret;
}
/**
* Gets the {@link Unit} based on its abbreviation.
*
* @param abbreviation the units abbreviation.
* @param abbreviation the units abbreviation.
* @return the corresponding Unit, or null if the abbreviation doesn't exist.
*/
public static Unit getPrimitiveUnit(String abbreviation) {
Unit ret = null;
for (UnitType type : UnitType.values()) {
Unit ret = null;
for (UnitType type : UnitType.values()) {
for (Unit unit : type.getAll()) {
if (unit.abbreviation.equals(abbreviation)) {
ret = unit;
}
}
}
return ret;
return ret;
}
/**
@ -362,9 +358,9 @@ public enum UnitType {
final boolean isPrefixable;
public Unit(String name, String abbreviation, boolean isPrefixable, double factor1, double factor2) {
this(name, abbreviation, isPrefixable);
this.factor1 = factor1;
this.factor2 = factor2;
this(name, abbreviation, isPrefixable);
this.factor1 = factor1;
this.factor2 = factor2;
}
/** constructor
@ -384,16 +380,13 @@ public enum UnitType {
}
}
/**
* Exception for handling illegal unit conversion.
*/
public static class IllegalUnitConversionException extends Exception {
private static final long serialVersionUID = 2800176399857985431L;
private static final long serialVersionUID = 2800176399857985431L;
public IllegalUnitConversionException(String fromUnit, String toUnit) {
super("Illegal Unit Conversion", new Throwable("Can't convert " + fromUnit + " -> " + toUnit));
}
public IllegalUnitConversionException(String fromUnit, String toUnit) {
super("Illegal Unit Conversion", new Throwable("Can't convert " + fromUnit + " -> " + toUnit));
}
}
}