summaryrefslogtreecommitdiff
path: root/src/unitConverter/unit/LinearUnit.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/unitConverter/unit/LinearUnit.java')
-rw-r--r--src/unitConverter/unit/LinearUnit.java72
1 files changed, 71 insertions, 1 deletions
diff --git a/src/unitConverter/unit/LinearUnit.java b/src/unitConverter/unit/LinearUnit.java
index 229710c..e2c9eb2 100644
--- a/src/unitConverter/unit/LinearUnit.java
+++ b/src/unitConverter/unit/LinearUnit.java
@@ -16,6 +16,8 @@
*/
package unitConverter.unit;
+import java.util.Objects;
+
import unitConverter.dimension.UnitDimension;
/**
@@ -24,7 +26,7 @@ import unitConverter.dimension.UnitDimension;
* @author Adrien Hopkins
* @since 2019-01-25
*/
-public class LinearUnit extends AbstractUnit {
+public final class LinearUnit extends AbstractUnit {
/**
* The value of one of this unit in this unit's base unit
*
@@ -72,6 +74,34 @@ public class LinearUnit extends AbstractUnit {
}
/**
+ * Divides this unit by a scalar.
+ *
+ * @param divisor
+ * scalar to divide by
+ * @return quotient
+ * @since 2018-12-23
+ */
+ public LinearUnit dividedBy(final double divisor) {
+ return new LinearUnit(this.getBase(), this.getConversionFactor() / divisor);
+ }
+
+ /**
+ * Divides this unit by another unit.
+ *
+ * @param other
+ * unit to divide by
+ * @return quotient of two units
+ * @throws NullPointerException
+ * if other is null
+ * @since 2018-12-22
+ */
+ public LinearUnit dividedBy(final LinearUnit other) {
+ Objects.requireNonNull(other, "other must not be null");
+ final BaseUnit base = this.getBase().dividedBy(other.getBase());
+ return new LinearUnit(base, this.getConversionFactor() / other.getConversionFactor());
+ }
+
+ /**
* @return conversionFactor
* @since 2019-01-25
*/
@@ -79,6 +109,46 @@ public class LinearUnit extends AbstractUnit {
return this.conversionFactor;
}
+ /**
+ * Multiplies this unit by a scalar.
+ *
+ * @param multiplier
+ * scalar to multiply by
+ * @return product
+ * @since 2018-12-23
+ */
+ public LinearUnit times(final double multiplier) {
+ return new LinearUnit(this.getBase(), this.getConversionFactor() * multiplier);
+ }
+
+ /**
+ * Multiplies this unit by another unit.
+ *
+ * @param other
+ * unit to multiply by=
+ * @return product of two units
+ * @throws NullPointerException
+ * if other is null
+ * @since 2018-12-22
+ */
+ public LinearUnit times(final LinearUnit other) {
+ Objects.requireNonNull(other, "other must not be null");
+ final BaseUnit base = this.getBase().times(other.getBase());
+ return new LinearUnit(base, this.getConversionFactor() * other.getConversionFactor());
+ }
+
+ /**
+ * Returns this unit but to an exponent.
+ *
+ * @param exponent
+ * exponent to exponientate unit to
+ * @return exponientated unit
+ * @since 2019-01-15
+ */
+ public LinearUnit toExponent(final int exponent) {
+ return new LinearUnit(this.getBase().toExponent(exponent), Math.pow(this.conversionFactor, exponent));
+ }
+
@Override
public String toString() {
return super.toString() + String.format(" (equal to %s * base)", this.getConversionFactor());