Search in sources :

Example 6 with IncommensurableException

use of javax.measure.IncommensurableException in project unit-api by unitsofmeasurement.

the class TestUnit method getConverterToAny.

public UnitConverter getConverterToAny(Unit<?> that) throws IncommensurableException, UnconvertibleException {
    if (!isCompatible(that))
        throw new IncommensurableException(this + " is not compatible with " + that);
    // Since both units are
    TestUnit thatAbstr = (TestUnit) that;
    // compatible they must
    // be both test
    // units.
    Unit thisSystemUnit = this.getSystemUnit();
    UnitConverter thisToDimension = this.getSystemConverter();
    Unit thatSystemUnit = thatAbstr.getSystemUnit();
    UnitConverter thatToDimension = thatAbstr.getSystemConverter();
    return thatToDimension.inverse().concatenate(thisToDimension);
}
Also used : IncommensurableException(javax.measure.IncommensurableException) UnitConverter(javax.measure.UnitConverter) Unit(javax.measure.Unit) BaseUnit(javax.measure.test.unit.BaseUnit)

Aggregations

IncommensurableException (javax.measure.IncommensurableException)6 UnconvertibleException (javax.measure.UnconvertibleException)4 UnitConverter (javax.measure.UnitConverter)3 Test (org.junit.Test)3 MeasurementException (javax.measure.MeasurementException)2 Unit (javax.measure.Unit)2 ParseException (gov.sandia.n2a.language.ParseException)1 BaseUnit (javax.measure.test.unit.BaseUnit)1