summaryrefslogtreecommitdiff
path: root/src/org/unitConverter/unit/LinearUnit.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/unitConverter/unit/LinearUnit.java')
-rw-r--r--src/org/unitConverter/unit/LinearUnit.java27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/org/unitConverter/unit/LinearUnit.java b/src/org/unitConverter/unit/LinearUnit.java
index 7b7338b..1532fc4 100644
--- a/src/org/unitConverter/unit/LinearUnit.java
+++ b/src/org/unitConverter/unit/LinearUnit.java
@@ -128,11 +128,21 @@ public final class LinearUnit extends Unit {
this.conversionFactor = conversionFactor;
}
+ /**
+ * {@inheritDoc}
+ *
+ * Converts by dividing by {@code conversionFactor}
+ */
@Override
protected double convertFromBase(final double value) {
return value / this.getConversionFactor();
}
+ /**
+ * {@inheritDoc}
+ *
+ * Converts by multiplying by {@code conversionFactor}
+ */
@Override
protected double convertToBase(final double value) {
return value * this.getConversionFactor();
@@ -170,6 +180,11 @@ public final class LinearUnit extends Unit {
return valueOf(base, this.getConversionFactor() / divisor.getConversionFactor());
}
+ /**
+ * {@inheritDoc}
+ *
+ * Uses the base and conversion factor of units to test for equality.
+ */
@Override
public boolean equals(final Object obj) {
if (!(obj instanceof LinearUnit))
@@ -187,6 +202,11 @@ public final class LinearUnit extends Unit {
return this.conversionFactor;
}
+ /**
+ * {@inheritDoc}
+ *
+ * Uses the base and conversion factor to compute a hash code.
+ */
@Override
public int hashCode() {
return 31 * this.getBase().hashCode() + DecimalComparison.hash(this.getConversionFactor());
@@ -234,7 +254,7 @@ public final class LinearUnit extends Unit {
throw new IllegalArgumentException(
String.format("Incompatible units for subtraction \"%s\" and \"%s\".", this, subtrahendend));
- // add the units
+ // subtract the units
return valueOf(this.getBase(), this.getConversionFactor() - subtrahendend.getConversionFactor());
}
@@ -312,7 +332,10 @@ public final class LinearUnit extends Unit {
return valueOf(this.getBase().toExponent(exponent), Math.pow(this.conversionFactor, exponent));
}
- // returns a definition of the unit
+ /**
+ * @return a string providing a definition of this unit
+ * @since 2019-10-21
+ */
@Override
public String toString() {
return this.getPrimaryName().orElse("Unnamed unit")