summaryrefslogtreecommitdiff
path: root/src/org/unitConverter/newUnits/LinearUnit.java
diff options
context:
space:
mode:
authorAdrien Hopkins <masterofnumbers17@gmail.com>2019-10-16 14:41:44 -0400
committerAdrien Hopkins <masterofnumbers17@gmail.com>2019-10-16 14:41:44 -0400
commit9eba2e72ecba1f33c73d358eb509f0a0816aa810 (patch)
treeb5ad025a2fb2315b613516cea1fbc3e3ae8ac733 /src/org/unitConverter/newUnits/LinearUnit.java
parent45286c30f96f152f821098d878ede64ecbabe48a (diff)
Added unit prefixes.
Diffstat (limited to 'src/org/unitConverter/newUnits/LinearUnit.java')
-rw-r--r--src/org/unitConverter/newUnits/LinearUnit.java29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/org/unitConverter/newUnits/LinearUnit.java b/src/org/unitConverter/newUnits/LinearUnit.java
index 5a589b7..7600dad 100644
--- a/src/org/unitConverter/newUnits/LinearUnit.java
+++ b/src/org/unitConverter/newUnits/LinearUnit.java
@@ -29,6 +29,21 @@ import org.unitConverter.math.ObjectProduct;
*/
public final class LinearUnit extends AbstractUnit {
/**
+ * Gets a {@code LinearUnit} from a unit and a value. For example, converts '59 °F' to a linear unit with the value
+ * of '288.15 K'
+ *
+ * @param unit
+ * unit to convert
+ * @param value
+ * value to convert
+ * @return value expressed as a {@code LinearUnit}
+ * @since 2019-10-16
+ */
+ public static LinearUnit fromValue(final Unit unit, final double value) {
+ return new LinearUnit(unit.getBase(), unit.convertToBase(value));
+ }
+
+ /**
* Gets a {@code LinearUnit} from a unit base and a conversion factor. In other words, gets the product of
* {@code unitBase} and {@code conversionFactor}, expressed as a {@code LinearUnit}.
*
@@ -129,7 +144,7 @@ public final class LinearUnit extends AbstractUnit {
@Override
public int hashCode() {
- return Objects.hash(this.getBase(), this.getConversionFactor());
+ return 31 * this.getBase().hashCode() + DecimalComparison.hash(this.getConversionFactor());
}
/**
@@ -258,4 +273,16 @@ public final class LinearUnit extends AbstractUnit {
return Double.toString(this.conversionFactor) + " * " + this.getBase().toString(BaseUnit::getSymbol);
}
+ /**
+ * Returns the result of applying {@code prefix} to this unit.
+ *
+ * @param prefix
+ * prefix to apply
+ * @return unit with prefix
+ * @since 2019-03-18
+ * @since v0.2.0
+ */
+ public LinearUnit withPrefix(final UnitPrefix prefix) {
+ return this.times(prefix.getMultiplier());
+ }
}