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