summaryrefslogtreecommitdiff
path: root/src/main/java/sevenUnits/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/sevenUnits/utils')
-rw-r--r--src/main/java/sevenUnits/utils/NameSymbol.java2
-rw-r--r--src/main/java/sevenUnits/utils/NamedObjectProduct.java51
-rw-r--r--src/main/java/sevenUnits/utils/ObjectProduct.java30
3 files changed, 27 insertions, 56 deletions
diff --git a/src/main/java/sevenUnits/utils/NameSymbol.java b/src/main/java/sevenUnits/utils/NameSymbol.java
index 41cf41d..955f980 100644
--- a/src/main/java/sevenUnits/utils/NameSymbol.java
+++ b/src/main/java/sevenUnits/utils/NameSymbol.java
@@ -38,7 +38,7 @@ public final class NameSymbol {
* Creates a {@code NameSymbol}, ensuring that if primaryName is null and
* otherNames is not empty, one name is moved from otherNames to primaryName
*
- * Ensure that otherNames is a copy of the inputted argument.
+ * Ensure that otherNames is not a copy of the inputted argument.
*/
private static final NameSymbol create(final String name,
final String symbol, final Set<String> otherNames) {
diff --git a/src/main/java/sevenUnits/utils/NamedObjectProduct.java b/src/main/java/sevenUnits/utils/NamedObjectProduct.java
deleted file mode 100644
index 89b2fad..0000000
--- a/src/main/java/sevenUnits/utils/NamedObjectProduct.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Copyright (C) 2021 Adrien Hopkins
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-package sevenUnits.utils;
-
-import java.util.Map;
-
-/**
- * An ObjectProduct with name(s) and/or a symbol. Can be created with the
- * {@link ObjectProduct#withName} method.
- *
- * @author Adrien Hopkins
- * @since 2021-12-15
- */
-public class NamedObjectProduct<T> extends ObjectProduct<T>
- implements Nameable {
- private final NameSymbol nameSymbol;
-
- NamedObjectProduct(final Map<T, Integer> exponents,
- final NameSymbol nameSymbol) {
- super(exponents);
- this.nameSymbol = nameSymbol;
- }
-
- @Override
- public NameSymbol getNameSymbol() {
- return this.nameSymbol;
- }
-
- public final String toDefinitionString() {
- return super.toString();
- }
-
- @Override
- public String toString() {
- return this.nameSymbol.toString();
- }
-}
diff --git a/src/main/java/sevenUnits/utils/ObjectProduct.java b/src/main/java/sevenUnits/utils/ObjectProduct.java
index 830f9d7..110bdc1 100644
--- a/src/main/java/sevenUnits/utils/ObjectProduct.java
+++ b/src/main/java/sevenUnits/utils/ObjectProduct.java
@@ -33,7 +33,7 @@ import java.util.function.Function;
* @author Adrien Hopkins
* @since 2019-10-16
*/
-public class ObjectProduct<T> {
+public class ObjectProduct<T> implements Nameable {
/**
* Returns an empty ObjectProduct of a certain type
*
@@ -83,15 +83,32 @@ public class ObjectProduct<T> {
final Map<T, Integer> exponents;
/**
- * Creates the {@code ObjectProduct}.
+ * The object's name and symbol
+ */
+ private final NameSymbol nameSymbol;
+
+ /**
+ * Creates a {@code ObjectProduct} without a name/symbol.
*
* @param exponents objects that make up this product
* @since 2019-10-16
*/
ObjectProduct(final Map<T, Integer> exponents) {
+ this(exponents, NameSymbol.EMPTY);
+ }
+
+ /**
+ * Creates the {@code ObjectProduct}.
+ *
+ * @param exponents objects that make up this product
+ * @param nameSymbol name and symbol of object product
+ * @since 2019-10-16
+ */
+ ObjectProduct(final Map<T, Integer> exponents, NameSymbol nameSymbol) {
this.exponents = Collections.unmodifiableMap(
ConditionalExistenceCollections.conditionalExistenceMap(exponents,
e -> !Integer.valueOf(0).equals(e.getValue())));
+ this.nameSymbol = nameSymbol;
}
/**
@@ -171,6 +188,11 @@ public class ObjectProduct<T> {
}
@Override
+ public NameSymbol getNameSymbol() {
+ return this.nameSymbol;
+ }
+
+ @Override
public int hashCode() {
return Objects.hash(this.exponents);
}
@@ -288,7 +310,7 @@ public class ObjectProduct<T> {
* {@code nameSymbol}
* @since 2021-12-15
*/
- public NamedObjectProduct<T> withName(NameSymbol nameSymbol) {
- return new NamedObjectProduct<>(this.exponents, nameSymbol);
+ public ObjectProduct<T> withName(NameSymbol nameSymbol) {
+ return new ObjectProduct<>(this.exponents, nameSymbol);
}
}