diff options
Diffstat (limited to 'src/org/unitConverter/newUnits/LinearUnit.java')
-rw-r--r-- | src/org/unitConverter/newUnits/LinearUnit.java | 29 |
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()); + } } |