diff options
author | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2019-03-22 17:00:58 -0400 |
---|---|---|
committer | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2019-03-22 17:00:58 -0400 |
commit | 943496888d18b031be19ba8e7348ec188dc8eb6b (patch) | |
tree | 03b440bf7d7789be5fd88b8ce3785f900804c773 /src/org/unitConverter/UnitsDatabase.java | |
parent | ea940f2c5b6450231ff9ce61f4b6704babdb0d9e (diff) |
Made BaseUnit a subclass of LinearUnit and made an expression parser
Diffstat (limited to 'src/org/unitConverter/UnitsDatabase.java')
-rwxr-xr-x | src/org/unitConverter/UnitsDatabase.java | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/src/org/unitConverter/UnitsDatabase.java b/src/org/unitConverter/UnitsDatabase.java index 4d41735..3af1c8d 100755 --- a/src/org/unitConverter/UnitsDatabase.java +++ b/src/org/unitConverter/UnitsDatabase.java @@ -393,8 +393,6 @@ public final class UnitsDatabase { final Unit unit = this.getUnit(baseAndExponent[0]); if (unit instanceof LinearUnit) { base = (LinearUnit) unit; - } else if (unit instanceof BaseUnit) { - base = ((BaseUnit) unit).asLinearUnit(); } else throw new IllegalArgumentException("Base of exponientation must be a linear or base unit."); } @@ -464,7 +462,7 @@ public final class UnitsDatabase { // parse the expression // start with an "empty" unit then apply operations on it - LinearUnit unit = SI.SI.getBaseUnit(UnitDimension.EMPTY).asLinearUnit(); + LinearUnit unit = SI.SI.getBaseUnit(UnitDimension.EMPTY); boolean dividing = false; // if I'm just creating an alias, just create one instead of going through the parsing process @@ -567,8 +565,6 @@ public final class UnitsDatabase { // try to turn the value into a linear unit if (valueUnit instanceof LinearUnit) { value = (LinearUnit) valueUnit; - } else if (valueUnit instanceof BaseUnit) { - value = ((BaseUnit) valueUnit).asLinearUnit(); } else throw new IllegalArgumentException("Only linear and base units can be exponientated."); } @@ -594,10 +590,7 @@ public final class UnitsDatabase { // the unitsfile is looking for a linear unit if (!this.containsUnitName(part)) throw new IllegalArgumentException("Unrecognized unit name \"" + part + "\"."); - Unit other = this.getUnit(part); - if (other instanceof BaseUnit) { - other = ((BaseUnit) other).asLinearUnit(); - } + final Unit other = this.getUnit(part); if (other instanceof LinearUnit) { if (dividing) { unit = unit.dividedBy((LinearUnit) other); |