Skip to content

Commit

Permalink
216: Update Spec
Browse files Browse the repository at this point in the history
  • Loading branch information
keilw committed Nov 17, 2020
1 parent b3a6d29 commit b19d10e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 191 deletions.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<artifactId>uom-parent</artifactId>
<version>2.1</version>
</parent>
<version>2.1.1-SNAPSHOT</version>

<scm>
<url>https://github.com/unitsofmeasurement/indriya.git</url>
Expand Down
59 changes: 19 additions & 40 deletions src/main/java/tech/units/indriya/AbstractUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@
* International System of Units</a>
* @author <a href="mailto:[email protected]">Jean-Marie Dautelle</a>
* @author <a href="mailto:[email protected]">Werner Keil</a>
* @version 2.4, December 14, 2019
* @version 3.0, November 16, 2020
* @since 1.0
*/
public abstract class AbstractUnit<Q extends Quantity<Q>>
implements ComparableUnit<Q>, Nameable, PrefixOperator<Q>, SymbolSupplier {
implements Unit<Q>, Comparable<Unit<Q>>, PrefixOperator<Q>, Nameable, SymbolSupplier {

/**
*
Expand Down Expand Up @@ -153,12 +153,20 @@ protected Type getActualType() {
*
* @return <code>equals(toSystemUnit())</code>
*/
@Override
public boolean isSystemUnit() {
Unit<Q> sys = this.toSystemUnit();
return this == sys || this.equals(sys);
}


/**
* Returns the converter from this unit to its unscaled {@link #toSystemUnit
* System Unit} unit.
*
* @return <code>getConverterTo(this.toSystemUnit())</code>
* @see #toSystemUnit
*/
public abstract UnitConverter getSystemConverter();

/**
* Returns the unscaled {@link SI} unit from which this unit is derived.
*
Expand Down Expand Up @@ -271,11 +279,11 @@ public final boolean isCompatible(Unit<?> that) {
*/
@SuppressWarnings("unchecked")
@Override
public final <T extends Quantity<T>> ComparableUnit<T> asType(Class<T> type) {
public final <T extends Quantity<T>> Unit<T> asType(Class<T> 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<T>) this;
return (Unit<T>) this;
}

@Override
Expand Down Expand Up @@ -310,7 +318,7 @@ public final UnitConverter getConverterTo(Unit<Q> 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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -414,32 +422,13 @@ protected final UnitConverter internalGetConverterTo(Unit<Q> that, boolean useEq
return thatToSI.inverse().concatenate(thisToSI);
}

/**
* Returns the product of this unit with the one specified.
*
* <p>
* Note: If the specified unit (that) is not a physical unit, then
* <code>that.multiply(this)</code> is returned.
* </p>
*
* @param that the unit multiplicand.
* @return <code>this * that</code>
*/
@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 <code>this * that</code>
*/
protected final Unit<?> multiply(ComparableUnit<?> that) {
public final Unit<?> multiply(Unit<?> that) {
if (this.equals(ONE))
return that;
if (that.equals(ONE))
Expand Down Expand Up @@ -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 <code>this.multiply(that.inverse())</code>
*/
protected final Unit<?> divide(ComparableUnit<?> that) {
return this.multiply(that.inverse());
}

/**
* Returns a unit equals to the given root of this unit.
*
Expand Down Expand Up @@ -594,8 +573,8 @@ protected static final class Equalizer {
* @return <code>true</code> if <code>this</code> and <code>obj</code> are
* considered equal; <code>false</code>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()) &&
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tech/units/indriya/ComparableQuantity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -46,7 +46,7 @@
* @author otaviojava
* @author werner
* @param <Q>
* @version 2.1, September 28, 2020
* @version 2.2, November 16, 2020
* @since 1.0
*/
public interface ComparableQuantity<Q extends Quantity<Q>> extends Quantity<Q>, Comparable<Quantity<Q>>, QuantityConverter<Q>, Serializable {
Expand Down
86 changes: 0 additions & 86 deletions src/main/java/tech/units/indriya/ComparableUnit.java

This file was deleted.

45 changes: 0 additions & 45 deletions src/main/java/tech/units/indriya/MeasurementError.java

This file was deleted.

12 changes: 0 additions & 12 deletions src/main/java/tech/units/indriya/format/DefaultFormatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br>
* The variant is an arbitrary value to allow a variation of a <code>UnitFormat</code>, for example <code>case sensitive</code> vs. <code>case insensitive</code> <a href="https://ucum.org/ucum.html">UCUM</a> format.
* <p>If no variant is applicable, the <code>UnitFormat</code> matching the name only is returned.</p>
*
* @param name
* the name of the format.
* @param variant Any arbitrary value used to indicate a variation of a <code>UnitFormat</code>.
* @return the corresponding unit format.
*/
@Override
public UnitFormat getUnitFormat(String name, String variant) {
return getUnitFormat(name);
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/tech/units/indriya/unit/PrefixTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
Expand All @@ -205,8 +205,8 @@ public void testNestedOperationsShouldBeSame() {

@Test
public void testNestedEquivalence() {
ComparableUnit<Mass> a = (ComparableUnit<Mass>) MICRO(GRAM);
ComparableUnit<Mass> b = (ComparableUnit<Mass>) GRAM.divide(1000).divide(1000);
AbstractUnit<Mass> a = (AbstractUnit<Mass>) MICRO(GRAM);
AbstractUnit<Mass> b = (AbstractUnit<Mass>) GRAM.divide(1000).divide(1000);
assertEquals(true, a.isEquivalentTo(b));
assertEquals(true, b.isEquivalentTo(a));
}
Expand Down

0 comments on commit b19d10e

Please sign in to comment.