diff options
author | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2024-03-24 13:14:11 -0500 |
---|---|---|
committer | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2024-03-24 13:14:11 -0500 |
commit | 26291e672b0e683edc9d57710a9a9d96ca199c45 (patch) | |
tree | df88f3d3f110e50f38b8a2752d55df4a0c777677 /src/main/java/sevenUnits/unit/Unit.java | |
parent | cc45a65c78c578eb404d8773b22e5b046917621f (diff) |
Format source code & set explicit UTF-8
Diffstat (limited to 'src/main/java/sevenUnits/unit/Unit.java')
-rw-r--r-- | src/main/java/sevenUnits/unit/Unit.java | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/src/main/java/sevenUnits/unit/Unit.java b/src/main/java/sevenUnits/unit/Unit.java index 14478ba..59e928a 100644 --- a/src/main/java/sevenUnits/unit/Unit.java +++ b/src/main/java/sevenUnits/unit/Unit.java @@ -59,7 +59,7 @@ public abstract class Unit implements Nameable { final DoubleUnaryOperator converterTo) { return new FunctionalUnit(base, converterFrom, converterTo); } - + /** * Returns a unit from its base and the functions it uses to convert to and * from its base. @@ -87,28 +87,28 @@ public abstract class Unit implements Nameable { final DoubleUnaryOperator converterTo, final NameSymbol ns) { return new FunctionalUnit(base, converterFrom, converterTo, ns); } - + /** * The combination of units that this unit is based on. * * @since 2019-10-16 */ private final ObjectProduct<BaseUnit> unitBase; - + /** * This unit's name(s) and symbol * * @since 2020-09-07 */ private final NameSymbol nameSymbol; - + /** * Cache storing the result of getDimension() * * @since 2019-10-16 */ private transient ObjectProduct<BaseDimension> dimension = null; - + /** * A constructor that constructs {@code BaseUnit} instances. * @@ -121,7 +121,7 @@ public abstract class Unit implements Nameable { throw new AssertionError(); this.nameSymbol = nameSymbol; } - + /** * Creates the {@code Unit}. * @@ -135,7 +135,7 @@ public abstract class Unit implements Nameable { "unitBase may not be null"); this.nameSymbol = Objects.requireNonNull(ns, "ns may not be null"); } - + /** * @return this unit as a {@link Unitlike} * @since 2020-09-07 @@ -144,7 +144,7 @@ public abstract class Unit implements Nameable { return Unitlike.fromConversionFunctions(this.getBase(), this::convertFromBase, this::convertToBase, this.getNameSymbol()); } - + /** * Checks if a value expressed in this unit can be converted to a value * expressed in {@code other} @@ -159,7 +159,7 @@ public abstract class Unit implements Nameable { Objects.requireNonNull(other, "other must not be null."); return Objects.equals(this.getBase(), other.getBase()); } - + /** * Checks if a value expressed in this unit can be converted to a value * expressed in {@code other} @@ -174,7 +174,7 @@ public abstract class Unit implements Nameable { Objects.requireNonNull(other, "other must not be null."); return Objects.equals(this.getBase(), other.getBase()); } - + /** * Converts from a value expressed in this unit's base unit to a value * expressed in this unit. @@ -190,14 +190,14 @@ 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 <b>base</b> unit * @return value expressed in <b>this</b> unit * @since 2018-12-22 * @since v0.1.0 */ protected abstract double convertFromBase(double value); - + /** * Converts a value expressed in this unit to a value expressed in * {@code other}. @@ -206,7 +206,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 @@ -224,7 +224,7 @@ public abstract class Unit implements Nameable { throw new IllegalArgumentException( String.format("Cannot convert from %s to %s.", this, other)); } - + /** * Converts a value expressed in this unit to a value expressed in * {@code other}. @@ -252,7 +252,7 @@ public abstract class Unit implements Nameable { throw new IllegalArgumentException( String.format("Cannot convert from %s to %s.", this, other)); } - + /** * Converts from a value expressed in this unit to a value expressed in this * unit's base unit. @@ -268,14 +268,14 @@ 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 <b>this</b> unit * @return value expressed in <b>base</b> unit * @since 2018-12-22 * @since v0.1.0 */ protected abstract double convertToBase(double value); - + /** * @return combination of units that this unit is based on * @since 2018-12-22 @@ -284,7 +284,7 @@ public abstract class Unit implements Nameable { public final ObjectProduct<BaseUnit> getBase() { return this.unitBase; } - + /** * @return dimension measured by this unit * @since 2018-12-22 @@ -294,16 +294,16 @@ public abstract class Unit implements Nameable { 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 the nameSymbol * @since 2020-09-07 @@ -312,7 +312,7 @@ public abstract class Unit implements Nameable { public final NameSymbol getNameSymbol() { return this.nameSymbol; } - + /** * Returns true iff this unit is metric. * <p> @@ -337,18 +337,18 @@ public abstract class Unit implements Nameable { if (!(this instanceof LinearUnit)) return false; final LinearUnit linear = (LinearUnit) this; - + // second condition - check that for (final BaseUnit b : linear.getBase().getBaseSet()) { if (!Metric.BaseUnits.BASE_UNITS.contains(b)) return false; } - + // third condition - check that conversion factor is a power of 10 return DecimalComparison .equals(Math.log10(linear.getConversionFactor()) % 1.0, 0); } - + /** * @return a string representing this unit's definition * @since 2022-03-10 @@ -360,7 +360,7 @@ public abstract class Unit implements Nameable { return "derived from " + this.getBase().toString(BaseUnit::getShortName); } - + /** * @return a string containing both this unit's name and its definition * @since 2022-03-10 @@ -368,7 +368,7 @@ public abstract class Unit implements Nameable { public final String toFullString() { return this.toString() + " (" + this.toDefinitionString() + ")"; } - + @Override public String toString() { if (this.nameSymbol.getPrimaryName().isPresent() @@ -378,7 +378,7 @@ public abstract class Unit implements Nameable { else return this.getName(); } - + /** * @param ns name(s) and symbol to use * @return a copy of this unit with provided name(s) and symbol |