Skip to content

Commit

Permalink
# WARNING: head commit changed in the meantime
Browse files Browse the repository at this point in the history
177: Liters per 100 km to mpg conversion issue

Task-Url: unitsofmeasurement/uom-systems#177
  • Loading branch information
keilw committed Oct 8, 2020
1 parent ee8b0a6 commit 9357657
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@
* @author <a href="mailto:[email protected]">Jean-Marie Dautelle</a>
* @author <a href="mailto:[email protected]">Werner Keil</a>
* @author Andi Huber
* @version 1.4, Jun 23, 2019
* @version 2.0, Oct 8, 2020
* @since 1.0
*/
final class DoubleMultiplyConverter
extends AbstractConverter
implements MultiplyConverter {
extends AbstractConverter implements MultiplyConverter {

/**
*
Expand Down Expand Up @@ -135,6 +134,11 @@ public Double getValue() {
return doubleFactor;
}

@Override
public double getAsDouble() {
return doubleFactor;
}

@Override
public int compareTo(UnitConverter o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ public List<? extends UnitConverter> getConversionSteps() {
public Number getValue() {
return 1;
}


@Override
public double getAsDouble() {
return 1d;
}

@Override
public int compareTo(UnitConverter o) {
return AbstractConverter.IDENTITY.compareTo(o);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.function.DoubleSupplier;

import javax.measure.Prefix;
import javax.measure.UnitConverter;
Expand All @@ -49,11 +50,11 @@
* @author <a href="mailto:[email protected]">Jean-Marie Dautelle</a>
* @author <a href="mailto:[email protected]">Werner Keil</a>
* @author Andi Huber
* @version 2.6, September 10, 2019
* @version 2.7, October 8, 2020
* @since 1.0
*/
public interface MultiplyConverter extends UnitConverter, Converter<Number, Number>,
ValueSupplier<Number>, FactorSupplier<Number>, Comparable<UnitConverter> {
ValueSupplier<Number>, FactorSupplier<Number>, DoubleSupplier, Comparable<UnitConverter> {

// -- FACTORIES

Expand Down
20 changes: 12 additions & 8 deletions src/main/java/tech/units/indriya/function/PowerOfIntConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
* UnitConverter for numbers in base^exponent representation.
* @author Andi Huber
* @author Werner Keil
* @version 1.5, Jun 25, 2019
* @version 2.0, Oct 8, 2020
* @since 2.0
*/
//TODO[220] make this like all the other MultiplyConverter package private
// As it's used in the "format" package, we may not be able to make it package-private here
public final class PowerOfIntConverter extends AbstractConverter
implements MultiplyConverter, IntBaseSupplier, IntExponentSupplier {
private static final long serialVersionUID = 3546932001671571300L;
Expand Down Expand Up @@ -177,6 +177,16 @@ public final String transformationLiteral() {
}
return String.format("x -> x * %s^%s", base, exponent);
}

@Override
public Number getValue() {
return rationalFactor;
}

@Override
public double getAsDouble() {
return rationalFactor.doubleValue();
}

@Override
public int compareTo(UnitConverter o) {
Expand Down Expand Up @@ -223,10 +233,4 @@ private PowerOfIntConverter composeSameBaseNonIdentity(PowerOfIntConverter other
public RationalConverter toRationalConverter() {
return new RationalConverter(rationalFactor);
}

@Override
public Number getValue() {
return rationalFactor;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* Pi to the power of an integer exponent (π^exponent).
* @author Andi Huber
* @author Werner Keil
* @version 1.5, Jun 21, 2019
* @version 2.0, Oct 8, 2020
* @since 2.0
*/
final class PowerOfPiConverter extends AbstractConverter
Expand Down Expand Up @@ -176,5 +176,8 @@ public int hashCode() {
return hashCode;
}


@Override
public double getAsDouble() {
return getValue().doubleValue();
}
}
10 changes: 8 additions & 2 deletions src/main/java/tech/units/indriya/function/RationalConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

import java.math.BigInteger;
import java.util.Objects;
import java.util.function.DoubleSupplier;

import javax.measure.UnitConverter;

import tech.units.indriya.internal.function.Calculator;
Expand All @@ -44,7 +46,7 @@
* @author <a href="mailto:[email protected]">Jean-Marie Dautelle</a>
* @author <a href="mailto:[email protected]">Werner Keil</a>
* @author Andi Huber
* @version 1.8, August 21, 2019
* @version 2.0, October 8, 2020
* @since 1.0
*/
public final class RationalConverter extends AbstractConverter
Expand Down Expand Up @@ -228,6 +230,11 @@ public int hashCode() {
public Number getValue() {
return factor;
}

@Override
public double getAsDouble() {
return factor.doubleValue();
}

@Override
public int compareTo(UnitConverter o) {
Expand All @@ -253,5 +260,4 @@ private AbstractConverter composeSameType(RationalConverter that) {
? IDENTITY
: new RationalConverter(newDividend, newDivisor);
}

}

0 comments on commit 9357657

Please sign in to comment.