summaryrefslogtreecommitdiff
path: root/src/main/java/sevenUnits/unit/MultiUnit.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/MultiUnit.java
parentcc45a65c78c578eb404d8773b22e5b046917621f (diff)
Format source code & set explicit UTF-8
Diffstat (limited to 'src/main/java/sevenUnits/unit/MultiUnit.java')
-rw-r--r--src/main/java/sevenUnits/unit/MultiUnit.java30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/main/java/sevenUnits/unit/MultiUnit.java b/src/main/java/sevenUnits/unit/MultiUnit.java
index bc240e3..950c547 100644
--- a/src/main/java/sevenUnits/unit/MultiUnit.java
+++ b/src/main/java/sevenUnits/unit/MultiUnit.java
@@ -39,7 +39,7 @@ public final class MultiUnit extends Unitlike<List<Double>> {
public static final MultiUnit of(LinearUnit... units) {
return of(Arrays.asList(units));
}
-
+
/**
* Creates a {@code MultiUnit} from its units. It will not have a name or
* symbol.
@@ -57,12 +57,12 @@ public final class MultiUnit extends Unitlike<List<Double>> {
}
return new MultiUnit(new ArrayList<>(units), unitBase, NameSymbol.EMPTY);
}
-
+
/**
* The units that make up this value.
*/
private final List<LinearUnit> units;
-
+
/**
* Creates a {@code MultiUnit}.
*
@@ -73,24 +73,24 @@ public final class MultiUnit extends Unitlike<List<Double>> {
super(unitBase, ns);
this.units = units;
}
-
+
@Override
protected List<Double> convertFromBase(double value) {
final List<Double> values = new ArrayList<>(this.units.size());
double temp = value;
-
+
for (final LinearUnit unit : this.units.subList(0,
this.units.size() - 1)) {
values.add(Math.floor(temp / unit.getConversionFactor()));
temp %= unit.getConversionFactor();
}
-
+
values.add(this.units.size() - 1,
this.units.get(this.units.size() - 1).convertFromBase(temp));
-
+
return values;
}
-
+
/**
* Converts a value expressed in this unitlike form to a value expressed in
* {@code other}.
@@ -99,7 +99,7 @@ public final class MultiUnit extends Unitlike<List<Double>> {
* {@code other.convertFromBase(this.convertToBase(value))}.
* Therefore, overriding either of those methods will change the
* output of this method.
- *
+ *
* @param other unit to convert to
* @param value value to convert
* @return converted value
@@ -115,10 +115,10 @@ public final class MultiUnit extends Unitlike<List<Double>> {
for (final double d : values) {
valueList.add(d);
}
-
+
return this.convertTo(other, valueList);
}
-
+
/**
* Converts a value expressed in this unitlike form to a value expressed in
* {@code other}.
@@ -127,7 +127,7 @@ public final class MultiUnit extends Unitlike<List<Double>> {
* {@code other.convertFromBase(this.convertToBase(value))}.
* Therefore, overriding either of those methods will change the
* output of this method.
- *
+ *
* @param other unit to convert to
* @param value value to convert
* @return converted value
@@ -142,16 +142,16 @@ public final class MultiUnit extends Unitlike<List<Double>> {
for (final double d : values) {
valueList.add(d);
}
-
+
return this.convertTo(other, valueList);
}
-
+
@Override
protected double convertToBase(List<Double> value) {
if (value.size() != this.units.size())
throw new IllegalArgumentException("Wrong number of values for "
+ this.units.size() + "-unit MultiUnit.");
-
+
double baseValue = 0;
for (int i = 0; i < this.units.size(); i++) {
baseValue += value.get(i) * this.units.get(i).getConversionFactor();