summaryrefslogtreecommitdiff
path: root/src/org/unitConverter/newUnits/Unit.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/unitConverter/newUnits/Unit.java')
-rw-r--r--src/org/unitConverter/newUnits/Unit.java50
1 files changed, 26 insertions, 24 deletions
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<BaseUnit> unitBase;
- // /**
- // * Cache storing the result of getDimension()
- // *
- // * @since 2019-10-16
- // */
- // private transient ObjectProduct<BaseDimension> dimension = null;
+ /**
+ * Cache storing the result of getDimension()
+ *
+ * @since 2019-10-16
+ */
+ private transient ObjectProduct<BaseDimension> 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<BaseDimension> getDimension() {
- // if (this.dimension == null) {
- // final Map<BaseUnit, Integer> mapping = this.unitBase.exponentMap();
- // final Map<BaseDimension, Integer> 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<BaseDimension> getDimension() {
+ if (this.dimension == null) {
+ final Map<BaseUnit, Integer> mapping = this.unitBase.exponentMap();
+ final Map<BaseDimension, Integer> 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() {