From b19d10e204f97e599864befee0bb0a0a6bf31968 Mon Sep 17 00:00:00 2001 From: Werner Keil Date: Tue, 17 Nov 2020 01:29:00 +0100 Subject: [PATCH] 216: Update Spec Task-Url: https://github.com/unitsofmeasurement/unit-api/issues/216 --- pom.xml | 1 - .../java/tech/units/indriya/AbstractUnit.java | 59 ++++--------- .../units/indriya/ComparableQuantity.java | 4 +- .../tech/units/indriya/ComparableUnit.java | 86 ------------------- .../tech/units/indriya/MeasurementError.java | 45 ---------- .../indriya/format/DefaultFormatService.java | 12 --- .../tech/units/indriya/unit/PrefixTest.java | 10 +-- 7 files changed, 26 insertions(+), 191 deletions(-) delete mode 100644 src/main/java/tech/units/indriya/ComparableUnit.java delete mode 100644 src/main/java/tech/units/indriya/MeasurementError.java diff --git a/pom.xml b/pom.xml index 29fa2756..e948160e 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,6 @@ uom-parent 2.1 - 2.1.1-SNAPSHOT https://github.com/unitsofmeasurement/indriya.git diff --git a/src/main/java/tech/units/indriya/AbstractUnit.java b/src/main/java/tech/units/indriya/AbstractUnit.java index 3c1401c8..a9a626ed 100644 --- a/src/main/java/tech/units/indriya/AbstractUnit.java +++ b/src/main/java/tech/units/indriya/AbstractUnit.java @@ -83,11 +83,11 @@ * International System of Units * @author Jean-Marie Dautelle * @author Werner Keil - * @version 2.4, December 14, 2019 + * @version 3.0, November 16, 2020 * @since 1.0 */ public abstract class AbstractUnit> - implements ComparableUnit, Nameable, PrefixOperator, SymbolSupplier { + implements Unit, Comparable>, PrefixOperator, Nameable, SymbolSupplier { /** * @@ -153,12 +153,20 @@ protected Type getActualType() { * * @return equals(toSystemUnit()) */ - @Override public boolean isSystemUnit() { Unit sys = this.toSystemUnit(); return this == sys || this.equals(sys); } - + + /** + * Returns the converter from this unit to its unscaled {@link #toSystemUnit + * System Unit} unit. + * + * @return getConverterTo(this.toSystemUnit()) + * @see #toSystemUnit + */ + public abstract UnitConverter getSystemConverter(); + /** * Returns the unscaled {@link SI} unit from which this unit is derived. * @@ -271,11 +279,11 @@ public final boolean isCompatible(Unit that) { */ @SuppressWarnings("unchecked") @Override - public final > ComparableUnit asType(Class type) { + public final > Unit asType(Class type) { Dimension typeDimension = UnitDimension.of(type); if (typeDimension != null && !typeDimension.equals(this.getDimension())) throw new ClassCastException("The unit: " + this + " is not compatible with quantities of type " + type); - return (ComparableUnit) this; + return (Unit) this; } @Override @@ -310,7 +318,7 @@ public final UnitConverter getConverterTo(Unit that) throws UnconvertibleExce public final UnitConverter getConverterToAny(Unit that) throws IncommensurableException, UnconvertibleException { if (!isCompatible(that)) throw new IncommensurableException(this + " is not compatible with " + that); - ComparableUnit thatAbstr = (ComparableUnit) that; // Since both units are + AbstractUnit thatAbstr = (AbstractUnit) that; // Since both units are // compatible they must both be abstract units. final DimensionalModel model = DimensionalModel.current(); Unit thisSystemUnit = this.getSystemUnit(); @@ -379,7 +387,7 @@ private final boolean internalIsCompatible(Unit that, boolean checkEquals) { if (this == that) return true; } - if (!(that instanceof ComparableUnit)) + if (!(that instanceof Unit)) return false; Dimension thisDimension = this.getDimension(); Dimension thatDimension = that.getDimension(); @@ -414,32 +422,13 @@ protected final UnitConverter internalGetConverterTo(Unit that, boolean useEq return thatToSI.inverse().concatenate(thisToSI); } - /** - * Returns the product of this unit with the one specified. - * - *

