diff options
author | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2019-04-13 15:55:49 -0400 |
---|---|---|
committer | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2019-04-13 15:55:49 -0400 |
commit | f0f4898f796b9cc26294ba9feb22692143d00a9e (patch) | |
tree | e54c5a53e5ad1786dadab650ceea6efa83522a9e /src/org/unitConverter/unit/UnitPrefix.java | |
parent | e0c5021a9ba85debf0c0722d78f75a0dbcc8376b (diff) |
Unit prefixes now have math methods, and use the expression parser.
Diffstat (limited to 'src/org/unitConverter/unit/UnitPrefix.java')
-rwxr-xr-x | src/org/unitConverter/unit/UnitPrefix.java | 36 |
1 files changed, 36 insertions, 0 deletions
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 @@ -25,9 +25,45 @@ package org.unitConverter.unit; */ 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)); + } } |