From b19d10e204f97e599864befee0bb0a0a6bf31968 Mon Sep 17 00:00:00 2001
From: Werner Keil
- * Note: If the specified unit (that) is not a physical unit, then
- * >
- implements ComparableUnit
, Nameable, PrefixOperator
, SymbolSupplier {
+ implements Unit
, Comparable
, 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 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.
- *
- *
that.multiply(this)
is returned.
- * 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; false
otherwise.
*/
- 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
, 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
}, 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.
- *
UnitFormat
, for example case sensitive
vs. case insensitive
UCUM format.
- * If no variant is applicable, the UnitFormat
matching the name only is returned.
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