From e86fb71e1665cb9e8511bafd54df0fb8cbca5adc Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Fri, 30 May 2025 19:48:42 -0500 Subject: Remove Unitlike/MultiUnit I ended up never using this code - it was simpler to just use lists of units and values. Making a whole new object for lists of units, and an abstract class for things that convert things other than doubles, is needlessly complicated, and doesn't solve any major issues. For example, I still need to store each Unitlike type in a different collection, because it will have a different type. --- src/main/java/sevenUnits/unit/Unit.java | 52 --------------------------------- 1 file changed, 52 deletions(-) (limited to 'src/main/java/sevenUnits/unit/Unit.java') diff --git a/src/main/java/sevenUnits/unit/Unit.java b/src/main/java/sevenUnits/unit/Unit.java index 59e928a..d25b362 100644 --- a/src/main/java/sevenUnits/unit/Unit.java +++ b/src/main/java/sevenUnits/unit/Unit.java @@ -136,15 +136,6 @@ public abstract class Unit implements Nameable { this.nameSymbol = Objects.requireNonNull(ns, "ns may not be null"); } - /** - * @return this unit as a {@link Unitlike} - * @since 2020-09-07 - */ - public final Unitlike asUnitlike() { - 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} @@ -160,21 +151,6 @@ public abstract class Unit implements Nameable { 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} - * - * @param other unit or unitlike form to test with - * @return true if they are compatible - * @since 2019-01-13 - * @since v0.1.0 - * @throws NullPointerException if other is null - */ - public final boolean canConvertTo(final Unitlike other) { - 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. @@ -225,34 +201,6 @@ public abstract class Unit implements Nameable { String.format("Cannot convert from %s to %s.", this, other)); } - /** - * Converts a value expressed in this unit to a value expressed in - * {@code other}. - * - * @implSpec If conversion is possible, this implementation returns - * {@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 - * @return converted value - * @since 2020-09-07 - * @throws IllegalArgumentException if {@code other} is incompatible for - * conversion with this unit (as tested by - * {@link Unit#canConvertTo}). - * @throws NullPointerException if other is null - */ - public final W convertTo(final Unitlike other, final double value) { - Objects.requireNonNull(other, "other must not be null."); - if (this.canConvertTo(other)) - return other.convertFromBase(this.convertToBase(value)); - else - 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. -- cgit v1.2.3