From f0f4898f796b9cc26294ba9feb22692143d00a9e Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Sat, 13 Apr 2019 15:55:49 -0400 Subject: Unit prefixes now have math methods, and use the expression parser. --- src/org/unitConverter/unit/UnitPrefix.java | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/org/unitConverter/unit/UnitPrefix.java') diff --git a/src/org/unitConverter/unit/UnitPrefix.java b/src/org/unitConverter/unit/UnitPrefix.java index 289e60f..a1609c6 100755 --- a/src/org/unitConverter/unit/UnitPrefix.java +++ b/src/org/unitConverter/unit/UnitPrefix.java @@ -24,10 +24,46 @@ package org.unitConverter.unit; * @since v0.1.0 */ public interface UnitPrefix { + /** + * Divides this prefix by {@code other}. + * + * @param other + * prefix to divide by + * @return quotient of prefixes + * @since 2019-04-13 + */ + default UnitPrefix dividedBy(final UnitPrefix other) { + return new DefaultUnitPrefix(this.getMultiplier() / other.getMultiplier()); + } + /** * @return this prefix's multiplier * @since 2019-01-14 * @since v0.1.0 */ double getMultiplier(); + + /** + * Multiplies this prefix by {@code other}. + * + * @param other + * prefix to multiply by + * @return product of prefixes + * @since 2019-04-13 + */ + default UnitPrefix times(final UnitPrefix other) { + return new DefaultUnitPrefix(this.getMultiplier() * other.getMultiplier()); + } + + /** + * Raises this prefix to an exponent. + * + * @param exponent + * exponent to raise to + * @return result of exponentiation. + * @since 2019-04-13 + */ + default UnitPrefix toExponent(final double exponent) { + return new DefaultUnitPrefix(Math.pow(getMultiplier(), exponent)); + } } -- cgit v1.2.3