From 208c56b56940e58fae1253a8d38e9e56249eb0cb Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Thu, 26 Aug 2021 11:26:02 -0500 Subject: Finished initial draft of design document --- src/main/java/sevenUnits/unit/BaseUnit.java | 2 +- src/main/java/sevenUnits/unit/Unit.java | 38 +++++++++++++---------------- 2 files changed, 18 insertions(+), 22 deletions(-) (limited to 'src/main') diff --git a/src/main/java/sevenUnits/unit/BaseUnit.java b/src/main/java/sevenUnits/unit/BaseUnit.java index b1e30fb..ee2c277 100644 --- a/src/main/java/sevenUnits/unit/BaseUnit.java +++ b/src/main/java/sevenUnits/unit/BaseUnit.java @@ -75,7 +75,7 @@ public final class BaseUnit extends Unit { */ private BaseUnit(final BaseDimension dimension, final String primaryName, final String symbol, final Set otherNames) { - super(primaryName, symbol, otherNames); + super(NameSymbol.of(primaryName, symbol, otherNames)); this.dimension = Objects.requireNonNull(dimension, "dimension must not be null."); } diff --git a/src/main/java/sevenUnits/unit/Unit.java b/src/main/java/sevenUnits/unit/Unit.java index 58b4e10..005b6f7 100644 --- a/src/main/java/sevenUnits/unit/Unit.java +++ b/src/main/java/sevenUnits/unit/Unit.java @@ -17,10 +17,8 @@ package sevenUnits.unit; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.Objects; -import java.util.Set; import java.util.function.DoubleUnaryOperator; import sevenUnits.utils.DecimalComparison; @@ -109,6 +107,19 @@ public abstract class Unit implements Nameable { */ private transient ObjectProduct dimension = null; + /** + * A constructor that constructs {@code BaseUnit} instances. + * + * @since 2019-10-16 + */ + Unit(final NameSymbol nameSymbol) { + if (this instanceof BaseUnit) { + this.unitBase = ObjectProduct.oneOf((BaseUnit) this); + } else + throw new AssertionError(); + this.nameSymbol = nameSymbol; + } + /** * Creates the {@code Unit}. * @@ -123,21 +134,6 @@ public abstract class Unit implements Nameable { this.nameSymbol = Objects.requireNonNull(ns, "ns may not be null"); } - /** - * A constructor that constructs {@code BaseUnit} instances. - * - * @since 2019-10-16 - */ - Unit(final String primaryName, final String symbol, - final Set otherNames) { - if (this instanceof BaseUnit) { - this.unitBase = ObjectProduct.oneOf((BaseUnit) this); - } else - throw new AssertionError(); - this.nameSymbol = NameSymbol.of(primaryName, symbol, - new HashSet<>(otherNames)); - } - /** * @return this unit as a {@link Unitlike} * @since 2020-09-07 @@ -192,7 +188,7 @@ public abstract class Unit implements Nameable { * * @implSpec This method is used by {@link #convertTo}, and its behaviour * affects the behaviour of {@code convertTo}. - * + * * @param value value expressed in base unit * @return value expressed in this unit * @since 2018-12-22 @@ -208,7 +204,7 @@ public abstract class Unit implements Nameable { * {@code other.convertFromBase(this.convertToBase(value))}. * Therefore, overriding either of those methods will change the * output of this method. - * + * * @param other unit to convert to * @param value value to convert * @return converted value @@ -235,7 +231,7 @@ public abstract class Unit implements Nameable { * {@code other.convertFromBase(this.convertToBase(value))}. * Therefore, overriding either of those methods will change the * output of this method. - * + * * @param other unitlike form to convert to * @param value value to convert * @param type of value to convert to @@ -270,7 +266,7 @@ public abstract class Unit implements Nameable { * * @implSpec This method is used by {@link #convertTo}, and its behaviour * affects the behaviour of {@code convertTo}. - * + * * @param value value expressed in this unit * @return value expressed in base unit * @since 2018-12-22 -- cgit v1.2.3