From 0169e644908c4285536d9d23ab82b0a3a46d9d8b Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Sat, 3 Oct 2020 11:40:17 -0500 Subject: Added the MultiUnit --- src/org/unitConverter/unit/UnitlikeValue.java | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/org/unitConverter/unit/UnitlikeValue.java') diff --git a/src/org/unitConverter/unit/UnitlikeValue.java b/src/org/unitConverter/unit/UnitlikeValue.java index 669a123..79201c4 100644 --- a/src/org/unitConverter/unit/UnitlikeValue.java +++ b/src/org/unitConverter/unit/UnitlikeValue.java @@ -22,17 +22,18 @@ import java.util.Optional; * * @since 2020-09-07 */ -final class UnitlikeValue { +final class UnitlikeValue, V> { /** * Gets a {@code UnitlikeValue}. * * @since 2020-10-02 */ - public static UnitlikeValue of(Unitlike unitlike, V value) { + public static , V> UnitlikeValue of(T unitlike, + V value) { return new UnitlikeValue<>(unitlike, value); } - private final Unitlike unitlike; + private final T unitlike; private final V value; /** @@ -40,7 +41,7 @@ final class UnitlikeValue { * @param value * @since 2020-09-07 */ - private UnitlikeValue(Unitlike unitlike, V value) { + private UnitlikeValue(T unitlike, V value) { this.unitlike = unitlike; this.value = value; } @@ -62,14 +63,15 @@ final class UnitlikeValue { } /** - * Returns a UnitValue that represents the same value expressed in a - * different unit + * Returns a UnitlikeValue that represents the same value expressed in a + * different unitlike form. * * @param other new unit to express value in * @return value expressed in {@code other} */ - public final UnitValue convertTo(Unit other) { - return UnitValue.of(other, + public final , W> UnitlikeValue convertTo( + U other) { + return UnitlikeValue.of(other, this.unitlike.convertTo(other, this.getValue())); } @@ -80,8 +82,8 @@ final class UnitlikeValue { * @param other new unit to express value in * @return value expressed in {@code other} */ - public final UnitlikeValue convertTo(Unitlike other) { - return UnitlikeValue.of(other, + public final UnitValue convertTo(Unit other) { + return UnitValue.of(other, this.unitlike.convertTo(other, this.getValue())); } @@ -114,7 +116,7 @@ final class UnitlikeValue { return true; if (!(obj instanceof UnitlikeValue)) return false; - final UnitlikeValue other = (UnitlikeValue) obj; + final UnitlikeValue other = (UnitlikeValue) obj; if (this.getUnitlike() == null) { if (other.getUnitlike() != null) return false; -- cgit v1.2.3