summaryrefslogtreecommitdiff
path: root/src/main/java/sevenUnits/utils/ObjectProduct.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/utils/ObjectProduct.java
parentcc45a65c78c578eb404d8773b22e5b046917621f (diff)
Format source code & set explicit UTF-8
Diffstat (limited to 'src/main/java/sevenUnits/utils/ObjectProduct.java')
-rw-r--r--src/main/java/sevenUnits/utils/ObjectProduct.java56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/main/java/sevenUnits/utils/ObjectProduct.java b/src/main/java/sevenUnits/utils/ObjectProduct.java
index 66bb773..5a29d79 100644
--- a/src/main/java/sevenUnits/utils/ObjectProduct.java
+++ b/src/main/java/sevenUnits/utils/ObjectProduct.java
@@ -44,7 +44,7 @@ public class ObjectProduct<T> implements Nameable {
public static final <T> ObjectProduct<T> empty() {
return new ObjectProduct<>(new HashMap<>());
}
-
+
/**
* Gets an {@code ObjectProduct} from an object-to-integer mapping
*
@@ -57,7 +57,7 @@ public class ObjectProduct<T> implements Nameable {
final Map<T, Integer> map) {
return new ObjectProduct<>(new HashMap<>(map));
}
-
+
/**
* Gets an ObjectProduct that has one of the inputted argument, and nothing
* else.
@@ -73,7 +73,7 @@ public class ObjectProduct<T> implements Nameable {
map.put(object, 1);
return new ObjectProduct<>(map);
}
-
+
/**
* The objects that make up the product, mapped to their exponents. This map
* treats zero as null, and is immutable.
@@ -81,12 +81,12 @@ public class ObjectProduct<T> implements Nameable {
* @since 2019-10-16
*/
final Map<T, Integer> exponents;
-
+
/**
* The object's name and symbol
*/
private final NameSymbol nameSymbol;
-
+
/**
* Creates a {@code ObjectProduct} without a name/symbol.
*
@@ -96,7 +96,7 @@ public class ObjectProduct<T> implements Nameable {
ObjectProduct(final Map<T, Integer> exponents) {
this(exponents, NameSymbol.EMPTY);
}
-
+
/**
* Creates the {@code ObjectProduct}.
*
@@ -110,7 +110,7 @@ public class ObjectProduct<T> implements Nameable {
e -> !Integer.valueOf(0).equals(e.getValue())));
this.nameSymbol = nameSymbol;
}
-
+
/**
* Calculates the quotient of two products
*
@@ -125,17 +125,17 @@ public class ObjectProduct<T> implements Nameable {
final Set<T> objects = new HashSet<>();
objects.addAll(this.getBaseSet());
objects.addAll(other.getBaseSet());
-
+
// get a list of all exponents
final Map<T, Integer> map = new HashMap<>(objects.size());
for (final T key : objects) {
map.put(key, this.getExponent(key) - other.getExponent(key));
}
-
+
// create the product
return new ObjectProduct<>(map);
}
-
+
// this method relies on the use of ZeroIsNullMap
@Override
public boolean equals(final Object obj) {
@@ -146,7 +146,7 @@ public class ObjectProduct<T> implements Nameable {
final ObjectProduct<?> other = (ObjectProduct<?>) obj;
return Objects.equals(this.exponents, other.exponents);
}
-
+
/**
* @return immutable map mapping objects to exponents
* @since 2019-10-16
@@ -154,7 +154,7 @@ public class ObjectProduct<T> implements Nameable {
public Map<T, Integer> exponentMap() {
return this.exponents;
}
-
+
/**
* @return a set of all of the base objects with non-zero exponents that make
* up this dimension.
@@ -163,7 +163,7 @@ public class ObjectProduct<T> implements Nameable {
*/
public final Set<T> getBaseSet() {
final Set<T> dimensions = new HashSet<>();
-
+
// add all dimensions with a nonzero exponent - zero exponents shouldn't
// be there in the first place
for (final T dimension : this.exponents.keySet()) {
@@ -171,10 +171,10 @@ public class ObjectProduct<T> implements Nameable {
dimensions.add(dimension);
}
}
-
+
return dimensions;
}
-
+
/**
* Gets the exponent for a specific dimension.
*
@@ -186,17 +186,17 @@ public class ObjectProduct<T> implements Nameable {
public int getExponent(final T dimension) {
return this.exponents.getOrDefault(dimension, 0);
}
-
+
@Override
public NameSymbol getNameSymbol() {
return this.nameSymbol;
}
-
+
@Override
public int hashCode() {
return Objects.hash(this.exponents);
}
-
+
/**
* @return true if this product is a single object, i.e. it has one exponent
* of one and no other nonzero exponents
@@ -214,7 +214,7 @@ public class ObjectProduct<T> implements Nameable {
}
return oneCount == 1 && !twoOrMore;
}
-
+
/**
* Multiplies this product by another
*
@@ -229,17 +229,17 @@ public class ObjectProduct<T> implements Nameable {
final Set<T> objects = new HashSet<>();
objects.addAll(this.getBaseSet());
objects.addAll(other.getBaseSet());
-
+
// get a list of all exponents
final Map<T, Integer> map = new HashMap<>(objects.size());
for (final T key : objects) {
map.put(key, this.getExponent(key) + other.getExponent(key));
}
-
+
// create the product
return new ObjectProduct<>(map);
}
-
+
/**
* Returns this product, but to an exponent
*
@@ -254,7 +254,7 @@ public class ObjectProduct<T> implements Nameable {
}
return new ObjectProduct<>(map);
}
-
+
/**
* Converts this product to a string using the objects'
* {@link Object#toString()} method (or {@link Nameable#getShortName} if
@@ -271,7 +271,7 @@ public class ObjectProduct<T> implements Nameable {
.toString(o -> o instanceof Nameable ? ((Nameable) o).getShortName()
: o.toString());
}
-
+
/**
* Converts this product to a string. The objects that make up this product
* are represented by {@code objectToString}
@@ -283,7 +283,7 @@ public class ObjectProduct<T> implements Nameable {
public String toString(final Function<T, String> objectToString) {
final List<String> positiveStringComponents = new ArrayList<>();
final List<String> negativeStringComponents = new ArrayList<>();
-
+
// for each base object that makes up this object, add it and its exponent
for (final T object : this.getBaseSet()) {
final int exponent = this.exponents.get(object);
@@ -297,15 +297,15 @@ public class ObjectProduct<T> implements Nameable {
objectToString.apply(object), -exponent));
}
}
-
+
final String positiveString = positiveStringComponents.isEmpty() ? "1"
: String.join(" * ", positiveStringComponents);
final String negativeString = negativeStringComponents.isEmpty() ? ""
: " / " + String.join(" * ", negativeStringComponents);
-
+
return positiveString + negativeString;
}
-
+
/**
* @return named version of this {@code ObjectProduct}, using data from
* {@code nameSymbol}