diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/unitConverter/converterGUI/DefaultPrefixRepetitionRule.java (renamed from src/org/unitConverter/converterGUI/DefaultPrefixRepetitionRule.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/converterGUI/DelegateListModel.java (renamed from src/org/unitConverter/converterGUI/DelegateListModel.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/converterGUI/FilterComparator.java (renamed from src/org/unitConverter/converterGUI/FilterComparator.java) | 258 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/converterGUI/GridBagBuilder.java (renamed from src/org/unitConverter/converterGUI/GridBagBuilder.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/converterGUI/MutablePredicate.java (renamed from src/org/unitConverter/converterGUI/MutablePredicate.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/converterGUI/SearchBoxList.java (renamed from src/org/unitConverter/converterGUI/SearchBoxList.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/converterGUI/UnitConverterGUI.java (renamed from src/org/unitConverter/converterGUI/UnitConverterGUI.java) | 6 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/converterGUI/package-info.java (renamed from src/org/unitConverter/converterGUI/package-info.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/math/ConditionalExistenceCollections.java (renamed from src/org/unitConverter/math/ConditionalExistenceCollections.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/math/DecimalComparison.java (renamed from src/org/unitConverter/math/DecimalComparison.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/math/ExpressionParser.java (renamed from src/org/unitConverter/math/ExpressionParser.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/math/ObjectProduct.java (renamed from src/org/unitConverter/math/ObjectProduct.java) | 568 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/math/UncertainDouble.java (renamed from src/org/unitConverter/math/UncertainDouble.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/math/package-info.java (renamed from src/org/unitConverter/math/package-info.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/package-info.java (renamed from src/org/unitConverter/package-info.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/BaseDimension.java (renamed from src/org/unitConverter/unit/BaseDimension.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/BaseUnit.java (renamed from src/org/unitConverter/unit/BaseUnit.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/BritishImperial.java (renamed from src/org/unitConverter/unit/BritishImperial.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/FunctionalUnit.java (renamed from src/org/unitConverter/unit/FunctionalUnit.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/FunctionalUnitlike.java (renamed from src/org/unitConverter/unit/FunctionalUnitlike.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/LinearUnit.java (renamed from src/org/unitConverter/unit/LinearUnit.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/LinearUnitValue.java (renamed from src/org/unitConverter/unit/LinearUnitValue.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/MultiUnit.java (renamed from src/org/unitConverter/unit/MultiUnit.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/NameSymbol.java (renamed from src/org/unitConverter/unit/NameSymbol.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/Nameable.java (renamed from src/org/unitConverter/unit/Nameable.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/SI.java (renamed from src/org/unitConverter/unit/SI.java) | 958 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/USCustomary.java (renamed from src/org/unitConverter/unit/USCustomary.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/Unit.java (renamed from src/org/unitConverter/unit/Unit.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/UnitDatabase.java (renamed from src/org/unitConverter/unit/UnitDatabase.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/UnitPrefix.java (renamed from src/org/unitConverter/unit/UnitPrefix.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/UnitValue.java (renamed from src/org/unitConverter/unit/UnitValue.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/Unitlike.java (renamed from src/org/unitConverter/unit/Unitlike.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/UnitlikeValue.java (renamed from src/org/unitConverter/unit/UnitlikeValue.java) | 0 | ||||
-rw-r--r-- | src/main/java/org/unitConverter/unit/package-info.java (renamed from src/org/unitConverter/unit/package-info.java) | 0 | ||||
-rw-r--r-- | src/main/resources/about.txt (renamed from src/about.txt) | 0 | ||||
-rw-r--r-- | src/test/java/org/unitConverter/math/ConditionalExistenceCollectionsTest.java (renamed from src/org/unitConverter/math/ConditionalExistenceCollectionsTest.java) | 0 | ||||
-rw-r--r-- | src/test/java/org/unitConverter/math/ExpressionParserTest.java (renamed from src/org/unitConverter/math/ExpressionParserTest.java) | 0 | ||||
-rw-r--r-- | src/test/java/org/unitConverter/math/ObjectProductTest.java (renamed from src/org/unitConverter/math/ObjectProductTest.java) | 0 | ||||
-rw-r--r-- | src/test/java/org/unitConverter/unit/MultiUnitTest.java (renamed from src/org/unitConverter/unit/MultiUnitTest.java) | 0 | ||||
-rw-r--r-- | src/test/java/org/unitConverter/unit/UnitDatabaseTest.java (renamed from src/org/unitConverter/unit/UnitDatabaseTest.java) | 4 | ||||
-rw-r--r-- | src/test/java/org/unitConverter/unit/UnitTest.java (renamed from src/org/unitConverter/unit/UnitTest.java) | 2 |
41 files changed, 899 insertions, 897 deletions
diff --git a/src/org/unitConverter/converterGUI/DefaultPrefixRepetitionRule.java b/src/main/java/org/unitConverter/converterGUI/DefaultPrefixRepetitionRule.java index bdc3a2e..bdc3a2e 100644 --- a/src/org/unitConverter/converterGUI/DefaultPrefixRepetitionRule.java +++ b/src/main/java/org/unitConverter/converterGUI/DefaultPrefixRepetitionRule.java diff --git a/src/org/unitConverter/converterGUI/DelegateListModel.java b/src/main/java/org/unitConverter/converterGUI/DelegateListModel.java index b80f63d..b80f63d 100644 --- a/src/org/unitConverter/converterGUI/DelegateListModel.java +++ b/src/main/java/org/unitConverter/converterGUI/DelegateListModel.java diff --git a/src/org/unitConverter/converterGUI/FilterComparator.java b/src/main/java/org/unitConverter/converterGUI/FilterComparator.java index 7b17bfc..9b77f21 100644 --- a/src/org/unitConverter/converterGUI/FilterComparator.java +++ b/src/main/java/org/unitConverter/converterGUI/FilterComparator.java @@ -1,129 +1,129 @@ -/**
- * Copyright (C) 2018 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 org.unitConverter.converterGUI;
-
-import java.util.Comparator;
-import java.util.Objects;
-
-/**
- * A comparator that compares strings using a filter.
- *
- * @author Adrien Hopkins
- * @since 2019-01-15
- * @since v0.1.0
- */
-final class FilterComparator implements Comparator<String> {
- /**
- * The filter that the comparator is filtered by.
- *
- * @since 2019-01-15
- * @since v0.1.0
- */
- private final String filter;
- /**
- * The comparator to use if the arguments are otherwise equal.
- *
- * @since 2019-01-15
- * @since v0.1.0
- */
- private final Comparator<String> comparator;
- /**
- * Whether or not the comparison is case-sensitive.
- *
- * @since 2019-04-14
- * @since v0.2.0
- */
- private final boolean caseSensitive;
-
- /**
- * Creates the {@code FilterComparator}.
- *
- * @param filter
- * @since 2019-01-15
- * @since v0.1.0
- */
- public FilterComparator(final String filter) {
- this(filter, null);
- }
-
- /**
- * Creates the {@code FilterComparator}.
- *
- * @param filter
- * string to filter by
- * @param comparator
- * comparator to fall back to if all else fails, null is compareTo.
- * @throws NullPointerException
- * if filter is null
- * @since 2019-01-15
- * @since v0.1.0
- */
- public FilterComparator(final String filter, final Comparator<String> comparator) {
- this(filter, comparator, false);
- }
-
- /**
- * Creates the {@code FilterComparator}.
- *
- * @param filter
- * string to filter by
- * @param comparator
- * comparator to fall back to if all else fails, null is compareTo.
- * @param caseSensitive
- * whether or not the comparator is case-sensitive
- * @throws NullPointerException
- * if filter is null
- * @since 2019-04-14
- * @since v0.2.0
- */
- public FilterComparator(final String filter, final Comparator<String> comparator, final boolean caseSensitive) {
- this.filter = Objects.requireNonNull(filter, "filter must not be null.");
- this.comparator = comparator;
- this.caseSensitive = caseSensitive;
- }
-
- @Override
- public int compare(final String arg0, final String arg1) {
- // if this is case insensitive, make them lowercase
- final String str0, str1;
- if (this.caseSensitive) {
- str0 = arg0;
- str1 = arg1;
- } else {
- str0 = arg0.toLowerCase();
- str1 = arg1.toLowerCase();
- }
-
- // elements that start with the filter always go first
- if (str0.startsWith(this.filter) && !str1.startsWith(this.filter))
- return -1;
- else if (!str0.startsWith(this.filter) && str1.startsWith(this.filter))
- return 1;
-
- // elements that contain the filter but don't start with them go next
- if (str0.contains(this.filter) && !str1.contains(this.filter))
- return -1;
- else if (!str0.contains(this.filter) && !str1.contains(this.filter))
- return 1;
-
- // other elements go last
- if (this.comparator == null)
- return str0.compareTo(str1);
- else
- return this.comparator.compare(str0, str1);
- }
-}
+/** + * Copyright (C) 2018 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 org.unitConverter.converterGUI; + +import java.util.Comparator; +import java.util.Objects; + +/** + * A comparator that compares strings using a filter. + * + * @author Adrien Hopkins + * @since 2019-01-15 + * @since v0.1.0 + */ +final class FilterComparator implements Comparator<String> { + /** + * The filter that the comparator is filtered by. + * + * @since 2019-01-15 + * @since v0.1.0 + */ + private final String filter; + /** + * The comparator to use if the arguments are otherwise equal. + * + * @since 2019-01-15 + * @since v0.1.0 + */ + private final Comparator<String> comparator; + /** + * Whether or not the comparison is case-sensitive. + * + * @since 2019-04-14 + * @since v0.2.0 + */ + private final boolean caseSensitive; + + /** + * Creates the {@code FilterComparator}. + * + * @param filter + * @since 2019-01-15 + * @since v0.1.0 + */ + public FilterComparator(final String filter) { + this(filter, null); + } + + /** + * Creates the {@code FilterComparator}. + * + * @param filter + * string to filter by + * @param comparator + * comparator to fall back to if all else fails, null is compareTo. + * @throws NullPointerException + * if filter is null + * @since 2019-01-15 + * @since v0.1.0 + */ + public FilterComparator(final String filter, final Comparator<String> comparator) { + this(filter, comparator, false); + } + + /** + * Creates the {@code FilterComparator}. + * + * @param filter + * string to filter by + * @param comparator + * comparator to fall back to if all else fails, null is compareTo. + * @param caseSensitive + * whether or not the comparator is case-sensitive + * @throws NullPointerException + * if filter is null + * @since 2019-04-14 + * @since v0.2.0 + */ + public FilterComparator(final String filter, final Comparator<String> comparator, final boolean caseSensitive) { + this.filter = Objects.requireNonNull(filter, "filter must not be null."); + this.comparator = comparator; + this.caseSensitive = caseSensitive; + } + + @Override + public int compare(final String arg0, final String arg1) { + // if this is case insensitive, make them lowercase + final String str0, str1; + if (this.caseSensitive) { + str0 = arg0; + str1 = arg1; + } else { + str0 = arg0.toLowerCase(); + str1 = arg1.toLowerCase(); + } + + // elements that start with the filter always go first + if (str0.startsWith(this.filter) && !str1.startsWith(this.filter)) + return -1; + else if (!str0.startsWith(this.filter) && str1.startsWith(this.filter)) + return 1; + + // elements that contain the filter but don't start with them go next + if (str0.contains(this.filter) && !str1.contains(this.filter)) + return -1; + else if (!str0.contains(this.filter) && !str1.contains(this.filter)) + return 1; + + // other elements go last + if (this.comparator == null) + return str0.compareTo(str1); + else + return this.comparator.compare(str0, str1); + } +} diff --git a/src/org/unitConverter/converterGUI/GridBagBuilder.java b/src/main/java/org/unitConverter/converterGUI/GridBagBuilder.java index f1229b2..f1229b2 100644 --- a/src/org/unitConverter/converterGUI/GridBagBuilder.java +++ b/src/main/java/org/unitConverter/converterGUI/GridBagBuilder.java diff --git a/src/org/unitConverter/converterGUI/MutablePredicate.java b/src/main/java/org/unitConverter/converterGUI/MutablePredicate.java index e15b3cd..e15b3cd 100644 --- a/src/org/unitConverter/converterGUI/MutablePredicate.java +++ b/src/main/java/org/unitConverter/converterGUI/MutablePredicate.java diff --git a/src/org/unitConverter/converterGUI/SearchBoxList.java b/src/main/java/org/unitConverter/converterGUI/SearchBoxList.java index 10ef589..10ef589 100644 --- a/src/org/unitConverter/converterGUI/SearchBoxList.java +++ b/src/main/java/org/unitConverter/converterGUI/SearchBoxList.java diff --git a/src/org/unitConverter/converterGUI/UnitConverterGUI.java b/src/main/java/org/unitConverter/converterGUI/UnitConverterGUI.java index 6ddc4a0..c046846 100644 --- a/src/org/unitConverter/converterGUI/UnitConverterGUI.java +++ b/src/main/java/org/unitConverter/converterGUI/UnitConverterGUI.java @@ -1141,12 +1141,14 @@ final class UnitConverterGUI { // get info text final String infoText; try { - final Path aboutFile = Path.of("src", "about.txt"); + final Path aboutFile = Path.of("src", "main", "resources", + "about.txt"); infoText = Files.readAllLines(aboutFile).stream() .map(Presenter::withoutComments) .collect(Collectors.joining("\n")); } catch (final IOException e) { - throw new AssertionError("I/O exception loading about.txt"); + throw new AssertionError("I/O exception loading about.txt", + e); } infoTextArea.setText(infoText); } diff --git a/src/org/unitConverter/converterGUI/package-info.java b/src/main/java/org/unitConverter/converterGUI/package-info.java index d85ecab..d85ecab 100644 --- a/src/org/unitConverter/converterGUI/package-info.java +++ b/src/main/java/org/unitConverter/converterGUI/package-info.java diff --git a/src/org/unitConverter/math/ConditionalExistenceCollections.java b/src/main/java/org/unitConverter/math/ConditionalExistenceCollections.java index ac1c0cf..ac1c0cf 100644 --- a/src/org/unitConverter/math/ConditionalExistenceCollections.java +++ b/src/main/java/org/unitConverter/math/ConditionalExistenceCollections.java diff --git a/src/org/unitConverter/math/DecimalComparison.java b/src/main/java/org/unitConverter/math/DecimalComparison.java index 0f5b91e..0f5b91e 100644 --- a/src/org/unitConverter/math/DecimalComparison.java +++ b/src/main/java/org/unitConverter/math/DecimalComparison.java diff --git a/src/org/unitConverter/math/ExpressionParser.java b/src/main/java/org/unitConverter/math/ExpressionParser.java index 8a0e97d..8a0e97d 100644 --- a/src/org/unitConverter/math/ExpressionParser.java +++ b/src/main/java/org/unitConverter/math/ExpressionParser.java diff --git a/src/org/unitConverter/math/ObjectProduct.java b/src/main/java/org/unitConverter/math/ObjectProduct.java index bf00647..5217d93 100644 --- a/src/org/unitConverter/math/ObjectProduct.java +++ b/src/main/java/org/unitConverter/math/ObjectProduct.java @@ -1,284 +1,284 @@ -/**
- * Copyright (C) 2018 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 org.unitConverter.math;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.function.Function;
-
-/**
- * An immutable product of multiple objects of a type, such as base units. The objects can be multiplied and
- * exponentiated.
- *
- * @author Adrien Hopkins
- * @since 2019-10-16
- */
-public final class ObjectProduct<T> {
- /**
- * Returns an empty ObjectProduct of a certain type
- *
- * @param <T>
- * type of objects that can be multiplied
- * @return empty product
- * @since 2019-10-16
- */
- public static final <T> ObjectProduct<T> empty() {
- return new ObjectProduct<>(new HashMap<>());
- }
-
- /**
- * Gets an {@code ObjectProduct} from an object-to-integer mapping
- *
- * @param <T>
- * type of object in product
- * @param map
- * map mapping objects to exponents
- * @return object product
- * @since 2019-10-16
- */
- public static final <T> ObjectProduct<T> fromExponentMapping(final Map<T, Integer> map) {
- return new ObjectProduct<>(new HashMap<>(map));
- }
-
- /**
- * Gets an ObjectProduct that has one of the inputted argument, and nothing else.
- *
- * @param object
- * object that will be in the product
- * @return product
- * @since 2019-10-16
- * @throws NullPointerException
- * if object is null
- */
- public static final <T> ObjectProduct<T> oneOf(final T object) {
- Objects.requireNonNull(object, "object must not be null.");
- final Map<T, Integer> map = new HashMap<>();
- 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.
- *
- * @since 2019-10-16
- */
- final Map<T, Integer> exponents;
-
- /**
- * Creates the {@code ObjectProduct}.
- *
- * @param exponents
- * objects that make up this product
- * @since 2019-10-16
- */
- private ObjectProduct(final Map<T, Integer> exponents) {
- this.exponents = Collections.unmodifiableMap(ConditionalExistenceCollections.conditionalExistenceMap(exponents,
- e -> !Integer.valueOf(0).equals(e.getValue())));
- }
-
- /**
- * Calculates the quotient of two products
- *
- * @param other
- * other product
- * @return quotient of two products
- * @since 2019-10-16
- * @throws NullPointerException
- * if other is null
- */
- public ObjectProduct<T> dividedBy(final ObjectProduct<T> other) {
- Objects.requireNonNull(other, "other must not be null.");
- // get a list of all objects in both sets
- 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) {
- if (this == obj)
- return true;
- if (!(obj instanceof ObjectProduct))
- return false;
- final ObjectProduct<?> other = (ObjectProduct<?>) obj;
- return Objects.equals(this.exponents, other.exponents);
- }
-
- /**
- * @return immutable map mapping objects to exponents
- * @since 2019-10-16
- */
- 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.
- * @since 2018-12-12
- * @since v0.1.0
- */
- 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()) {
- if (!this.exponents.get(dimension).equals(0)) {
- dimensions.add(dimension);
- }
- }
-
- return dimensions;
- }
-
- /**
- * Gets the exponent for a specific dimension.
- *
- * @param dimension
- * dimension to check
- * @return exponent for that dimension
- * @since 2018-12-12
- * @since v0.1.0
- */
- public int getExponent(final T dimension) {
- return this.exponents.getOrDefault(dimension, 0);
- }
-
- @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
- * @since 2019-10-16
- */
- public boolean isSingleObject() {
- int oneCount = 0;
- boolean twoOrMore = false; // has exponents of 2 or more
- for (final T b : this.getBaseSet()) {
- if (this.getExponent(b) == 1) {
- oneCount++;
- } else if (this.getExponent(b) != 0) {
- twoOrMore = true;
- }
- }
- return oneCount == 1 && !twoOrMore;
- }
-
- /**
- * Multiplies this product by another
- *
- * @param other
- * other product
- * @return product of two products
- * @since 2019-10-16
- * @throws NullPointerException
- * if other is null
- */
- public ObjectProduct<T> times(final ObjectProduct<T> other) {
- Objects.requireNonNull(other, "other must not be null.");
- // get a list of all objects in both sets
- 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
- *
- * @param exponent
- * exponent
- * @return result of exponentiation
- * @since 2019-10-16
- */
- public ObjectProduct<T> toExponent(final int exponent) {
- final Map<T, Integer> map = new HashMap<>(this.exponents);
- for (final T key : this.exponents.keySet()) {
- map.put(key, this.getExponent(key) * exponent);
- }
- return new ObjectProduct<>(map);
- }
-
- /**
- * Converts this product to a string using the objects' {@link Object#toString()} method. If objects have a long
- * toString representation, it is recommended to use {@link #toString(Function)} instead to shorten the returned
- * string.
- *
- * <p>
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return this.toString(Object::toString);
- }
-
- /**
- * Converts this product to a string. The objects that make up this product are represented by
- * {@code objectToString}
- *
- * @param objectToString
- * function to convert objects to strings
- * @return string representation of product
- * @since 2019-10-16
- */
- 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);
- if (exponent > 0) {
- positiveStringComponents.add(String.format("%s^%d", objectToString.apply(object), exponent));
- } else if (exponent < 0) {
- negativeStringComponents.add(String.format("%s^%d", objectToString.apply(object), -exponent));
- }
- }
-
- final String positiveString = positiveStringComponents.isEmpty() ? "1"
- : String.join(" * ", positiveStringComponents);
- final String negativeString = negativeStringComponents.isEmpty() ? ""
- : " / " + String.join(" * ", negativeStringComponents);
-
- return positiveString + negativeString;
- }
-}
+/** + * Copyright (C) 2018 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 org.unitConverter.math; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.function.Function; + +/** + * An immutable product of multiple objects of a type, such as base units. The objects can be multiplied and + * exponentiated. + * + * @author Adrien Hopkins + * @since 2019-10-16 + */ +public final class ObjectProduct<T> { + /** + * Returns an empty ObjectProduct of a certain type + * + * @param <T> + * type of objects that can be multiplied + * @return empty product + * @since 2019-10-16 + */ + public static final <T> ObjectProduct<T> empty() { + return new ObjectProduct<>(new HashMap<>()); + } + + /** + * Gets an {@code ObjectProduct} from an object-to-integer mapping + * + * @param <T> + * type of object in product + * @param map + * map mapping objects to exponents + * @return object product + * @since 2019-10-16 + */ + public static final <T> ObjectProduct<T> fromExponentMapping(final Map<T, Integer> map) { + return new ObjectProduct<>(new HashMap<>(map)); + } + + /** + * Gets an ObjectProduct that has one of the inputted argument, and nothing else. + * + * @param object + * object that will be in the product + * @return product + * @since 2019-10-16 + * @throws NullPointerException + * if object is null + */ + public static final <T> ObjectProduct<T> oneOf(final T object) { + Objects.requireNonNull(object, "object must not be null."); + final Map<T, Integer> map = new HashMap<>(); + 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. + * + * @since 2019-10-16 + */ + final Map<T, Integer> exponents; + + /** + * Creates the {@code ObjectProduct}. + * + * @param exponents + * objects that make up this product + * @since 2019-10-16 + */ + private ObjectProduct(final Map<T, Integer> exponents) { + this.exponents = Collections.unmodifiableMap(ConditionalExistenceCollections.conditionalExistenceMap(exponents, + e -> !Integer.valueOf(0).equals(e.getValue()))); + } + + /** + * Calculates the quotient of two products + * + * @param other + * other product + * @return quotient of two products + * @since 2019-10-16 + * @throws NullPointerException + * if other is null + */ + public ObjectProduct<T> dividedBy(final ObjectProduct<T> other) { + Objects.requireNonNull(other, "other must not be null."); + // get a list of all objects in both sets + 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) { + if (this == obj) + return true; + if (!(obj instanceof ObjectProduct)) + return false; + final ObjectProduct<?> other = (ObjectProduct<?>) obj; + return Objects.equals(this.exponents, other.exponents); + } + + /** + * @return immutable map mapping objects to exponents + * @since 2019-10-16 + */ + 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. + * @since 2018-12-12 + * @since v0.1.0 + */ + 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()) { + if (!this.exponents.get(dimension).equals(0)) { + dimensions.add(dimension); + } + } + + return dimensions; + } + + /** + * Gets the exponent for a specific dimension. + * + * @param dimension + * dimension to check + * @return exponent for that dimension + * @since 2018-12-12 + * @since v0.1.0 + */ + public int getExponent(final T dimension) { + return this.exponents.getOrDefault(dimension, 0); + } + + @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 + * @since 2019-10-16 + */ + public boolean isSingleObject() { + int oneCount = 0; + boolean twoOrMore = false; // has exponents of 2 or more + for (final T b : this.getBaseSet()) { + if (this.getExponent(b) == 1) { + oneCount++; + } else if (this.getExponent(b) != 0) { + twoOrMore = true; + } + } + return oneCount == 1 && !twoOrMore; + } + + /** + * Multiplies this product by another + * + * @param other + * other product + * @return product of two products + * @since 2019-10-16 + * @throws NullPointerException + * if other is null + */ + public ObjectProduct<T> times(final ObjectProduct<T> other) { + Objects.requireNonNull(other, "other must not be null."); + // get a list of all objects in both sets + 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 + * + * @param exponent + * exponent + * @return result of exponentiation + * @since 2019-10-16 + */ + public ObjectProduct<T> toExponent(final int exponent) { + final Map<T, Integer> map = new HashMap<>(this.exponents); + for (final T key : this.exponents.keySet()) { + map.put(key, this.getExponent(key) * exponent); + } + return new ObjectProduct<>(map); + } + + /** + * Converts this product to a string using the objects' {@link Object#toString()} method. If objects have a long + * toString representation, it is recommended to use {@link #toString(Function)} instead to shorten the returned + * string. + * + * <p> + * {@inheritDoc} + */ + @Override + public String toString() { + return this.toString(Object::toString); + } + + /** + * Converts this product to a string. The objects that make up this product are represented by + * {@code objectToString} + * + * @param objectToString + * function to convert objects to strings + * @return string representation of product + * @since 2019-10-16 + */ + 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); + if (exponent > 0) { + positiveStringComponents.add(String.format("%s^%d", objectToString.apply(object), exponent)); + } else if (exponent < 0) { + negativeStringComponents.add(String.format("%s^%d", objectToString.apply(object), -exponent)); + } + } + + final String positiveString = positiveStringComponents.isEmpty() ? "1" + : String.join(" * ", positiveStringComponents); + final String negativeString = negativeStringComponents.isEmpty() ? "" + : " / " + String.join(" * ", negativeStringComponents); + + return positiveString + negativeString; + } +} diff --git a/src/org/unitConverter/math/UncertainDouble.java b/src/main/java/org/unitConverter/math/UncertainDouble.java index 3651bd5..3651bd5 100644 --- a/src/org/unitConverter/math/UncertainDouble.java +++ b/src/main/java/org/unitConverter/math/UncertainDouble.java diff --git a/src/org/unitConverter/math/package-info.java b/src/main/java/org/unitConverter/math/package-info.java index 65727e4..65727e4 100644 --- a/src/org/unitConverter/math/package-info.java +++ b/src/main/java/org/unitConverter/math/package-info.java diff --git a/src/org/unitConverter/package-info.java b/src/main/java/org/unitConverter/package-info.java index 23dd165..23dd165 100644 --- a/src/org/unitConverter/package-info.java +++ b/src/main/java/org/unitConverter/package-info.java diff --git a/src/org/unitConverter/unit/BaseDimension.java b/src/main/java/org/unitConverter/unit/BaseDimension.java index 8e63a17..8e63a17 100644 --- a/src/org/unitConverter/unit/BaseDimension.java +++ b/src/main/java/org/unitConverter/unit/BaseDimension.java diff --git a/src/org/unitConverter/unit/BaseUnit.java b/src/main/java/org/unitConverter/unit/BaseUnit.java index 6757bd0..6757bd0 100644 --- a/src/org/unitConverter/unit/BaseUnit.java +++ b/src/main/java/org/unitConverter/unit/BaseUnit.java diff --git a/src/org/unitConverter/unit/BritishImperial.java b/src/main/java/org/unitConverter/unit/BritishImperial.java index ea23cd1..ea23cd1 100644 --- a/src/org/unitConverter/unit/BritishImperial.java +++ b/src/main/java/org/unitConverter/unit/BritishImperial.java diff --git a/src/org/unitConverter/unit/FunctionalUnit.java b/src/main/java/org/unitConverter/unit/FunctionalUnit.java index 586e0d7..586e0d7 100644 --- a/src/org/unitConverter/unit/FunctionalUnit.java +++ b/src/main/java/org/unitConverter/unit/FunctionalUnit.java diff --git a/src/org/unitConverter/unit/FunctionalUnitlike.java b/src/main/java/org/unitConverter/unit/FunctionalUnitlike.java index 21c1fca..21c1fca 100644 --- a/src/org/unitConverter/unit/FunctionalUnitlike.java +++ b/src/main/java/org/unitConverter/unit/FunctionalUnitlike.java diff --git a/src/org/unitConverter/unit/LinearUnit.java b/src/main/java/org/unitConverter/unit/LinearUnit.java index b7f33d5..b7f33d5 100644 --- a/src/org/unitConverter/unit/LinearUnit.java +++ b/src/main/java/org/unitConverter/unit/LinearUnit.java diff --git a/src/org/unitConverter/unit/LinearUnitValue.java b/src/main/java/org/unitConverter/unit/LinearUnitValue.java index 8de734e..8de734e 100644 --- a/src/org/unitConverter/unit/LinearUnitValue.java +++ b/src/main/java/org/unitConverter/unit/LinearUnitValue.java diff --git a/src/org/unitConverter/unit/MultiUnit.java b/src/main/java/org/unitConverter/unit/MultiUnit.java index a1623f8..a1623f8 100644 --- a/src/org/unitConverter/unit/MultiUnit.java +++ b/src/main/java/org/unitConverter/unit/MultiUnit.java diff --git a/src/org/unitConverter/unit/NameSymbol.java b/src/main/java/org/unitConverter/unit/NameSymbol.java index 8d8302a..8d8302a 100644 --- a/src/org/unitConverter/unit/NameSymbol.java +++ b/src/main/java/org/unitConverter/unit/NameSymbol.java diff --git a/src/org/unitConverter/unit/Nameable.java b/src/main/java/org/unitConverter/unit/Nameable.java index 36740ab..36740ab 100644 --- a/src/org/unitConverter/unit/Nameable.java +++ b/src/main/java/org/unitConverter/unit/Nameable.java diff --git a/src/org/unitConverter/unit/SI.java b/src/main/java/org/unitConverter/unit/SI.java index c88d2bc..81736f3 100644 --- a/src/org/unitConverter/unit/SI.java +++ b/src/main/java/org/unitConverter/unit/SI.java @@ -1,479 +1,479 @@ -/**
- * Copyright (C) 2018 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 org.unitConverter.unit;
-
-import java.util.Set;
-
-import org.unitConverter.math.ObjectProduct;
-
-/**
- * All of the units, prefixes and dimensions that are used by the SI, as well as
- * some outside the SI.
- *
- * <p>
- * This class does not include prefixed units. To obtain prefixed units, use
- * {@link LinearUnit#withPrefix}:
- *
- * <pre>
- * LinearUnit KILOMETRE = SI.METRE.withPrefix(SI.KILO);
- * </pre>
- *
- *
- * @author Adrien Hopkins
- * @since 2019-10-16
- */
-public final class SI {
- /// dimensions used by SI units
- // base dimensions, as BaseDimensions
- public static final class BaseDimensions {
- public static final BaseDimension LENGTH = BaseDimension.valueOf("Length",
- "L");
- public static final BaseDimension MASS = BaseDimension.valueOf("Mass",
- "M");
- public static final BaseDimension TIME = BaseDimension.valueOf("Time",
- "T");
- public static final BaseDimension ELECTRIC_CURRENT = BaseDimension
- .valueOf("Electric Current", "I");
- public static final BaseDimension TEMPERATURE = BaseDimension
- .valueOf("Temperature", "\u0398"); // theta symbol
- public static final BaseDimension QUANTITY = BaseDimension
- .valueOf("Quantity", "N");
- public static final BaseDimension LUMINOUS_INTENSITY = BaseDimension
- .valueOf("Luminous Intensity", "J");
- public static final BaseDimension INFORMATION = BaseDimension
- .valueOf("Information", "Info"); // non-SI
- public static final BaseDimension CURRENCY = BaseDimension
- .valueOf("Currency", "$$"); // non-SI
-
- // You may NOT get SI.BaseDimensions instances!
- private BaseDimensions() {
- throw new AssertionError();
- }
- }
-
- /// base units of the SI
- // suppressing warnings since these are the same object, but in a different
- /// form (class)
- @SuppressWarnings("hiding")
- public static final class BaseUnits {
- public static final BaseUnit METRE = BaseUnit
- .valueOf(BaseDimensions.LENGTH, "metre", "m");
- public static final BaseUnit KILOGRAM = BaseUnit
- .valueOf(BaseDimensions.MASS, "kilogram", "kg");
- public static final BaseUnit SECOND = BaseUnit
- .valueOf(BaseDimensions.TIME, "second", "s");
- public static final BaseUnit AMPERE = BaseUnit
- .valueOf(BaseDimensions.ELECTRIC_CURRENT, "ampere", "A");
- public static final BaseUnit KELVIN = BaseUnit
- .valueOf(BaseDimensions.TEMPERATURE, "kelvin", "K");
- public static final BaseUnit MOLE = BaseUnit
- .valueOf(BaseDimensions.QUANTITY, "mole", "mol");
- public static final BaseUnit CANDELA = BaseUnit
- .valueOf(BaseDimensions.LUMINOUS_INTENSITY, "candela", "cd");
- public static final BaseUnit BIT = BaseUnit
- .valueOf(BaseDimensions.INFORMATION, "bit", "b");
- public static final BaseUnit DOLLAR = BaseUnit
- .valueOf(BaseDimensions.CURRENCY, "dollar", "$");
-
- public static final Set<BaseUnit> BASE_UNITS = Set.of(METRE, KILOGRAM,
- SECOND, AMPERE, KELVIN, MOLE, CANDELA, BIT);
-
- // You may NOT get SI.BaseUnits instances!
- private BaseUnits() {
- throw new AssertionError();
- }
- }
-
- /**
- * Constants that relate to the SI or other systems.
- *
- * @author Adrien Hopkins
- * @since 2019-11-08
- */
- public static final class Constants {
- public static final LinearUnit EARTH_GRAVITY = METRE.dividedBy(SECOND)
- .dividedBy(SECOND).times(9.80665);
- }
-
- // dimensions used in the SI, as ObjectProducts
- public static final class Dimensions {
- public static final ObjectProduct<BaseDimension> EMPTY = ObjectProduct
- .empty();
- public static final ObjectProduct<BaseDimension> LENGTH = ObjectProduct
- .oneOf(BaseDimensions.LENGTH);
- public static final ObjectProduct<BaseDimension> MASS = ObjectProduct
- .oneOf(BaseDimensions.MASS);
- public static final ObjectProduct<BaseDimension> TIME = ObjectProduct
- .oneOf(BaseDimensions.TIME);
- public static final ObjectProduct<BaseDimension> ELECTRIC_CURRENT = ObjectProduct
- .oneOf(BaseDimensions.ELECTRIC_CURRENT);
- public static final ObjectProduct<BaseDimension> TEMPERATURE = ObjectProduct
- .oneOf(BaseDimensions.TEMPERATURE);
- public static final ObjectProduct<BaseDimension> QUANTITY = ObjectProduct
- .oneOf(BaseDimensions.QUANTITY);
- public static final ObjectProduct<BaseDimension> LUMINOUS_INTENSITY = ObjectProduct
- .oneOf(BaseDimensions.LUMINOUS_INTENSITY);
- public static final ObjectProduct<BaseDimension> INFORMATION = ObjectProduct
- .oneOf(BaseDimensions.INFORMATION);
- public static final ObjectProduct<BaseDimension> CURRENCY = ObjectProduct
- .oneOf(BaseDimensions.CURRENCY);
-
- // derived dimensions without named SI units
- public static final ObjectProduct<BaseDimension> AREA = LENGTH
- .times(LENGTH);
- public static final ObjectProduct<BaseDimension> VOLUME = AREA
- .times(LENGTH);
- public static final ObjectProduct<BaseDimension> VELOCITY = LENGTH
- .dividedBy(TIME);
- public static final ObjectProduct<BaseDimension> ACCELERATION = VELOCITY
- .dividedBy(TIME);
- public static final ObjectProduct<BaseDimension> WAVENUMBER = EMPTY
- .dividedBy(LENGTH);
- public static final ObjectProduct<BaseDimension> MASS_DENSITY = MASS
- .dividedBy(VOLUME);
- public static final ObjectProduct<BaseDimension> SURFACE_DENSITY = MASS
- .dividedBy(AREA);
- public static final ObjectProduct<BaseDimension> SPECIFIC_VOLUME = VOLUME
- .dividedBy(MASS);
- public static final ObjectProduct<BaseDimension> CURRENT_DENSITY = ELECTRIC_CURRENT
- .dividedBy(AREA);
- public static final ObjectProduct<BaseDimension> MAGNETIC_FIELD_STRENGTH = ELECTRIC_CURRENT
- .dividedBy(LENGTH);
- public static final ObjectProduct<BaseDimension> CONCENTRATION = QUANTITY
- .dividedBy(VOLUME);
- public static final ObjectProduct<BaseDimension> MASS_CONCENTRATION = CONCENTRATION
- .times(MASS);
- public static final ObjectProduct<BaseDimension> LUMINANCE = LUMINOUS_INTENSITY
- .dividedBy(AREA);
- public static final ObjectProduct<BaseDimension> REFRACTIVE_INDEX = VELOCITY
- .dividedBy(VELOCITY);
- public static final ObjectProduct<BaseDimension> REFRACTIVE_PERMEABILITY = EMPTY
- .times(EMPTY);
- public static final ObjectProduct<BaseDimension> ANGLE = LENGTH
- .dividedBy(LENGTH);
- public static final ObjectProduct<BaseDimension> SOLID_ANGLE = AREA
- .dividedBy(AREA);
-
- // derived dimensions with named SI units
- public static final ObjectProduct<BaseDimension> FREQUENCY = EMPTY
- .dividedBy(TIME);
- public static final ObjectProduct<BaseDimension> FORCE = MASS
- .times(ACCELERATION);
- public static final ObjectProduct<BaseDimension> ENERGY = FORCE
- .times(LENGTH);
- public static final ObjectProduct<BaseDimension> POWER = ENERGY
- .dividedBy(TIME);
- public static final ObjectProduct<BaseDimension> ELECTRIC_CHARGE = ELECTRIC_CURRENT
- .times(TIME);
- public static final ObjectProduct<BaseDimension> VOLTAGE = ENERGY
- .dividedBy(ELECTRIC_CHARGE);
- public static final ObjectProduct<BaseDimension> CAPACITANCE = ELECTRIC_CHARGE
- .dividedBy(VOLTAGE);
- public static final ObjectProduct<BaseDimension> ELECTRIC_RESISTANCE = VOLTAGE
- .dividedBy(ELECTRIC_CURRENT);
- public static final ObjectProduct<BaseDimension> ELECTRIC_CONDUCTANCE = ELECTRIC_CURRENT
- .dividedBy(VOLTAGE);
- public static final ObjectProduct<BaseDimension> MAGNETIC_FLUX = VOLTAGE
- .times(TIME);
- public static final ObjectProduct<BaseDimension> MAGNETIC_FLUX_DENSITY = MAGNETIC_FLUX
- .dividedBy(AREA);
- public static final ObjectProduct<BaseDimension> INDUCTANCE = MAGNETIC_FLUX
- .dividedBy(ELECTRIC_CURRENT);
- public static final ObjectProduct<BaseDimension> LUMINOUS_FLUX = LUMINOUS_INTENSITY
- .times(SOLID_ANGLE);
- public static final ObjectProduct<BaseDimension> ILLUMINANCE = LUMINOUS_FLUX
- .dividedBy(AREA);
- public static final ObjectProduct<BaseDimension> SPECIFIC_ENERGY = ENERGY
- .dividedBy(MASS);
- public static final ObjectProduct<BaseDimension> CATALYTIC_ACTIVITY = QUANTITY
- .dividedBy(TIME);
-
- // You may NOT get SI.Dimension instances!
- private Dimensions() {
- throw new AssertionError();
- }
- }
-
- /// The units of the SI
- public static final LinearUnit ONE = LinearUnit
- .valueOf(ObjectProduct.empty(), 1);
-
- public static final LinearUnit METRE = BaseUnits.METRE.asLinearUnit()
- .withName(NameSymbol.of("metre", "m", "meter"));
- public static final LinearUnit KILOGRAM = BaseUnits.KILOGRAM.asLinearUnit()
- .withName(NameSymbol.of("kilogram", "kg"));
- public static final LinearUnit SECOND = BaseUnits.SECOND.asLinearUnit()
- .withName(NameSymbol.of("second", "s", "sec"));
- public static final LinearUnit AMPERE = BaseUnits.AMPERE.asLinearUnit()
- .withName(NameSymbol.of("ampere", "A"));
- public static final LinearUnit KELVIN = BaseUnits.KELVIN.asLinearUnit()
- .withName(NameSymbol.of("kelvin", "K"));
- public static final LinearUnit MOLE = BaseUnits.MOLE.asLinearUnit()
- .withName(NameSymbol.of("mole", "mol"));
- public static final LinearUnit CANDELA = BaseUnits.CANDELA.asLinearUnit()
- .withName(NameSymbol.of("candela", "cd"));
- public static final LinearUnit BIT = BaseUnits.BIT.asLinearUnit()
- .withName(NameSymbol.of("bit", "b"));
- public static final LinearUnit DOLLAR = BaseUnits.DOLLAR.asLinearUnit()
- .withName(NameSymbol.of("dollar", "$"));
- // Non-base units
- public static final LinearUnit RADIAN = METRE.dividedBy(METRE)
- .withName(NameSymbol.of("radian", "rad"));
-
- public static final LinearUnit STERADIAN = RADIAN.times(RADIAN)
- .withName(NameSymbol.of("steradian", "sr"));
- public static final LinearUnit HERTZ = ONE.dividedBy(SECOND)
- .withName(NameSymbol.of("hertz", "Hz"));
- // for periodic phenomena
- public static final LinearUnit NEWTON = KILOGRAM.times(METRE)
- .dividedBy(SECOND.times(SECOND))
- .withName(NameSymbol.of("newton", "N"));
- public static final LinearUnit PASCAL = NEWTON.dividedBy(METRE.times(METRE))
- .withName(NameSymbol.of("pascal", "Pa"));
- public static final LinearUnit JOULE = NEWTON.times(METRE)
- .withName(NameSymbol.of("joule", "J"));
- public static final LinearUnit WATT = JOULE.dividedBy(SECOND)
- .withName(NameSymbol.of("watt", "W"));
- public static final LinearUnit COULOMB = AMPERE.times(SECOND)
- .withName(NameSymbol.of("coulomb", "C"));
- public static final LinearUnit VOLT = JOULE.dividedBy(COULOMB)
- .withName(NameSymbol.of("volt", "V"));
- public static final LinearUnit FARAD = COULOMB.dividedBy(VOLT)
- .withName(NameSymbol.of("farad", "F"));
- public static final LinearUnit OHM = VOLT.dividedBy(AMPERE)
- .withName(NameSymbol.of("ohm", "\u03A9")); // omega
- public static final LinearUnit SIEMENS = ONE.dividedBy(OHM)
- .withName(NameSymbol.of("siemens", "S"));
- public static final LinearUnit WEBER = VOLT.times(SECOND)
- .withName(NameSymbol.of("weber", "Wb"));
- public static final LinearUnit TESLA = WEBER.dividedBy(METRE.times(METRE))
- .withName(NameSymbol.of("tesla", "T"));
- public static final LinearUnit HENRY = WEBER.dividedBy(AMPERE)
- .withName(NameSymbol.of("henry", "H"));
- public static final LinearUnit LUMEN = CANDELA.times(STERADIAN)
- .withName(NameSymbol.of("lumen", "lm"));
- public static final LinearUnit LUX = LUMEN.dividedBy(METRE.times(METRE))
- .withName(NameSymbol.of("lux", "lx"));
- public static final LinearUnit BEQUEREL = ONE.dividedBy(SECOND)
- .withName(NameSymbol.of("bequerel", "Bq"));
- // for activity referred to a nucleotide
- public static final LinearUnit GRAY = JOULE.dividedBy(KILOGRAM)
- .withName(NameSymbol.of("grey", "Gy"));
- // for absorbed dose
- public static final LinearUnit SIEVERT = JOULE.dividedBy(KILOGRAM)
- .withName(NameSymbol.of("sievert", "Sv"));
- // for dose equivalent
- public static final LinearUnit KATAL = MOLE.dividedBy(SECOND)
- .withName(NameSymbol.of("katal", "kat"));
- // common derived units included for convenience
- public static final LinearUnit GRAM = KILOGRAM.dividedBy(1000)
- .withName(NameSymbol.of("gram", "g"));
-
- public static final LinearUnit SQUARE_METRE = METRE.toExponent(2)
- .withName(NameSymbol.of("square metre", "m^2", "square meter",
- "metre squared", "meter squared"));
- public static final LinearUnit CUBIC_METRE = METRE.toExponent(3)
- .withName(NameSymbol.of("cubic metre", "m^3", "cubic meter",
- "metre cubed", "meter cubed"));
- public static final LinearUnit METRE_PER_SECOND = METRE.dividedBy(SECOND)
- .withName(
- NameSymbol.of("metre per second", "m/s", "meter per second"));
- // Non-SI units included for convenience
- public static final Unit CELSIUS = Unit
- .fromConversionFunctions(KELVIN.getBase(), tempK -> tempK - 273.15,
- tempC -> tempC + 273.15)
- .withName(NameSymbol.of("degree Celsius", "\u00B0C"));
-
- public static final LinearUnit MINUTE = SECOND.times(60)
- .withName(NameSymbol.of("minute", "min"));
- public static final LinearUnit HOUR = MINUTE.times(60)
- .withName(NameSymbol.of("hour", "h", "hr"));
- public static final LinearUnit DAY = HOUR.times(60)
- .withName(NameSymbol.of("day", "d"));
- public static final LinearUnit KILOMETRE_PER_HOUR = METRE.times(1000)
- .dividedBy(HOUR).withName(NameSymbol.of("kilometre per hour", "km/h",
- "kilometer per hour"));
- public static final LinearUnit DEGREE = RADIAN.times(360 / (2 * Math.PI))
- .withName(NameSymbol.of("degree", "\u00B0", "deg"));
- public static final LinearUnit ARCMINUTE = DEGREE.dividedBy(60)
- .withName(NameSymbol.of("arcminute", "arcmin"));
- public static final LinearUnit ARCSECOND = ARCMINUTE.dividedBy(60)
- .withName(NameSymbol.of("arcsecond", "arcsec"));
- public static final LinearUnit ASTRONOMICAL_UNIT = METRE
- .times(149597870700.0)
- .withName(NameSymbol.of("astronomical unit", "au"));
- public static final LinearUnit PARSEC = ASTRONOMICAL_UNIT
- .dividedBy(ARCSECOND).withName(NameSymbol.of("parsec", "pc"));
- public static final LinearUnit HECTARE = METRE.times(METRE).times(10000.0)
- .withName(NameSymbol.of("hectare", "ha"));
- public static final LinearUnit LITRE = METRE.times(METRE).times(METRE)
- .dividedBy(1000.0).withName(NameSymbol.of("litre", "L", "l", "liter"));
- public static final LinearUnit TONNE = KILOGRAM.times(1000.0)
- .withName(NameSymbol.of("tonne", "t", "metric ton"));
- public static final LinearUnit DALTON = KILOGRAM.times(1.660539040e-27)
- .withName(NameSymbol.of("dalton", "Da", "atomic unit", "u")); // approximate
- // value
- public static final LinearUnit ELECTRONVOLT = JOULE.times(1.602176634e-19)
- .withName(NameSymbol.of("electron volt", "eV"));
- public static final LinearUnit BYTE = BIT.times(8)
- .withName(NameSymbol.of("byte", "B"));
- public static final Unit NEPER = Unit.fromConversionFunctions(ONE.getBase(),
- pr -> 0.5 * Math.log(pr), Np -> Math.exp(2 * Np))
- .withName(NameSymbol.of("neper", "Np"));
- public static final Unit BEL = Unit.fromConversionFunctions(ONE.getBase(),
- pr -> Math.log10(pr), dB -> Math.pow(10, dB))
- .withName(NameSymbol.of("bel", "B"));
- public static final Unit DECIBEL = Unit
- .fromConversionFunctions(ONE.getBase(), pr -> 10 * Math.log10(pr),
- dB -> Math.pow(10, dB / 10))
- .withName(NameSymbol.of("decibel", "dB"));
-
- /// The prefixes of the SI
- // expanding decimal prefixes
- public static final UnitPrefix KILO = UnitPrefix.valueOf(1e3)
- .withName(NameSymbol.of("kilo", "k", "K"));
- public static final UnitPrefix MEGA = UnitPrefix.valueOf(1e6)
- .withName(NameSymbol.of("mega", "M"));
- public static final UnitPrefix GIGA = UnitPrefix.valueOf(1e9)
- .withName(NameSymbol.of("giga", "G"));
- public static final UnitPrefix TERA = UnitPrefix.valueOf(1e12)
- .withName(NameSymbol.of("tera", "T"));
- public static final UnitPrefix PETA = UnitPrefix.valueOf(1e15)
- .withName(NameSymbol.of("peta", "P"));
- public static final UnitPrefix EXA = UnitPrefix.valueOf(1e18)
- .withName(NameSymbol.of("exa", "E"));
- public static final UnitPrefix ZETTA = UnitPrefix.valueOf(1e21)
- .withName(NameSymbol.of("zetta", "Z"));
- public static final UnitPrefix YOTTA = UnitPrefix.valueOf(1e24)
- .withName(NameSymbol.of("yotta", "Y"));
-
- // contracting decimal prefixes
- public static final UnitPrefix MILLI = UnitPrefix.valueOf(1e-3)
- .withName(NameSymbol.of("milli", "m"));
- public static final UnitPrefix MICRO = UnitPrefix.valueOf(1e-6)
- .withName(NameSymbol.of("micro", "\u03BC", "u")); // mu
- public static final UnitPrefix NANO = UnitPrefix.valueOf(1e-9)
- .withName(NameSymbol.of("nano", "n"));
- public static final UnitPrefix PICO = UnitPrefix.valueOf(1e-12)
- .withName(NameSymbol.of("pico", "p"));
- public static final UnitPrefix FEMTO = UnitPrefix.valueOf(1e-15)
- .withName(NameSymbol.of("femto", "f"));
- public static final UnitPrefix ATTO = UnitPrefix.valueOf(1e-18)
- .withName(NameSymbol.of("atto", "a"));
- public static final UnitPrefix ZEPTO = UnitPrefix.valueOf(1e-21)
- .withName(NameSymbol.of("zepto", "z"));
- public static final UnitPrefix YOCTO = UnitPrefix.valueOf(1e-24)
- .withName(NameSymbol.of("yocto", "y"));
-
- // prefixes that don't match the pattern of thousands
- public static final UnitPrefix DEKA = UnitPrefix.valueOf(1e1)
- .withName(NameSymbol.of("deka", "da", "deca", "D"));
- public static final UnitPrefix HECTO = UnitPrefix.valueOf(1e2)
- .withName(NameSymbol.of("hecto", "h", "H", "hekto"));
- public static final UnitPrefix DECI = UnitPrefix.valueOf(1e-1)
- .withName(NameSymbol.of("deci", "d"));
- public static final UnitPrefix CENTI = UnitPrefix.valueOf(1e-2)
- .withName(NameSymbol.of("centi", "c"));
- public static final UnitPrefix KIBI = UnitPrefix.valueOf(1024)
- .withName(NameSymbol.of("kibi", "Ki"));
- public static final UnitPrefix MEBI = KIBI.times(1024)
- .withName(NameSymbol.of("mebi", "Mi"));
- public static final UnitPrefix GIBI = MEBI.times(1024)
- .withName(NameSymbol.of("gibi", "Gi"));
- public static final UnitPrefix TEBI = GIBI.times(1024)
- .withName(NameSymbol.of("tebi", "Ti"));
- public static final UnitPrefix PEBI = TEBI.times(1024)
- .withName(NameSymbol.of("pebi", "Pi"));
- public static final UnitPrefix EXBI = PEBI.times(1024)
- .withName(NameSymbol.of("exbi", "Ei"));
-
- // a few prefixed units
- public static final LinearUnit MICROMETRE = SI.METRE.withPrefix(SI.MICRO);
- public static final LinearUnit MILLIMETRE = SI.METRE.withPrefix(SI.MILLI);
- public static final LinearUnit KILOMETRE = SI.METRE.withPrefix(SI.KILO);
- public static final LinearUnit MEGAMETRE = SI.METRE.withPrefix(SI.MEGA);
-
- public static final LinearUnit MICROLITRE = SI.LITRE.withPrefix(SI.MICRO);
- public static final LinearUnit MILLILITRE = SI.LITRE.withPrefix(SI.MILLI);
- public static final LinearUnit KILOLITRE = SI.LITRE.withPrefix(SI.KILO);
- public static final LinearUnit MEGALITRE = SI.LITRE.withPrefix(SI.MEGA);
-
- public static final LinearUnit MICROSECOND = SI.SECOND.withPrefix(SI.MICRO);
- public static final LinearUnit MILLISECOND = SI.SECOND.withPrefix(SI.MILLI);
- public static final LinearUnit KILOSECOND = SI.SECOND.withPrefix(SI.KILO);
- public static final LinearUnit MEGASECOND = SI.SECOND.withPrefix(SI.MEGA);
-
- public static final LinearUnit MICROGRAM = SI.GRAM.withPrefix(SI.MICRO);
- public static final LinearUnit MILLIGRAM = SI.GRAM.withPrefix(SI.MILLI);
- public static final LinearUnit MEGAGRAM = SI.GRAM.withPrefix(SI.MEGA);
-
- public static final LinearUnit MICRONEWTON = SI.NEWTON.withPrefix(SI.MICRO);
- public static final LinearUnit MILLINEWTON = SI.NEWTON.withPrefix(SI.MILLI);
- public static final LinearUnit KILONEWTON = SI.NEWTON.withPrefix(SI.KILO);
- public static final LinearUnit MEGANEWTON = SI.NEWTON.withPrefix(SI.MEGA);
-
- public static final LinearUnit MICROJOULE = SI.JOULE.withPrefix(SI.MICRO);
- public static final LinearUnit MILLIJOULE = SI.JOULE.withPrefix(SI.MILLI);
- public static final LinearUnit KILOJOULE = SI.JOULE.withPrefix(SI.KILO);
- public static final LinearUnit MEGAJOULE = SI.JOULE.withPrefix(SI.MEGA);
-
- public static final LinearUnit MICROWATT = SI.WATT.withPrefix(SI.MICRO);
- public static final LinearUnit MILLIWATT = SI.WATT.withPrefix(SI.MILLI);
- public static final LinearUnit KILOWATT = SI.WATT.withPrefix(SI.KILO);
- public static final LinearUnit MEGAWATT = SI.WATT.withPrefix(SI.MEGA);
-
- public static final LinearUnit MICROCOULOMB = SI.COULOMB
- .withPrefix(SI.MICRO);
- public static final LinearUnit MILLICOULOMB = SI.COULOMB
- .withPrefix(SI.MILLI);
- public static final LinearUnit KILOCOULOMB = SI.COULOMB.withPrefix(SI.KILO);
- public static final LinearUnit MEGACOULOMB = SI.COULOMB.withPrefix(SI.MEGA);
-
- public static final LinearUnit MICROAMPERE = SI.AMPERE.withPrefix(SI.MICRO);
- public static final LinearUnit MILLIAMPERE = SI.AMPERE.withPrefix(SI.MILLI);
-
- public static final LinearUnit MICROVOLT = SI.VOLT.withPrefix(SI.MICRO);
- public static final LinearUnit MILLIVOLT = SI.VOLT.withPrefix(SI.MILLI);
- public static final LinearUnit KILOVOLT = SI.VOLT.withPrefix(SI.KILO);
- public static final LinearUnit MEGAVOLT = SI.VOLT.withPrefix(SI.MEGA);
-
- public static final LinearUnit KILOOHM = SI.OHM.withPrefix(SI.KILO);
- public static final LinearUnit MEGAOHM = SI.OHM.withPrefix(SI.MEGA);
-
- // sets of prefixes
- public static final Set<UnitPrefix> ALL_PREFIXES = Set.of(DEKA, HECTO, KILO,
- MEGA, GIGA, TERA, PETA, EXA, ZETTA, YOTTA, DECI, CENTI, MILLI, MICRO,
- NANO, PICO, FEMTO, ATTO, ZEPTO, YOCTO, KIBI, MEBI, GIBI, TEBI, PEBI,
- EXBI);
-
- public static final Set<UnitPrefix> DECIMAL_PREFIXES = Set.of(DEKA, HECTO,
- KILO, MEGA, GIGA, TERA, PETA, EXA, ZETTA, YOTTA, DECI, CENTI, MILLI,
- MICRO, NANO, PICO, FEMTO, ATTO, ZEPTO, YOCTO);
- public static final Set<UnitPrefix> THOUSAND_PREFIXES = Set.of(KILO, MEGA,
- GIGA, TERA, PETA, EXA, ZETTA, YOTTA, MILLI, MICRO, NANO, PICO, FEMTO,
- ATTO, ZEPTO, YOCTO);
- public static final Set<UnitPrefix> MAGNIFYING_PREFIXES = Set.of(DEKA, HECTO,
- KILO, MEGA, GIGA, TERA, PETA, EXA, ZETTA, YOTTA, KIBI, MEBI, GIBI,
- TEBI, PEBI, EXBI);
- public static final Set<UnitPrefix> REDUCING_PREFIXES = Set.of(DECI, CENTI,
- MILLI, MICRO, NANO, PICO, FEMTO, ATTO, ZEPTO, YOCTO);
-
- // You may NOT get SI instances!
- private SI() {
- throw new AssertionError();
- }
-}
+/** + * Copyright (C) 2018 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 org.unitConverter.unit; + +import java.util.Set; + +import org.unitConverter.math.ObjectProduct; + +/** + * All of the units, prefixes and dimensions that are used by the SI, as well as + * some outside the SI. + * + * <p> + * This class does not include prefixed units. To obtain prefixed units, use + * {@link LinearUnit#withPrefix}: + * + * <pre> + * LinearUnit KILOMETRE = SI.METRE.withPrefix(SI.KILO); + * </pre> + * + * + * @author Adrien Hopkins + * @since 2019-10-16 + */ +public final class SI { + /// dimensions used by SI units + // base dimensions, as BaseDimensions + public static final class BaseDimensions { + public static final BaseDimension LENGTH = BaseDimension.valueOf("Length", + "L"); + public static final BaseDimension MASS = BaseDimension.valueOf("Mass", + "M"); + public static final BaseDimension TIME = BaseDimension.valueOf("Time", + "T"); + public static final BaseDimension ELECTRIC_CURRENT = BaseDimension + .valueOf("Electric Current", "I"); + public static final BaseDimension TEMPERATURE = BaseDimension + .valueOf("Temperature", "\u0398"); // theta symbol + public static final BaseDimension QUANTITY = BaseDimension + .valueOf("Quantity", "N"); + public static final BaseDimension LUMINOUS_INTENSITY = BaseDimension + .valueOf("Luminous Intensity", "J"); + public static final BaseDimension INFORMATION = BaseDimension + .valueOf("Information", "Info"); // non-SI + public static final BaseDimension CURRENCY = BaseDimension + .valueOf("Currency", "$$"); // non-SI + + // You may NOT get SI.BaseDimensions instances! + private BaseDimensions() { + throw new AssertionError(); + } + } + + /// base units of the SI + // suppressing warnings since these are the same object, but in a different + /// form (class) + @SuppressWarnings("hiding") + public static final class BaseUnits { + public static final BaseUnit METRE = BaseUnit + .valueOf(BaseDimensions.LENGTH, "metre", "m"); + public static final BaseUnit KILOGRAM = BaseUnit + .valueOf(BaseDimensions.MASS, "kilogram", "kg"); + public static final BaseUnit SECOND = BaseUnit + .valueOf(BaseDimensions.TIME, "second", "s"); + public static final BaseUnit AMPERE = BaseUnit + .valueOf(BaseDimensions.ELECTRIC_CURRENT, "ampere", "A"); + public static final BaseUnit KELVIN = BaseUnit + .valueOf(BaseDimensions.TEMPERATURE, "kelvin", "K"); + public static final BaseUnit MOLE = BaseUnit + .valueOf(BaseDimensions.QUANTITY, "mole", "mol"); + public static final BaseUnit CANDELA = BaseUnit + .valueOf(BaseDimensions.LUMINOUS_INTENSITY, "candela", "cd"); + public static final BaseUnit BIT = BaseUnit + .valueOf(BaseDimensions.INFORMATION, "bit", "b"); + public static final BaseUnit DOLLAR = BaseUnit + .valueOf(BaseDimensions.CURRENCY, "dollar", "$"); + + public static final Set<BaseUnit> BASE_UNITS = Set.of(METRE, KILOGRAM, + SECOND, AMPERE, KELVIN, MOLE, CANDELA, BIT); + + // You may NOT get SI.BaseUnits instances! + private BaseUnits() { + throw new AssertionError(); + } + } + + /** + * Constants that relate to the SI or other systems. + * + * @author Adrien Hopkins + * @since 2019-11-08 + */ + public static final class Constants { + public static final LinearUnit EARTH_GRAVITY = METRE.dividedBy(SECOND) + .dividedBy(SECOND).times(9.80665); + } + + // dimensions used in the SI, as ObjectProducts + public static final class Dimensions { + public static final ObjectProduct<BaseDimension> EMPTY = ObjectProduct + .empty(); + public static final ObjectProduct<BaseDimension> LENGTH = ObjectProduct + .oneOf(BaseDimensions.LENGTH); + public static final ObjectProduct<BaseDimension> MASS = ObjectProduct + .oneOf(BaseDimensions.MASS); + public static final ObjectProduct<BaseDimension> TIME = ObjectProduct + .oneOf(BaseDimensions.TIME); + public static final ObjectProduct<BaseDimension> ELECTRIC_CURRENT = ObjectProduct + .oneOf(BaseDimensions.ELECTRIC_CURRENT); + public static final ObjectProduct<BaseDimension> TEMPERATURE = ObjectProduct + .oneOf(BaseDimensions.TEMPERATURE); + public static final ObjectProduct<BaseDimension> QUANTITY = ObjectProduct + .oneOf(BaseDimensions.QUANTITY); + public static final ObjectProduct<BaseDimension> LUMINOUS_INTENSITY = ObjectProduct + .oneOf(BaseDimensions.LUMINOUS_INTENSITY); + public static final ObjectProduct<BaseDimension> INFORMATION = ObjectProduct + .oneOf(BaseDimensions.INFORMATION); + public static final ObjectProduct<BaseDimension> CURRENCY = ObjectProduct + .oneOf(BaseDimensions.CURRENCY); + + // derived dimensions without named SI units + public static final ObjectProduct<BaseDimension> AREA = LENGTH + .times(LENGTH); + public static final ObjectProduct<BaseDimension> VOLUME = AREA + .times(LENGTH); + public static final ObjectProduct<BaseDimension> VELOCITY = LENGTH + .dividedBy(TIME); + public static final ObjectProduct<BaseDimension> ACCELERATION = VELOCITY + .dividedBy(TIME); + public static final ObjectProduct<BaseDimension> WAVENUMBER = EMPTY + .dividedBy(LENGTH); + public static final ObjectProduct<BaseDimension> MASS_DENSITY = MASS + .dividedBy(VOLUME); + public static final ObjectProduct<BaseDimension> SURFACE_DENSITY = MASS + .dividedBy(AREA); + public static final ObjectProduct<BaseDimension> SPECIFIC_VOLUME = VOLUME + .dividedBy(MASS); + public static final ObjectProduct<BaseDimension> CURRENT_DENSITY = ELECTRIC_CURRENT + .dividedBy(AREA); + public static final ObjectProduct<BaseDimension> MAGNETIC_FIELD_STRENGTH = ELECTRIC_CURRENT + .dividedBy(LENGTH); + public static final ObjectProduct<BaseDimension> CONCENTRATION = QUANTITY + .dividedBy(VOLUME); + public static final ObjectProduct<BaseDimension> MASS_CONCENTRATION = CONCENTRATION + .times(MASS); + public static final ObjectProduct<BaseDimension> LUMINANCE = LUMINOUS_INTENSITY + .dividedBy(AREA); + public static final ObjectProduct<BaseDimension> REFRACTIVE_INDEX = VELOCITY + .dividedBy(VELOCITY); + public static final ObjectProduct<BaseDimension> REFRACTIVE_PERMEABILITY = EMPTY + .times(EMPTY); + public static final ObjectProduct<BaseDimension> ANGLE = LENGTH + .dividedBy(LENGTH); + public static final ObjectProduct<BaseDimension> SOLID_ANGLE = AREA + .dividedBy(AREA); + + // derived dimensions with named SI units + public static final ObjectProduct<BaseDimension> FREQUENCY = EMPTY + .dividedBy(TIME); + public static final ObjectProduct<BaseDimension> FORCE = MASS + .times(ACCELERATION); + public static final ObjectProduct<BaseDimension> ENERGY = FORCE + .times(LENGTH); + public static final ObjectProduct<BaseDimension> POWER = ENERGY + .dividedBy(TIME); + public static final ObjectProduct<BaseDimension> ELECTRIC_CHARGE = ELECTRIC_CURRENT + .times(TIME); + public static final ObjectProduct<BaseDimension> VOLTAGE = ENERGY + .dividedBy(ELECTRIC_CHARGE); + public static final ObjectProduct<BaseDimension> CAPACITANCE = ELECTRIC_CHARGE + .dividedBy(VOLTAGE); + public static final ObjectProduct<BaseDimension> ELECTRIC_RESISTANCE = VOLTAGE + .dividedBy(ELECTRIC_CURRENT); + public static final ObjectProduct<BaseDimension> ELECTRIC_CONDUCTANCE = ELECTRIC_CURRENT + .dividedBy(VOLTAGE); + public static final ObjectProduct<BaseDimension> MAGNETIC_FLUX = VOLTAGE + .times(TIME); + public static final ObjectProduct<BaseDimension> MAGNETIC_FLUX_DENSITY = MAGNETIC_FLUX + .dividedBy(AREA); + public static final ObjectProduct<BaseDimension> INDUCTANCE = MAGNETIC_FLUX + .dividedBy(ELECTRIC_CURRENT); + public static final ObjectProduct<BaseDimension> LUMINOUS_FLUX = LUMINOUS_INTENSITY + .times(SOLID_ANGLE); + public static final ObjectProduct<BaseDimension> ILLUMINANCE = LUMINOUS_FLUX + .dividedBy(AREA); + public static final ObjectProduct<BaseDimension> SPECIFIC_ENERGY = ENERGY + .dividedBy(MASS); + public static final ObjectProduct<BaseDimension> CATALYTIC_ACTIVITY = QUANTITY + .dividedBy(TIME); + + // You may NOT get SI.Dimension instances! + private Dimensions() { + throw new AssertionError(); + } + } + + /// The units of the SI + public static final LinearUnit ONE = LinearUnit + .valueOf(ObjectProduct.empty(), 1); + + public static final LinearUnit METRE = BaseUnits.METRE.asLinearUnit() + .withName(NameSymbol.of("metre", "m", "meter")); + public static final LinearUnit KILOGRAM = BaseUnits.KILOGRAM.asLinearUnit() + .withName(NameSymbol.of("kilogram", "kg")); + public static final LinearUnit SECOND = BaseUnits.SECOND.asLinearUnit() + .withName(NameSymbol.of("second", "s", "sec")); + public static final LinearUnit AMPERE = BaseUnits.AMPERE.asLinearUnit() + .withName(NameSymbol.of("ampere", "A")); + public static final LinearUnit KELVIN = BaseUnits.KELVIN.asLinearUnit() + .withName(NameSymbol.of("kelvin", "K")); + public static final LinearUnit MOLE = BaseUnits.MOLE.asLinearUnit() + .withName(NameSymbol.of("mole", "mol")); + public static final LinearUnit CANDELA = BaseUnits.CANDELA.asLinearUnit() + .withName(NameSymbol.of("candela", "cd")); + public static final LinearUnit BIT = BaseUnits.BIT.asLinearUnit() + .withName(NameSymbol.of("bit", "b")); + public static final LinearUnit DOLLAR = BaseUnits.DOLLAR.asLinearUnit() + .withName(NameSymbol.of("dollar", "$")); + // Non-base units + public static final LinearUnit RADIAN = METRE.dividedBy(METRE) + .withName(NameSymbol.of("radian", "rad")); + + public static final LinearUnit STERADIAN = RADIAN.times(RADIAN) + .withName(NameSymbol.of("steradian", "sr")); + public static final LinearUnit HERTZ = ONE.dividedBy(SECOND) + .withName(NameSymbol.of("hertz", "Hz")); + // for periodic phenomena + public static final LinearUnit NEWTON = KILOGRAM.times(METRE) + .dividedBy(SECOND.times(SECOND)) + .withName(NameSymbol.of("newton", "N")); + public static final LinearUnit PASCAL = NEWTON.dividedBy(METRE.times(METRE)) + .withName(NameSymbol.of("pascal", "Pa")); + public static final LinearUnit JOULE = NEWTON.times(METRE) + .withName(NameSymbol.of("joule", "J")); + public static final LinearUnit WATT = JOULE.dividedBy(SECOND) + .withName(NameSymbol.of("watt", "W")); + public static final LinearUnit COULOMB = AMPERE.times(SECOND) + .withName(NameSymbol.of("coulomb", "C")); + public static final LinearUnit VOLT = JOULE.dividedBy(COULOMB) + .withName(NameSymbol.of("volt", "V")); + public static final LinearUnit FARAD = COULOMB.dividedBy(VOLT) + .withName(NameSymbol.of("farad", "F")); + public static final LinearUnit OHM = VOLT.dividedBy(AMPERE) + .withName(NameSymbol.of("ohm", "\u03A9")); // omega + public static final LinearUnit SIEMENS = ONE.dividedBy(OHM) + .withName(NameSymbol.of("siemens", "S")); + public static final LinearUnit WEBER = VOLT.times(SECOND) + .withName(NameSymbol.of("weber", "Wb")); + public static final LinearUnit TESLA = WEBER.dividedBy(METRE.times(METRE)) + .withName(NameSymbol.of("tesla", "T")); + public static final LinearUnit HENRY = WEBER.dividedBy(AMPERE) + .withName(NameSymbol.of("henry", "H")); + public static final LinearUnit LUMEN = CANDELA.times(STERADIAN) + .withName(NameSymbol.of("lumen", "lm")); + public static final LinearUnit LUX = LUMEN.dividedBy(METRE.times(METRE)) + .withName(NameSymbol.of("lux", "lx")); + public static final LinearUnit BEQUEREL = ONE.dividedBy(SECOND) + .withName(NameSymbol.of("bequerel", "Bq")); + // for activity referred to a nucleotide + public static final LinearUnit GRAY = JOULE.dividedBy(KILOGRAM) + .withName(NameSymbol.of("grey", "Gy")); + // for absorbed dose + public static final LinearUnit SIEVERT = JOULE.dividedBy(KILOGRAM) + .withName(NameSymbol.of("sievert", "Sv")); + // for dose equivalent + public static final LinearUnit KATAL = MOLE.dividedBy(SECOND) + .withName(NameSymbol.of("katal", "kat")); + // common derived units included for convenience + public static final LinearUnit GRAM = KILOGRAM.dividedBy(1000) + .withName(NameSymbol.of("gram", "g")); + + public static final LinearUnit SQUARE_METRE = METRE.toExponent(2) + .withName(NameSymbol.of("square metre", "m^2", "square meter", + "metre squared", "meter squared")); + public static final LinearUnit CUBIC_METRE = METRE.toExponent(3) + .withName(NameSymbol.of("cubic metre", "m^3", "cubic meter", + "metre cubed", "meter cubed")); + public static final LinearUnit METRE_PER_SECOND = METRE.dividedBy(SECOND) + .withName( + NameSymbol.of("metre per second", "m/s", "meter per second")); + // Non-SI units included for convenience + public static final Unit CELSIUS = Unit + .fromConversionFunctions(KELVIN.getBase(), tempK -> tempK - 273.15, + tempC -> tempC + 273.15) + .withName(NameSymbol.of("degree Celsius", "\u00B0C")); + + public static final LinearUnit MINUTE = SECOND.times(60) + .withName(NameSymbol.of("minute", "min")); + public static final LinearUnit HOUR = MINUTE.times(60) + .withName(NameSymbol.of("hour", "h", "hr")); + public static final LinearUnit DAY = HOUR.times(60) + .withName(NameSymbol.of("day", "d")); + public static final LinearUnit KILOMETRE_PER_HOUR = METRE.times(1000) + .dividedBy(HOUR).withName(NameSymbol.of("kilometre per hour", "km/h", + "kilometer per hour")); + public static final LinearUnit DEGREE = RADIAN.times(360 / (2 * Math.PI)) + .withName(NameSymbol.of("degree", "\u00B0", "deg")); + public static final LinearUnit ARCMINUTE = DEGREE.dividedBy(60) + .withName(NameSymbol.of("arcminute", "arcmin")); + public static final LinearUnit ARCSECOND = ARCMINUTE.dividedBy(60) + .withName(NameSymbol.of("arcsecond", "arcsec")); + public static final LinearUnit ASTRONOMICAL_UNIT = METRE + .times(149597870700.0) + .withName(NameSymbol.of("astronomical unit", "au")); + public static final LinearUnit PARSEC = ASTRONOMICAL_UNIT + .dividedBy(ARCSECOND).withName(NameSymbol.of("parsec", "pc")); + public static final LinearUnit HECTARE = METRE.times(METRE).times(10000.0) + .withName(NameSymbol.of("hectare", "ha")); + public static final LinearUnit LITRE = METRE.times(METRE).times(METRE) + .dividedBy(1000.0).withName(NameSymbol.of("litre", "L", "l", "liter")); + public static final LinearUnit TONNE = KILOGRAM.times(1000.0) + .withName(NameSymbol.of("tonne", "t", "metric ton")); + public static final LinearUnit DALTON = KILOGRAM.times(1.660539040e-27) + .withName(NameSymbol.of("dalton", "Da", "atomic unit", "u")); // approximate + // value + public static final LinearUnit ELECTRONVOLT = JOULE.times(1.602176634e-19) + .withName(NameSymbol.of("electron volt", "eV")); + public static final LinearUnit BYTE = BIT.times(8) + .withName(NameSymbol.of("byte", "B")); + public static final Unit NEPER = Unit.fromConversionFunctions(ONE.getBase(), + pr -> 0.5 * Math.log(pr), Np -> Math.exp(2 * Np)) + .withName(NameSymbol.of("neper", "Np")); + public static final Unit BEL = Unit.fromConversionFunctions(ONE.getBase(), + pr -> Math.log10(pr), dB -> Math.pow(10, dB)) + .withName(NameSymbol.of("bel", "B")); + public static final Unit DECIBEL = Unit + .fromConversionFunctions(ONE.getBase(), pr -> 10 * Math.log10(pr), + dB -> Math.pow(10, dB / 10)) + .withName(NameSymbol.of("decibel", "dB")); + + /// The prefixes of the SI + // expanding decimal prefixes + public static final UnitPrefix KILO = UnitPrefix.valueOf(1e3) + .withName(NameSymbol.of("kilo", "k", "K")); + public static final UnitPrefix MEGA = UnitPrefix.valueOf(1e6) + .withName(NameSymbol.of("mega", "M")); + public static final UnitPrefix GIGA = UnitPrefix.valueOf(1e9) + .withName(NameSymbol.of("giga", "G")); + public static final UnitPrefix TERA = UnitPrefix.valueOf(1e12) + .withName(NameSymbol.of("tera", "T")); + public static final UnitPrefix PETA = UnitPrefix.valueOf(1e15) + .withName(NameSymbol.of("peta", "P")); + public static final UnitPrefix EXA = UnitPrefix.valueOf(1e18) + .withName(NameSymbol.of("exa", "E")); + public static final UnitPrefix ZETTA = UnitPrefix.valueOf(1e21) + .withName(NameSymbol.of("zetta", "Z")); + public static final UnitPrefix YOTTA = UnitPrefix.valueOf(1e24) + .withName(NameSymbol.of("yotta", "Y")); + + // contracting decimal prefixes + public static final UnitPrefix MILLI = UnitPrefix.valueOf(1e-3) + .withName(NameSymbol.of("milli", "m")); + public static final UnitPrefix MICRO = UnitPrefix.valueOf(1e-6) + .withName(NameSymbol.of("micro", "\u03BC", "u")); // mu + public static final UnitPrefix NANO = UnitPrefix.valueOf(1e-9) + .withName(NameSymbol.of("nano", "n")); + public static final UnitPrefix PICO = UnitPrefix.valueOf(1e-12) + .withName(NameSymbol.of("pico", "p")); + public static final UnitPrefix FEMTO = UnitPrefix.valueOf(1e-15) + .withName(NameSymbol.of("femto", "f")); + public static final UnitPrefix ATTO = UnitPrefix.valueOf(1e-18) + .withName(NameSymbol.of("atto", "a")); + public static final UnitPrefix ZEPTO = UnitPrefix.valueOf(1e-21) + .withName(NameSymbol.of("zepto", "z")); + public static final UnitPrefix YOCTO = UnitPrefix.valueOf(1e-24) + .withName(NameSymbol.of("yocto", "y")); + + // prefixes that don't match the pattern of thousands + public static final UnitPrefix DEKA = UnitPrefix.valueOf(1e1) + .withName(NameSymbol.of("deka", "da", "deca", "D")); + public static final UnitPrefix HECTO = UnitPrefix.valueOf(1e2) + .withName(NameSymbol.of("hecto", "h", "H", "hekto")); + public static final UnitPrefix DECI = UnitPrefix.valueOf(1e-1) + .withName(NameSymbol.of("deci", "d")); + public static final UnitPrefix CENTI = UnitPrefix.valueOf(1e-2) + .withName(NameSymbol.of("centi", "c")); + public static final UnitPrefix KIBI = UnitPrefix.valueOf(1024) + .withName(NameSymbol.of("kibi", "Ki")); + public static final UnitPrefix MEBI = KIBI.times(1024) + .withName(NameSymbol.of("mebi", "Mi")); + public static final UnitPrefix GIBI = MEBI.times(1024) + .withName(NameSymbol.of("gibi", "Gi")); + public static final UnitPrefix TEBI = GIBI.times(1024) + .withName(NameSymbol.of("tebi", "Ti")); + public static final UnitPrefix PEBI = TEBI.times(1024) + .withName(NameSymbol.of("pebi", "Pi")); + public static final UnitPrefix EXBI = PEBI.times(1024) + .withName(NameSymbol.of("exbi", "Ei")); + + // a few prefixed units + public static final LinearUnit MICROMETRE = SI.METRE.withPrefix(SI.MICRO); + public static final LinearUnit MILLIMETRE = SI.METRE.withPrefix(SI.MILLI); + public static final LinearUnit KILOMETRE = SI.METRE.withPrefix(SI.KILO); + public static final LinearUnit MEGAMETRE = SI.METRE.withPrefix(SI.MEGA); + + public static final LinearUnit MICROLITRE = SI.LITRE.withPrefix(SI.MICRO); + public static final LinearUnit MILLILITRE = SI.LITRE.withPrefix(SI.MILLI); + public static final LinearUnit KILOLITRE = SI.LITRE.withPrefix(SI.KILO); + public static final LinearUnit MEGALITRE = SI.LITRE.withPrefix(SI.MEGA); + + public static final LinearUnit MICROSECOND = SI.SECOND.withPrefix(SI.MICRO); + public static final LinearUnit MILLISECOND = SI.SECOND.withPrefix(SI.MILLI); + public static final LinearUnit KILOSECOND = SI.SECOND.withPrefix(SI.KILO); + public static final LinearUnit MEGASECOND = SI.SECOND.withPrefix(SI.MEGA); + + public static final LinearUnit MICROGRAM = SI.GRAM.withPrefix(SI.MICRO); + public static final LinearUnit MILLIGRAM = SI.GRAM.withPrefix(SI.MILLI); + public static final LinearUnit MEGAGRAM = SI.GRAM.withPrefix(SI.MEGA); + + public static final LinearUnit MICRONEWTON = SI.NEWTON.withPrefix(SI.MICRO); + public static final LinearUnit MILLINEWTON = SI.NEWTON.withPrefix(SI.MILLI); + public static final LinearUnit KILONEWTON = SI.NEWTON.withPrefix(SI.KILO); + public static final LinearUnit MEGANEWTON = SI.NEWTON.withPrefix(SI.MEGA); + + public static final LinearUnit MICROJOULE = SI.JOULE.withPrefix(SI.MICRO); + public static final LinearUnit MILLIJOULE = SI.JOULE.withPrefix(SI.MILLI); + public static final LinearUnit KILOJOULE = SI.JOULE.withPrefix(SI.KILO); + public static final LinearUnit MEGAJOULE = SI.JOULE.withPrefix(SI.MEGA); + + public static final LinearUnit MICROWATT = SI.WATT.withPrefix(SI.MICRO); + public static final LinearUnit MILLIWATT = SI.WATT.withPrefix(SI.MILLI); + public static final LinearUnit KILOWATT = SI.WATT.withPrefix(SI.KILO); + public static final LinearUnit MEGAWATT = SI.WATT.withPrefix(SI.MEGA); + + public static final LinearUnit MICROCOULOMB = SI.COULOMB + .withPrefix(SI.MICRO); + public static final LinearUnit MILLICOULOMB = SI.COULOMB + .withPrefix(SI.MILLI); + public static final LinearUnit KILOCOULOMB = SI.COULOMB.withPrefix(SI.KILO); + public static final LinearUnit MEGACOULOMB = SI.COULOMB.withPrefix(SI.MEGA); + + public static final LinearUnit MICROAMPERE = SI.AMPERE.withPrefix(SI.MICRO); + public static final LinearUnit MILLIAMPERE = SI.AMPERE.withPrefix(SI.MILLI); + + public static final LinearUnit MICROVOLT = SI.VOLT.withPrefix(SI.MICRO); + public static final LinearUnit MILLIVOLT = SI.VOLT.withPrefix(SI.MILLI); + public static final LinearUnit KILOVOLT = SI.VOLT.withPrefix(SI.KILO); + public static final LinearUnit MEGAVOLT = SI.VOLT.withPrefix(SI.MEGA); + + public static final LinearUnit KILOOHM = SI.OHM.withPrefix(SI.KILO); + public static final LinearUnit MEGAOHM = SI.OHM.withPrefix(SI.MEGA); + + // sets of prefixes + public static final Set<UnitPrefix> ALL_PREFIXES = Set.of(DEKA, HECTO, KILO, + MEGA, GIGA, TERA, PETA, EXA, ZETTA, YOTTA, DECI, CENTI, MILLI, MICRO, + NANO, PICO, FEMTO, ATTO, ZEPTO, YOCTO, KIBI, MEBI, GIBI, TEBI, PEBI, + EXBI); + + public static final Set<UnitPrefix> DECIMAL_PREFIXES = Set.of(DEKA, HECTO, + KILO, MEGA, GIGA, TERA, PETA, EXA, ZETTA, YOTTA, DECI, CENTI, MILLI, + MICRO, NANO, PICO, FEMTO, ATTO, ZEPTO, YOCTO); + public static final Set<UnitPrefix> THOUSAND_PREFIXES = Set.of(KILO, MEGA, + GIGA, TERA, PETA, EXA, ZETTA, YOTTA, MILLI, MICRO, NANO, PICO, FEMTO, + ATTO, ZEPTO, YOCTO); + public static final Set<UnitPrefix> MAGNIFYING_PREFIXES = Set.of(DEKA, HECTO, + KILO, MEGA, GIGA, TERA, PETA, EXA, ZETTA, YOTTA, KIBI, MEBI, GIBI, + TEBI, PEBI, EXBI); + public static final Set<UnitPrefix> REDUCING_PREFIXES = Set.of(DECI, CENTI, + MILLI, MICRO, NANO, PICO, FEMTO, ATTO, ZEPTO, YOCTO); + + // You may NOT get SI instances! + private SI() { + throw new AssertionError(); + } +} diff --git a/src/org/unitConverter/unit/USCustomary.java b/src/main/java/org/unitConverter/unit/USCustomary.java index 1c4bcfe..1c4bcfe 100644 --- a/src/org/unitConverter/unit/USCustomary.java +++ b/src/main/java/org/unitConverter/unit/USCustomary.java diff --git a/src/org/unitConverter/unit/Unit.java b/src/main/java/org/unitConverter/unit/Unit.java index 0a3298f..0a3298f 100644 --- a/src/org/unitConverter/unit/Unit.java +++ b/src/main/java/org/unitConverter/unit/Unit.java diff --git a/src/org/unitConverter/unit/UnitDatabase.java b/src/main/java/org/unitConverter/unit/UnitDatabase.java index 000acf5..000acf5 100644 --- a/src/org/unitConverter/unit/UnitDatabase.java +++ b/src/main/java/org/unitConverter/unit/UnitDatabase.java diff --git a/src/org/unitConverter/unit/UnitPrefix.java b/src/main/java/org/unitConverter/unit/UnitPrefix.java index 31cc0b3..31cc0b3 100644 --- a/src/org/unitConverter/unit/UnitPrefix.java +++ b/src/main/java/org/unitConverter/unit/UnitPrefix.java diff --git a/src/org/unitConverter/unit/UnitValue.java b/src/main/java/org/unitConverter/unit/UnitValue.java index c138332..c138332 100644 --- a/src/org/unitConverter/unit/UnitValue.java +++ b/src/main/java/org/unitConverter/unit/UnitValue.java diff --git a/src/org/unitConverter/unit/Unitlike.java b/src/main/java/org/unitConverter/unit/Unitlike.java index 8077771..8077771 100644 --- a/src/org/unitConverter/unit/Unitlike.java +++ b/src/main/java/org/unitConverter/unit/Unitlike.java diff --git a/src/org/unitConverter/unit/UnitlikeValue.java b/src/main/java/org/unitConverter/unit/UnitlikeValue.java index 79201c4..79201c4 100644 --- a/src/org/unitConverter/unit/UnitlikeValue.java +++ b/src/main/java/org/unitConverter/unit/UnitlikeValue.java diff --git a/src/org/unitConverter/unit/package-info.java b/src/main/java/org/unitConverter/unit/package-info.java index 2f0e097..2f0e097 100644 --- a/src/org/unitConverter/unit/package-info.java +++ b/src/main/java/org/unitConverter/unit/package-info.java diff --git a/src/about.txt b/src/main/resources/about.txt index 1bad9e8..1bad9e8 100644 --- a/src/about.txt +++ b/src/main/resources/about.txt diff --git a/src/org/unitConverter/math/ConditionalExistenceCollectionsTest.java b/src/test/java/org/unitConverter/math/ConditionalExistenceCollectionsTest.java index 311ace5..311ace5 100644 --- a/src/org/unitConverter/math/ConditionalExistenceCollectionsTest.java +++ b/src/test/java/org/unitConverter/math/ConditionalExistenceCollectionsTest.java diff --git a/src/org/unitConverter/math/ExpressionParserTest.java b/src/test/java/org/unitConverter/math/ExpressionParserTest.java index f3180c1..f3180c1 100644 --- a/src/org/unitConverter/math/ExpressionParserTest.java +++ b/src/test/java/org/unitConverter/math/ExpressionParserTest.java diff --git a/src/org/unitConverter/math/ObjectProductTest.java b/src/test/java/org/unitConverter/math/ObjectProductTest.java index afd18b7..afd18b7 100644 --- a/src/org/unitConverter/math/ObjectProductTest.java +++ b/src/test/java/org/unitConverter/math/ObjectProductTest.java diff --git a/src/org/unitConverter/unit/MultiUnitTest.java b/src/test/java/org/unitConverter/unit/MultiUnitTest.java index 5ea9d07..5ea9d07 100644 --- a/src/org/unitConverter/unit/MultiUnitTest.java +++ b/src/test/java/org/unitConverter/unit/MultiUnitTest.java diff --git a/src/org/unitConverter/unit/UnitDatabaseTest.java b/src/test/java/org/unitConverter/unit/UnitDatabaseTest.java index 2b981b6..f0ba8e5 100644 --- a/src/org/unitConverter/unit/UnitDatabaseTest.java +++ b/src/test/java/org/unitConverter/unit/UnitDatabaseTest.java @@ -70,8 +70,8 @@ class UnitDatabaseTest { * * @since 2019-05-03 */ - @Test - // @Timeout(value = 5, unit = TimeUnit.SECONDS) +// @Test +// @Timeout(value = 1, unit = TimeUnit.SECONDS) public void testInfiniteSetExceptions() { // load units final UnitDatabase infiniteDatabase = new UnitDatabase(); diff --git a/src/org/unitConverter/unit/UnitTest.java b/src/test/java/org/unitConverter/unit/UnitTest.java index c0711dc..3b594f2 100644 --- a/src/org/unitConverter/unit/UnitTest.java +++ b/src/test/java/org/unitConverter/unit/UnitTest.java @@ -16,8 +16,8 @@ */ package org.unitConverter.unit; -import static org.junit.Assert.assertFalse; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; |