Search in sources :

Example 1 with AbstractUnit

use of tech.units.indriya.AbstractUnit in project indriya by unitsofmeasurement.

the class AbsUnitTest method testCompound2.

@SuppressWarnings("unchecked")
@Test
public void testCompound2() {
    @SuppressWarnings("rawtypes") final AbstractUnit hourMin = (AbstractUnit) ((AbstractUnit) HOUR).compound(MINUTE);
    assertEquals("h:min:s", hourMin.compound(SECOND).toString());
}
Also used : AbstractUnit(tech.units.indriya.AbstractUnit) Test(org.junit.jupiter.api.Test)

Example 2 with AbstractUnit

use of tech.units.indriya.AbstractUnit in project indriya by unitsofmeasurement.

the class ProductUnit method getSystemConverter.

@Override
public UnitConverter getSystemConverter() {
    UnitConverter converter = AbstractConverter.IDENTITY;
    for (Element e : elements) {
        if (e.unit instanceof AbstractUnit) {
            UnitConverter cvtr = ((AbstractUnit) e.unit).getSystemConverter();
            if (!(cvtr.isLinear()))
                throw new UnsupportedOperationException(e.unit + " is non-linear, cannot convert");
            if (e.root != 1)
                throw new UnsupportedOperationException(e.unit + " holds a base unit with fractional exponent");
            int pow = e.pow;
            if (pow < 0) {
                // Negative power.
                pow = -pow;
                cvtr = cvtr.inverse();
            }
            for (int j = 0; j < pow; j++) {
                converter = converter.concatenate(cvtr);
            }
        }
    }
    return converter;
}
Also used : AbstractUnit(tech.units.indriya.AbstractUnit) UnitConverter(javax.measure.UnitConverter)

Aggregations

AbstractUnit (tech.units.indriya.AbstractUnit)2 UnitConverter (javax.measure.UnitConverter)1 Test (org.junit.jupiter.api.Test)1