summaryrefslogtreecommitdiff
path: root/src/org/unitConverter/newUnits/AbstractUnit.java
diff options
context:
space:
mode:
authorAdrien Hopkins <masterofnumbers17@gmail.com>2019-10-16 15:35:30 -0400
committerAdrien Hopkins <masterofnumbers17@gmail.com>2019-10-16 15:35:30 -0400
commitabe715a30844537693ae186308adcab62c66f121 (patch)
tree1b285a083f91c9db125a6dcc22b6da7a0e9b0d66 /src/org/unitConverter/newUnits/AbstractUnit.java
parent9eba2e72ecba1f33c73d358eb509f0a0816aa810 (diff)
Made Unit an abstract class.
The abstract unit conversion methods are now protected.
Diffstat (limited to 'src/org/unitConverter/newUnits/AbstractUnit.java')
-rw-r--r--src/org/unitConverter/newUnits/AbstractUnit.java81
1 files changed, 0 insertions, 81 deletions
diff --git a/src/org/unitConverter/newUnits/AbstractUnit.java b/src/org/unitConverter/newUnits/AbstractUnit.java
deleted file mode 100644
index bc4608e..0000000
--- a/src/org/unitConverter/newUnits/AbstractUnit.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * Copyright (C) 2019 Adrien Hopkins
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-package org.unitConverter.newUnits;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-import org.unitConverter.dimension.BaseDimension;
-import org.unitConverter.math.ObjectProduct;
-
-/**
- * @author Adrien Hopkins
- * @since 2019-10-16
- */
-public abstract class AbstractUnit implements Unit {
- /**
- * The combination of units that this unit is based on.
- */
- private final ObjectProduct<BaseUnit> unitBase;
-
- /**
- * Cache storing the result of getDimension()
- */
- private transient ObjectProduct<BaseDimension> dimension = null;
-
- /**
- * Creates the {@code AbstractUnit}.
- *
- * @param unitBase
- * @since 2019-10-16
- * @throws NullPointerException
- * if unitBase is null
- */
- public AbstractUnit(final ObjectProduct<BaseUnit> unitBase) {
- this.unitBase = Objects.requireNonNull(unitBase, "unitBase must not be null.");
- }
-
- /**
- * @return unitBase
- * @since 2019-10-16
- */
- @Override
- public final ObjectProduct<BaseUnit> getBase() {
- return this.unitBase;
- }
-
- @Override
- 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() {
- return "Unit derived from base " + this.getBase().toString();
- }
-}