- * Note: If the specified unit (that) is not a physical unit, then - * that.multiply(this) is returned. - *

- * - * @param that the unit multiplicand. - * @return this * that - */ - @Override - public final Unit multiply(Unit that) { - if (that instanceof ComparableUnit) - return multiply((ComparableUnit) that); - // return that.multiply(this); // Commutatif. - return ProductUnit.ofProduct(this, that); - } - /** * Returns the product of this physical unit with the one specified. * * @param that the physical unit multiplicand. * @return this * that */ - protected final Unit multiply(ComparableUnit that) { + public final Unit multiply(Unit that) { if (this.equals(ONE)) return that; if (that.equals(ONE)) @@ -491,16 +480,6 @@ public final Unit divide(Unit that) { return this.multiply(that.inverse()); } - /** - * Returns the quotient of this physical unit with the one specified. - * - * @param that the physical unit divisor. - * @return this.multiply(that.inverse()) - */ - protected final Unit divide(ComparableUnit that) { - return this.multiply(that.inverse()); - } - /** * Returns a unit equals to the given root of this unit. * @@ -594,8 +573,8 @@ protected static final class Equalizer { * @return true if this and obj are * considered equal; falseotherwise. */ - public static boolean areEqual(@SuppressWarnings("rawtypes") ComparableUnit u1, - @SuppressWarnings("rawtypes") ComparableUnit u2) { + public static boolean areEqual(@SuppressWarnings("rawtypes") Unit u1, + @SuppressWarnings("rawtypes") Unit u2) { /* * if (u1 != null && u2 != null) { if (u1.getName() != null && u1.getSymbol() != * null) { return u1.getName().equals(u2.getName()) && diff --git a/src/main/java/tech/units/indriya/ComparableQuantity.java b/src/main/java/tech/units/indriya/ComparableQuantity.java index c86d6321..4bfa85c2 100644 --- a/src/main/java/tech/units/indriya/ComparableQuantity.java +++ b/src/main/java/tech/units/indriya/ComparableQuantity.java @@ -37,7 +37,7 @@ import tech.uom.lib.common.function.QuantityConverter; /** - * Quantity that adapts Comparables to the {@link Quantity} interface. + * Quantity that adapts Comparable to the {@link Quantity} interface. * For use in other quantities, when supposed to work on Comparables. * * It extends {@link Quantity} with {@linkplain Comparable} and {@linkplain Serializable } @@ -46,7 +46,7 @@ * @author otaviojava * @author werner * @param - * @version 2.1, September 28, 2020 + * @version 2.2, November 16, 2020 * @since 1.0 */ public interface ComparableQuantity> extends Quantity, Comparable>, QuantityConverter, Serializable { diff --git a/src/main/java/tech/units/indriya/ComparableUnit.java b/src/main/java/tech/units/indriya/ComparableUnit.java deleted file mode 100644 index ec3f54c5..00000000 --- a/src/main/java/tech/units/indriya/ComparableUnit.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Units of Measurement Reference Implementation - * Copyright (c) 2005-2020, Jean-Marie Dautelle, Werner Keil, Otavio Santana. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions - * and the following disclaimer in the documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of JSR-385, Indriya nor the names of their contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package tech.units.indriya; - -import java.io.Serializable; - -import javax.measure.Quantity; -import javax.measure.Unit; -import javax.measure.UnitConverter; - -/** - * Unit specialized for the Java SE platform. It extends {@link Unit} with - * {@linkplain Comparable} and {@linkplain Serializable } - * - * @see {@link Unit} - * @author werner - * @param - * @version 1.6, September 27, 2020 - * @since 1.0.9 - * @deprecated should be split between Unit and AbstractUnit - */ -public interface ComparableUnit> extends Unit, Comparable>, Serializable { - - /** - * Compares two instances of {@code Unit}, doing the conversion of unit if necessary. - * - * @param that the {@code Unit} to be compared with this instance. - * @return {@code true} if {@code that < this}. - * @throws NullPointerException if the unit is null - * - * @see Cambridge Dictionary: equivalent - * @see LEXICO: equivalent - */ - boolean isEquivalentTo(Unit that); - - /** - * Indicates if this unit belongs to the set of coherent SI units (unscaled SI - * units). - * - * The base and coherent derived units of the SI form a coherent set, designated - * the set of coherent SI units. The word coherent is used here in the following - * sense: when coherent units are used, equations between the numerical values - * of quantities take exactly the same form as the equations between the - * quantities themselves. Thus if only units from a coherent set are used, - * conversion factors between units are never required. - * - * @return equals(toSystemUnit()) - */ - boolean isSystemUnit(); - - /** - * Returns the converter from this unit to its unscaled {@link #toSystemUnit - * System Unit} unit. - * - * @return getConverterTo(this.toSystemUnit()) - * @see #toSystemUnit - */ - UnitConverter getSystemConverter(); -} diff --git a/src/main/java/tech/units/indriya/MeasurementError.java b/src/main/java/tech/units/indriya/MeasurementError.java deleted file mode 100644 index f04c8867..00000000 --- a/src/main/java/tech/units/indriya/MeasurementError.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Units of Measurement Reference Implementation - * Copyright (c) 2005-2020, Jean-Marie Dautelle, Werner Keil, Otavio Santana. - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions - * and the following disclaimer in the documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of JSR-385, Indriya nor the names of their contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package tech.units.indriya; - - -/** - * This error is used to indicate problems with creating, retrieving and manipulating units of measurement objects. - *

- * - * implSpec This class is intended for use in a single thread. Exception thrown when errors occur during Units of Measurement operations. - * - * @author Werner Keil - * @version 1.1, Sep 26, 2020 - * @since 2.0.2 - * @deprecated Use javax.measure.MeasurementError - */ -public class MeasurementError extends javax.measure.MeasurementError { -} diff --git a/src/main/java/tech/units/indriya/format/DefaultFormatService.java b/src/main/java/tech/units/indriya/format/DefaultFormatService.java index 45f51561..7770382a 100644 --- a/src/main/java/tech/units/indriya/format/DefaultFormatService.java +++ b/src/main/java/tech/units/indriya/format/DefaultFormatService.java @@ -129,18 +129,6 @@ public int getPriority() { return PRIO; } - /** - * Returns the unit format having the specified name or {@code null} if none. - * - * For example {@code getUnitFormat("Simple")} to return a simple {@link UnitFormat} implementation.
- * The variant is an arbitrary value to allow a variation of a UnitFormat, for example case sensitive vs. case insensitive UCUM format. - *

If no variant is applicable, the UnitFormat matching the name only is returned.

- * - * @param name - * the name of the format. - * @param variant Any arbitrary value used to indicate a variation of a UnitFormat. - * @return the corresponding unit format. - */ @Override public UnitFormat getUnitFormat(String name, String variant) { return getUnitFormat(name); diff --git a/src/test/java/tech/units/indriya/unit/PrefixTest.java b/src/test/java/tech/units/indriya/unit/PrefixTest.java index 94cd4db2..36c6ccdb 100644 --- a/src/test/java/tech/units/indriya/unit/PrefixTest.java +++ b/src/test/java/tech/units/indriya/unit/PrefixTest.java @@ -72,7 +72,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import tech.units.indriya.ComparableUnit; +import tech.units.indriya.AbstractUnit; import tech.units.indriya.function.RationalNumber; import tech.units.indriya.quantity.Quantities; @@ -186,8 +186,8 @@ public void testEquals() { @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testEquivalence() { - final ComparableUnit a = (ComparableUnit) MICRO(GRAM); - final ComparableUnit b = (ComparableUnit) GRAM.divide(1_000_000); + final AbstractUnit a = (AbstractUnit) MICRO(GRAM); + final AbstractUnit b = (AbstractUnit) GRAM.divide(1_000_000); assertEquals(true, a.isEquivalentTo(b)); assertEquals(true, b.isEquivalentTo(a)); } @@ -205,8 +205,8 @@ public void testNestedOperationsShouldBeSame() { @Test public void testNestedEquivalence() { - ComparableUnit a = (ComparableUnit) MICRO(GRAM); - ComparableUnit b = (ComparableUnit) GRAM.divide(1000).divide(1000); + AbstractUnit a = (AbstractUnit) MICRO(GRAM); + AbstractUnit b = (AbstractUnit) GRAM.divide(1000).divide(1000); assertEquals(true, a.isEquivalentTo(b)); assertEquals(true, b.isEquivalentTo(a)); }