summaryrefslogtreecommitdiff
path: root/src/main/java/sevenUnits/unit/Unitlike.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/Unitlike.java
parentcc45a65c78c578eb404d8773b22e5b046917621f (diff)
Format source code & set explicit UTF-8
Diffstat (limited to 'src/main/java/sevenUnits/unit/Unitlike.java')
-rw-r--r--src/main/java/sevenUnits/unit/Unitlike.java38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/main/java/sevenUnits/unit/Unitlike.java b/src/main/java/sevenUnits/unit/Unitlike.java
index 68de2c2..fef424e 100644
--- a/src/main/java/sevenUnits/unit/Unitlike.java
+++ b/src/main/java/sevenUnits/unit/Unitlike.java
@@ -55,7 +55,7 @@ public abstract class Unitlike<V> implements Nameable {
return new FunctionalUnitlike<>(base, NameSymbol.EMPTY, converterFrom,
converterTo);
}
-
+
/**
* Returns a unitlike form from its base and the functions it uses to convert
* to and from its base.
@@ -78,28 +78,28 @@ public abstract class Unitlike<V> implements Nameable {
final ToDoubleFunction<W> converterTo, final NameSymbol ns) {
return new FunctionalUnitlike<>(base, ns, converterFrom, converterTo);
}
-
+
/**
* The combination of units that this unit is based on.
*
* @since 2019-10-16
*/
private final ObjectProduct<BaseUnit> unitBase;
-
+
/**
* This unit's name(s) and symbol
*
* @since 2020-09-07
*/
private final NameSymbol nameSymbol;
-
+
/**
* Cache storing the result of getDimension()
*
* @since 2019-10-16
*/
private transient ObjectProduct<BaseDimension> dimension = null;
-
+
/**
* @param unitBase
* @since 2020-09-07
@@ -109,7 +109,7 @@ public abstract class Unitlike<V> implements Nameable {
"unitBase may not be null");
this.nameSymbol = Objects.requireNonNull(ns, "ns may not be null");
}
-
+
/**
* Checks if a value expressed in this unitlike form can be converted to a
* value expressed in {@code other}
@@ -124,7 +124,7 @@ public abstract class Unitlike<V> implements Nameable {
Objects.requireNonNull(other, "other must not be null.");
return Objects.equals(this.getBase(), other.getBase());
}
-
+
/**
* Checks if a value expressed in this unitlike form can be converted to a
* value expressed in {@code other}
@@ -139,9 +139,9 @@ public abstract class Unitlike<V> implements Nameable {
Objects.requireNonNull(other, "other must not be null.");
return Objects.equals(this.getBase(), other.getBase());
}
-
+
protected abstract V convertFromBase(double value);
-
+
/**
* Converts a value expressed in this unitlike form to a value expressed in
* {@code other}.
@@ -150,7 +150,7 @@ public abstract class Unitlike<V> implements Nameable {
* {@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
@@ -168,7 +168,7 @@ public abstract class Unitlike<V> implements Nameable {
throw new IllegalArgumentException(
String.format("Cannot convert from %s to %s.", this, other));
}
-
+
/**
* Converts a value expressed in this unitlike form to a value expressed in
* {@code other}.
@@ -196,9 +196,9 @@ public abstract class Unitlike<V> implements Nameable {
throw new IllegalArgumentException(
String.format("Cannot convert from %s to %s.", this, other));
}
-
+
protected abstract double convertToBase(V value);
-
+
/**
* @return combination of units that this unit is based on
* @since 2018-12-22
@@ -207,7 +207,7 @@ public abstract class Unitlike<V> implements Nameable {
public final ObjectProduct<BaseUnit> getBase() {
return this.unitBase;
}
-
+
/**
* @return dimension measured by this unit
* @since 2018-12-22
@@ -217,16 +217,16 @@ public abstract class Unitlike<V> implements Nameable {
if (this.dimension == null) {
final Map<BaseUnit, Integer> mapping = this.unitBase.exponentMap();
final Map<BaseDimension, Integer> dimensionMap = new HashMap<>();
-
+
for (final BaseUnit key : mapping.keySet()) {
dimensionMap.put(key.getBaseDimension(), mapping.get(key));
}
-
+
this.dimension = ObjectProduct.fromExponentMapping(dimensionMap);
}
return this.dimension;
}
-
+
/**
* @return the nameSymbol
* @since 2020-09-07
@@ -235,7 +235,7 @@ public abstract class Unitlike<V> implements Nameable {
public final NameSymbol getNameSymbol() {
return this.nameSymbol;
}
-
+
@Override
public String toString() {
return this.getPrimaryName().orElse("Unnamed unitlike form")
@@ -247,7 +247,7 @@ public abstract class Unitlike<V> implements Nameable {
+ (this.getOtherNames().isEmpty() ? ""
: ", also called " + String.join(", ", this.getOtherNames()));
}
-
+
/**
* @param ns name(s) and symbol to use
* @return a copy of this unitlike form with provided name(s) and symbol