From df06497dc4d7359de006c5885074f3356dbb81de Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Wed, 16 Oct 2019 16:50:04 -0400 Subject: Added new constructors for BaseUnit and BaseDimension. --- src/org/unitConverter/newUnits/Unit.java | 50 +++++++++++++++++--------------- 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'src/org/unitConverter/newUnits/Unit.java') diff --git a/src/org/unitConverter/newUnits/Unit.java b/src/org/unitConverter/newUnits/Unit.java index feeb25e..339ab95 100644 --- a/src/org/unitConverter/newUnits/Unit.java +++ b/src/org/unitConverter/newUnits/Unit.java @@ -16,6 +16,8 @@ */ package org.unitConverter.newUnits; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; import java.util.function.DoubleUnaryOperator; @@ -62,12 +64,12 @@ public abstract class Unit { */ private final ObjectProduct unitBase; - // /** - // * Cache storing the result of getDimension() - // * - // * @since 2019-10-16 - // */ - // private transient ObjectProduct dimension = null; + /** + * Cache storing the result of getDimension() + * + * @since 2019-10-16 + */ + private transient ObjectProduct dimension = null; /** * A constructor that constructs {@code BaseUnit} instances. @@ -177,24 +179,24 @@ public abstract class Unit { return this.unitBase; } - // /** - // * @return dimension measured by this unit - // * @since 2018-12-22 - // * @since v0.1.0 - // */ - // private final ObjectProduct getDimension() { - // if (this.dimension == null) { - // final Map mapping = this.unitBase.exponentMap(); - // final Map dimensionMap = new HashMap<>(); - // - // for (final BaseUnit key : mapping.keySet()) { - // dimensionMap.put(key.getBaseDimension(), mapping.get(key)); - // } - // - // this.dimension = ObjectProduct.fromExponentMapping(dimensionMap); - // } - // return this.dimension; - // } + /** + * @return dimension measured by this unit + * @since 2018-12-22 + * @since v0.1.0 + */ + public final ObjectProduct getDimension() { + if (this.dimension == null) { + final Map mapping = this.unitBase.exponentMap(); + final Map dimensionMap = new HashMap<>(); + + for (final BaseUnit key : mapping.keySet()) { + dimensionMap.put(key.getBaseDimension(), mapping.get(key)); + } + + this.dimension = ObjectProduct.fromExponentMapping(dimensionMap); + } + return this.dimension; + } @Override public String toString() { -- cgit v1.2.3