diff options
author | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2020-10-03 11:40:17 -0500 |
---|---|---|
committer | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2020-10-03 11:40:17 -0500 |
commit | 0169e644908c4285536d9d23ab82b0a3a46d9d8b (patch) | |
tree | a921546e3bf022fdc6cc47a2123cfc367fd46557 /src/org/unitConverter/unit/UnitlikeValue.java | |
parent | cd33f886dfbd35c0ee3d8cf5b553ea3481b0b3a1 (diff) |
Added the MultiUnit
Diffstat (limited to 'src/org/unitConverter/unit/UnitlikeValue.java')
-rw-r--r-- | src/org/unitConverter/unit/UnitlikeValue.java | 24 |
1 files changed, 13 insertions, 11 deletions
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<V> { +final class UnitlikeValue<T extends Unitlike<V>, V> { /** * Gets a {@code UnitlikeValue<V>}. * * @since 2020-10-02 */ - public static <V> UnitlikeValue<V> of(Unitlike<V> unitlike, V value) { + public static <T extends Unitlike<V>, V> UnitlikeValue<T, V> of(T unitlike, + V value) { return new UnitlikeValue<>(unitlike, value); } - private final Unitlike<V> unitlike; + private final T unitlike; private final V value; /** @@ -40,7 +41,7 @@ final class UnitlikeValue<V> { * @param value * @since 2020-09-07 */ - private UnitlikeValue(Unitlike<V> unitlike, V value) { + private UnitlikeValue(T unitlike, V value) { this.unitlike = unitlike; this.value = value; } @@ -62,14 +63,15 @@ final class UnitlikeValue<V> { } /** - * 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 <U extends Unitlike<W>, W> UnitlikeValue<U, W> convertTo( + U other) { + return UnitlikeValue.of(other, this.unitlike.convertTo(other, this.getValue())); } @@ -80,8 +82,8 @@ final class UnitlikeValue<V> { * @param other new unit to express value in * @return value expressed in {@code other} */ - public final <W> UnitlikeValue<W> convertTo(Unitlike<W> 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<V> { 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; |