Java Code Examples for javax.measure.Quantity#to()

The following examples show how to use javax.measure.Quantity#to() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SmartHomeUnitsTest.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testKmh2Mih() {
    Quantity<Speed> kmh = Quantities.getQuantity(BigDecimal.TEN, SIUnits.KILOMETRE_PER_HOUR);

    Quantity<Speed> mph = kmh.to(ImperialUnits.MILES_PER_HOUR);
    assertThat(mph.getUnit(), is(ImperialUnits.MILES_PER_HOUR));
    assertThat(mph.getValue().doubleValue(), is(closeTo(6.21371192237333935d, DEFAULT_ERROR)));
}
 
Example 2
Source File: SmartHomeUnitsTest.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testKmh2Knot() {
    Quantity<Speed> kmh = Quantities.getQuantity(new BigDecimal("1.852"), SIUnits.KILOMETRE_PER_HOUR);

    Quantity<Speed> knot = kmh.to(SmartHomeUnits.KNOT);
    assertThat(knot.getUnit(), is(SmartHomeUnits.KNOT));
    assertThat(knot.getValue().doubleValue(), is(closeTo(1.000, DEFAULT_ERROR)));
}
 
Example 3
Source File: SmartHomeUnitsTest.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testKnot2Kmh() {
    Quantity<Speed> knot = Quantities.getQuantity(BigDecimal.TEN, SmartHomeUnits.KNOT);

    Quantity<Speed> kmh = knot.to(SIUnits.KILOMETRE_PER_HOUR);
    assertThat(kmh.getUnit(), is(SIUnits.KILOMETRE_PER_HOUR));
    assertThat(kmh.getValue().doubleValue(), is(closeTo(18.52, DEFAULT_ERROR)));
}
 
Example 4
Source File: SmartHomeUnitsTest.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testCm2In() {
    Quantity<Length> cm = Quantities.getQuantity(BigDecimal.TEN, MetricPrefix.CENTI(SIUnits.METRE));

    Quantity<Length> in = cm.to(ImperialUnits.INCH);
    assertThat(in.getUnit(), is(ImperialUnits.INCH));
    assertThat(in.getValue().doubleValue(), is(closeTo(3.93700787401574803d, DEFAULT_ERROR)));
}
 
Example 5
Source File: SmartHomeUnitsTest.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testM2Ft() {
    Quantity<Length> cm = Quantities.getQuantity(new BigDecimal("30"), MetricPrefix.CENTI(SIUnits.METRE));

    Quantity<Length> foot = cm.to(ImperialUnits.FOOT);
    assertThat(foot.getUnit(), is(ImperialUnits.FOOT));
    assertThat(foot.getValue().doubleValue(), is(closeTo(0.9842519685039369d, DEFAULT_ERROR)));
}
 
Example 6
Source File: SmartHomeUnitsTest.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testM2Yd() {
    Quantity<Length> m = Quantities.getQuantity(BigDecimal.ONE, SIUnits.METRE);

    Quantity<Length> yard = m.to(ImperialUnits.YARD);
    assertThat(yard.getUnit(), is(ImperialUnits.YARD));
    assertThat(yard.getValue().doubleValue(), is(closeTo(1.0936132983377076d, DEFAULT_ERROR)));
}
 
Example 7
Source File: SmartHomeUnitsTest.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testM2Ml() {
    Quantity<Length> km = Quantities.getQuantity(BigDecimal.TEN, MetricPrefix.KILO(SIUnits.METRE));

    Quantity<Length> mile = km.to(ImperialUnits.MILE);
    assertThat(mile.getUnit(), is(ImperialUnits.MILE));
    assertThat(mile.getValue().doubleValue(), is(closeTo(6.2137119223733395d, DEFAULT_ERROR)));
}
 
Example 8
Source File: SmartHomeUnitsTest.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testFahrenheit2Kelvin() {
    Quantity<Temperature> fahrenheit = Quantities.getQuantity(new BigDecimal("100"), ImperialUnits.FAHRENHEIT);

    Quantity<Temperature> kelvin = fahrenheit.to(SmartHomeUnits.KELVIN);
    assertThat(kelvin.getUnit(), is(SmartHomeUnits.KELVIN));
    assertThat(kelvin.getValue().doubleValue(), is(closeTo(310.92777777777777778d, DEFAULT_ERROR)));
}
 
Example 9
Source File: SmartHomeUnitsTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testM2Ml() {
    Quantity<Length> km = Quantities.getQuantity(BigDecimal.TEN, MetricPrefix.KILO(SIUnits.METRE));

    Quantity<Length> mile = km.to(ImperialUnits.MILE);
    assertThat(mile.getUnit(), is(ImperialUnits.MILE));
    assertThat(mile.getValue().doubleValue(), is(closeTo(6.2137119223733395d, DEFAULT_ERROR)));
}
 
Example 10
Source File: SmartHomeUnitsTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testM2Yd() {
    Quantity<Length> m = Quantities.getQuantity(BigDecimal.ONE, SIUnits.METRE);

    Quantity<Length> yard = m.to(ImperialUnits.YARD);
    assertThat(yard.getUnit(), is(ImperialUnits.YARD));
    assertThat(yard.getValue().doubleValue(), is(closeTo(1.0936132983377076d, DEFAULT_ERROR)));
}
 
