summaryrefslogtreecommitdiff
path: root/src/main/java/sevenUnits/unit/LinearUnit.java
diff options
context:
space:
mode:
authorAdrien Hopkins <adrien.p.hopkins@gmail.com>2024-03-24 13:14:11 -0500
committerAdrien Hopkins <adrien.p.hopkins@gmail.com>2024-03-24 13:14:11 -0500
commit26291e672b0e683edc9d57710a9a9d96ca199c45 (patch)
treedf88f3d3f110e50f38b8a2752d55df4a0c777677 /src/main/java/sevenUnits/unit/LinearUnit.java
parentcc45a65c78c578eb404d8773b22e5b046917621f (diff)
Format source code & set explicit UTF-8
Diffstat (limited to 'src/main/java/sevenUnits/unit/LinearUnit.java')
-rw-r--r--src/main/java/sevenUnits/unit/LinearUnit.java72
1 files changed, 36 insertions, 36 deletions
diff --git a/src/main/java/sevenUnits/unit/LinearUnit.java b/src/main/java/sevenUnits/unit/LinearUnit.java
index 103b7f6..6489229 100644
--- a/src/main/java/sevenUnits/unit/LinearUnit.java
+++ b/src/main/java/sevenUnits/unit/LinearUnit.java
@@ -46,7 +46,7 @@ public final class LinearUnit extends Unit {
Objects.requireNonNull(unit, "unit must not be null.").getBase(),
unit.convertToBase(value), NameSymbol.EMPTY);
}
-
+
/**
* 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'
@@ -64,7 +64,7 @@ public final class LinearUnit extends Unit {
Objects.requireNonNull(unit, "unit must not be null.").getBase(),
unit.convertToBase(value), ns);
}
-
+
/**
* @return the base unit associated with {@code unit}, as a
* {@code LinearUnit}.
@@ -73,7 +73,7 @@ public final class LinearUnit extends Unit {
public static LinearUnit getBase(final Unit unit) {
return new LinearUnit(unit.getBase(), 1, NameSymbol.EMPTY);
}
-
+
/**
* @return the base unit associated with {@code unitlike}, as a
* {@code LinearUnit}.
@@ -82,7 +82,7 @@ public final class LinearUnit extends Unit {
public static LinearUnit getBase(final Unitlike<?> unit) {
return new LinearUnit(unit.getBase(), 1, NameSymbol.EMPTY);
}
-
+
/**
* Gets a {@code LinearUnit} from a unit base and a conversion factor. In
* other words, gets the product of {@code unitBase} and
@@ -98,7 +98,7 @@ public final class LinearUnit extends Unit {
final double conversionFactor) {
return new LinearUnit(unitBase, conversionFactor, NameSymbol.EMPTY);
}
-
+
/**
* Gets a {@code LinearUnit} from a unit base and a conversion factor. In
* other words, gets the product of {@code unitBase} and
@@ -115,7 +115,7 @@ public final class LinearUnit extends Unit {
final double conversionFactor, final NameSymbol ns) {
return new LinearUnit(unitBase, conversionFactor, ns);
}
-
+
/**
* The value of this unit as represented in its base form. Mathematically,
*
@@ -126,7 +126,7 @@ public final class LinearUnit extends Unit {
* @since 2019-10-16
*/
private final double conversionFactor;
-
+
/**
* Creates the {@code LinearUnit}.
*
@@ -139,7 +139,7 @@ public final class LinearUnit extends Unit {
super(unitBase, ns);
this.conversionFactor = conversionFactor;
}
-
+
/**
* {@inheritDoc}
*
@@ -149,7 +149,7 @@ public final class LinearUnit extends Unit {
protected double convertFromBase(final double value) {
return value / this.getConversionFactor();
}
-
+
/**
* Converts an {@code UncertainDouble} value expressed in this unit to an
* {@code UncertainValue} value expressed in {@code other}.
@@ -172,9 +172,9 @@ public final class LinearUnit extends Unit {
else
throw new IllegalArgumentException(
String.format("Cannot convert from %s to %s.", this, other));
-
+
}
-
+
/**
* {@inheritDoc}
*
@@ -184,7 +184,7 @@ public final class LinearUnit extends Unit {
protected double convertToBase(final double value) {
return value * this.getConversionFactor();
}
-
+
/**
* Converts an {@code UncertainDouble} to the base unit.
*
@@ -193,7 +193,7 @@ public final class LinearUnit extends Unit {
UncertainDouble convertToBase(final UncertainDouble value) {
return value.timesExact(this.getConversionFactor());
}
-
+
/**
* Divides this unit by a scalar.
*
@@ -205,7 +205,7 @@ public final class LinearUnit extends Unit {
public LinearUnit dividedBy(final double divisor) {
return valueOf(this.getBase(), this.getConversionFactor() / divisor);
}
-
+
/**
* Returns the quotient of this unit and another.
*
@@ -217,14 +217,14 @@ public final class LinearUnit extends Unit {
*/
public LinearUnit dividedBy(final LinearUnit divisor) {
Objects.requireNonNull(divisor, "other must not be null");
-
+
// divide the units
final ObjectProduct<BaseUnit> base = this.getBase()
.dividedBy(divisor.getBase());
return valueOf(base,
this.getConversionFactor() / divisor.getConversionFactor());
}
-
+
/**
* {@inheritDoc}
*
@@ -239,7 +239,7 @@ public final class LinearUnit extends Unit {
&& DecimalComparison.equals(this.getConversionFactor(),
other.getConversionFactor());
}
-
+
/**
* @return conversion factor
* @since 2019-10-16
@@ -247,7 +247,7 @@ public final class LinearUnit extends Unit {
public double getConversionFactor() {
return this.conversionFactor;
}
-
+
/**
* {@inheritDoc}
*
@@ -258,7 +258,7 @@ public final class LinearUnit extends Unit {
return 31 * this.getBase().hashCode()
+ DecimalComparison.hash(this.getConversionFactor());
}
-
+
/**
* @return whether this unit is equivalent to a {@code BaseUnit} (i.e. there
* is a {@code BaseUnit b} where
@@ -268,7 +268,7 @@ public final class LinearUnit extends Unit {
public boolean isBase() {
return this.isCoherent() && this.getBase().isSingleObject();
}
-
+
/**
* @return whether this unit is coherent (i.e. has conversion factor 1)
* @since 2019-10-16
@@ -276,7 +276,7 @@ public final class LinearUnit extends Unit {
public boolean isCoherent() {
return this.getConversionFactor() == 1;
}
-
+
/**
* Returns the difference of this unit and another.
* <p>
@@ -296,18 +296,18 @@ public final class LinearUnit extends Unit {
*/
public LinearUnit minus(final LinearUnit subtrahend) {
Objects.requireNonNull(subtrahend, "addend must not be null.");
-
+
// reject subtrahends that cannot be added to this unit
if (!this.getBase().equals(subtrahend.getBase()))
throw new IllegalArgumentException(String.format(
"Incompatible units for subtraction \"%s\" and \"%s\".", this,
subtrahend));
-
+
// subtract the units
return valueOf(this.getBase(),
this.getConversionFactor() - subtrahend.getConversionFactor());
}
-
+
/**
* Returns the sum of this unit and another.
* <p>
@@ -327,18 +327,18 @@ public final class LinearUnit extends Unit {
*/
public LinearUnit plus(final LinearUnit addend) {
Objects.requireNonNull(addend, "addend must not be null.");
-
+
// reject addends that cannot be added to this unit
if (!this.getBase().equals(addend.getBase()))
throw new IllegalArgumentException(String.format(
"Incompatible units for addition \"%s\" and \"%s\".", this,
addend));
-
+
// add the units
return valueOf(this.getBase(),
this.getConversionFactor() + addend.getConversionFactor());
}
-
+
/**
* Multiplies this unit by a scalar.
*
@@ -350,7 +350,7 @@ public final class LinearUnit extends Unit {
public LinearUnit times(final double multiplier) {
return valueOf(this.getBase(), this.getConversionFactor() * multiplier);
}
-
+
/**
* Returns the product of this unit and another.
*
@@ -362,21 +362,21 @@ public final class LinearUnit extends Unit {
*/
public LinearUnit times(final LinearUnit multiplier) {
Objects.requireNonNull(multiplier, "other must not be null");
-
+
// multiply the units
final ObjectProduct<BaseUnit> base = this.getBase()
.times(multiplier.getBase());
return valueOf(base,
this.getConversionFactor() * multiplier.getConversionFactor());
}
-
+
@Override
public String toDefinitionString() {
return Double.toString(this.conversionFactor)
+ (this.getBase().equals(ObjectProduct.empty()) ? ""
: " " + this.getBase().toString(BaseUnit::getShortName));
}
-
+
/**
* Returns this unit but to an exponent.
*
@@ -389,12 +389,12 @@ public final class LinearUnit extends Unit {
return valueOf(this.getBase().toExponent(exponent),
Math.pow(this.conversionFactor, exponent));
}
-
+
@Override
public LinearUnit withName(final NameSymbol ns) {
return valueOf(this.getBase(), this.getConversionFactor(), ns);
}
-
+
/**
* Returns the result of applying {@code prefix} to this unit.
* <p>
@@ -413,7 +413,7 @@ public final class LinearUnit extends Unit {
*/
public LinearUnit withPrefix(final UnitPrefix prefix) {
final LinearUnit unit = this.times(prefix.getMultiplier());
-
+
// create new name and symbol, if possible
final String name;
if (this.getPrimaryName().isPresent()
@@ -422,14 +422,14 @@ public final class LinearUnit extends Unit {
} else {
name = null;
}
-
+
final String symbol;
if (this.getSymbol().isPresent() && prefix.getSymbol().isPresent()) {
symbol = prefix.getSymbol().get() + this.getSymbol().get();
} else {
symbol = null;
}
-
+
return unit.withName(NameSymbol.ofNullable(name, symbol));
}
}