From da01eec8c59477da649767f3ed72c98fe1bbb301 Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Sat, 26 Jan 2019 14:07:29 -0500 Subject: Added more @since tags, edited some documentation There is now a @since tag for version as well as date. --- src/unitConverter/unit/BaseUnit.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/unitConverter/unit/BaseUnit.java') diff --git a/src/unitConverter/unit/BaseUnit.java b/src/unitConverter/unit/BaseUnit.java index 204b1cd..d4a1e9c 100755 --- a/src/unitConverter/unit/BaseUnit.java +++ b/src/unitConverter/unit/BaseUnit.java @@ -26,12 +26,14 @@ import unitConverter.dimension.UnitDimension; * * @author Adrien Hopkins * @since 2018-12-23 + * @since v0.1.0 */ public final class BaseUnit extends AbstractUnit { /** * Is this unit a full base (i.e. m, s, ... but not N, J, ...) * * @since 2019-01-15 + * @since v0.1.0 */ private final boolean isFullBase; @@ -47,6 +49,7 @@ public final class BaseUnit extends AbstractUnit { * @param symbol * symbol of unit * @since 2018-12-23 + * @since v0.1.0 */ BaseUnit(final UnitDimension dimension, final UnitSystem system) { super(dimension, system); @@ -56,6 +59,7 @@ public final class BaseUnit extends AbstractUnit { /** * @return this unit as a {@code LinearUnit} * @since 2019-01-25 + * @since v0.1.0 */ public LinearUnit asLinearUnit() { return this.times(1); @@ -82,6 +86,7 @@ public final class BaseUnit extends AbstractUnit { * @throws NullPointerException * if other is null * @since 2018-12-22 + * @since v0.1.0 */ public BaseUnit dividedBy(final BaseUnit other) { Objects.requireNonNull(other, "other must not be null."); @@ -97,6 +102,7 @@ public final class BaseUnit extends AbstractUnit { * amount to divide by * @return quotient * @since 2018-12-23 + * @since v0.1.0 */ public LinearUnit dividedBy(final double divisor) { return new LinearUnit(this, 1 / divisor); @@ -113,6 +119,7 @@ public final class BaseUnit extends AbstractUnit { * @throws NullPointerException * if other is null * @since 2018-12-22 + * @since v0.1.0 */ public BaseUnit times(final BaseUnit other) { Objects.requireNonNull(other, "other must not be null."); @@ -127,7 +134,8 @@ public final class BaseUnit extends AbstractUnit { * @param multiplier * amount to multiply by * @return product - * @since 2018-12-23B + * @since 2018-12-23 + * @since v0.1.0 */ public LinearUnit times(final double multiplier) { return new LinearUnit(this, multiplier); @@ -140,6 +148,7 @@ public final class BaseUnit extends AbstractUnit { * exponent * @return result of exponentiation * @since 2019-01-15 + * @since v0.1.0 */ public BaseUnit toExponent(final int exponent) { return this.getSystem().getBaseUnit(this.getDimension().toExponent(exponent)); -- cgit v1.2.3 From a6a66e6fb11675e0ea738ad8d0b5a9ba7d2fac2b Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Sun, 27 Jan 2019 16:05:55 -0500 Subject: HOTFIX: Added equals and hashCode to the unit classes --- src/unitConverter/unit/BaseUnit.java | 18 ++++++++++++++++++ src/unitConverter/unit/LinearUnit.java | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'src/unitConverter/unit/BaseUnit.java') diff --git a/src/unitConverter/unit/BaseUnit.java b/src/unitConverter/unit/BaseUnit.java index d4a1e9c..fe36c45 100755 --- a/src/unitConverter/unit/BaseUnit.java +++ b/src/unitConverter/unit/BaseUnit.java @@ -108,6 +108,24 @@ public final class BaseUnit extends AbstractUnit { return new LinearUnit(this, 1 / divisor); } + @Override + public boolean equals(final Object obj) { + if (!(obj instanceof BaseUnit)) + return false; + final BaseUnit other = (BaseUnit) obj; + return Objects.equals(this.getSystem(), other.getSystem()) + && Objects.equals(this.getDimension(), other.getDimension()); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = result * prime + this.getSystem().hashCode(); + result = result * prime + this.getDimension().hashCode(); + return result; + } + /** * Multiplies this unit by another unit. * diff --git a/src/unitConverter/unit/LinearUnit.java b/src/unitConverter/unit/LinearUnit.java index 6514ff4..b786b3b 100644 --- a/src/unitConverter/unit/LinearUnit.java +++ b/src/unitConverter/unit/LinearUnit.java @@ -107,6 +107,15 @@ public final class LinearUnit extends AbstractUnit { return new LinearUnit(base, this.getConversionFactor() / other.getConversionFactor()); } + @Override + public boolean equals(final Object obj) { + if (!(obj instanceof LinearUnit)) + return false; + final LinearUnit other = (LinearUnit) obj; + return Objects.equals(this.getBase(), other.getBase()) + && Objects.equals(this.getConversionFactor(), other.getConversionFactor()); + } + /** * @return conversionFactor * @since 2018-12-22 @@ -116,6 +125,15 @@ public final class LinearUnit extends AbstractUnit { return this.conversionFactor; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = result * prime + this.getBase().hashCode(); + result = result * prime + Double.hashCode(this.getConversionFactor()); + return result; + } + /** * Multiplies this unit by a scalar. * -- cgit v1.2.3