Example 11
Source File: SmartHomeUnitsTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testM2Ft() {
    Quantity<Length> cm = Quantities.getQuantity(new BigDecimal("30"), MetricPrefix.CENTI(SIUnits.METRE));

    Quantity<Length> foot = cm.to(ImperialUnits.FOOT);
    assertThat(foot.getUnit(), is(ImperialUnits.FOOT));
    assertThat(foot.getValue().doubleValue(), is(closeTo(0.9842519685039369d, DEFAULT_ERROR)));
}
 
Example 12
Source File: SmartHomeUnitsTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testKmh2Mih() {
    Quantity<Speed> kmh = Quantities.getQuantity(BigDecimal.TEN, SIUnits.KILOMETRE_PER_HOUR);

    Quantity<Speed> mph = kmh.to(ImperialUnits.MILES_PER_HOUR);
    assertThat(mph.getUnit(), is(ImperialUnits.MILES_PER_HOUR));
    assertThat(mph.getValue().doubleValue(), is(closeTo(6.21371192237333935d, DEFAULT_ERROR)));
}
 
Example 13
Source File: SmartHomeUnitsTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testKmh2Knot() {
    Quantity<Speed> kmh = Quantities.getQuantity(new BigDecimal("1.852"), SIUnits.KILOMETRE_PER_HOUR);

    Quantity<Speed> knot = kmh.to(SmartHomeUnits.KNOT);
    assertThat(knot.getUnit(), is(SmartHomeUnits.KNOT));
    assertThat(knot.getValue().doubleValue(), is(closeTo(1.000, DEFAULT_ERROR)));
}
 
Example 14
Source File: SmartHomeUnitsTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testKnot2Kmh() {
    Quantity<Speed> knot = Quantities.getQuantity(BigDecimal.TEN, SmartHomeUnits.KNOT);

    Quantity<Speed> kmh = knot.to(SIUnits.KILOMETRE_PER_HOUR);
    assertThat(kmh.getUnit(), is(SIUnits.KILOMETRE_PER_HOUR));
    assertThat(kmh.getValue().doubleValue(), is(closeTo(18.52, DEFAULT_ERROR)));
}
 
Example 15
Source File: SmartHomeUnitsTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testCm2In() {
    Quantity<Length> cm = Quantities.getQuantity(BigDecimal.TEN, MetricPrefix.CENTI(SIUnits.METRE));

    Quantity<Length> in = cm.to(ImperialUnits.INCH);
    assertThat(in.getUnit(), is(ImperialUnits.INCH));
    assertThat(in.getValue().doubleValue(), is(closeTo(3.93700787401574803d, DEFAULT_ERROR)));
}
 
Example 16
Source File: SmartHomeUnitsTest.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testMicrogramPerCubicMeter2KilogramPerCubicMeter() {
    Quantity<Density> one_kg_m3 = Quantities.getQuantity(BigDecimal.ONE, SmartHomeUnits.KILOGRAM_PER_CUBICMETRE);
    Quantity<Density> converted = one_kg_m3.to(SmartHomeUnits.MICROGRAM_PER_CUBICMETRE);
    assertThat(converted.getValue().doubleValue(), is(closeTo(1000000000, DEFAULT_ERROR)));
}
 
Example 17
Source File: SmartHomeUnitsTest.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testMicrowattPerSquareCentimetre2KilogramPerSquareCentiMetre() {
    Quantity<Intensity> one_mw_cm2 = Quantities.getQuantity(BigDecimal.ONE, SmartHomeUnits.IRRADIANCE);
    Quantity<Intensity> converted = one_mw_cm2.to(SmartHomeUnits.MICROWATT_PER_SQUARE_CENTIMETRE);
    assertThat(converted.getValue().doubleValue(), is(closeTo(0.01, DEFAULT_ERROR)));
}
 
Example 18
Source File: CLDRTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testConvert() {
	Quantity<Speed> kph = Quantities.getQuantity(30, Units.KILOMETRE_PER_HOUR);
	Quantity<Speed> knots = kph.to(CLDR.KNOT);
	assertEquals(RationalNumber.of(new BigDecimal("16.19870410367170626349892008639309")), knots.getValue());
}
 
Example 19
Source File: SmartHomeUnitsTest.java    From openhab-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testMicrowattPerSquareCentimetre2KilogramPerSquareCentiMetre() {
    Quantity<Intensity> oneMwCm2 = Quantities.getQuantity(BigDecimal.ONE, SmartHomeUnits.IRRADIANCE);
    Quantity<Intensity> converted = oneMwCm2.to(SmartHomeUnits.MICROWATT_PER_SQUARE_CENTIMETRE);
    assertThat(converted.getValue().doubleValue(), is(100d));
}
 
Example 20
Source File: SmartHomeUnitsTest.java    From openhab-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testMicrogramPerCubicMeter2KilogramPerCubicMeter() {
    Quantity<Density> oneKgM3 = Quantities.getQuantity(BigDecimal.ONE, SmartHomeUnits.KILOGRAM_PER_CUBICMETRE);
    Quantity<Density> converted = oneKgM3.to(SmartHomeUnits.MICROGRAM_PER_CUBICMETRE);
    assertThat(converted.getValue().doubleValue(), is(closeTo(1000000000, DEFAULT_ERROR)));
}