javax.measure.quantity.Speed Java Examples
The following examples show how to use
javax.measure.quantity.Speed.
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: UnitsTest.java From sis with Apache License 2.0 | 6 votes |
/** * Tests getting a unit for a given quantity type. */ @Test public void testGetForQuantity() { assertSame("Length", Units.METRE, Units.get(Length.class)); assertSame("Mass", Units.KILOGRAM, Units.get(Mass.class)); assertSame("Time", Units.SECOND, Units.get(Time.class)); assertSame("Temperature", Units.KELVIN, Units.get(Temperature.class)); assertSame("Area", Units.SQUARE_METRE, Units.get(Area.class)); assertSame("Volume", Units.CUBIC_METRE, Units.get(Volume.class)); assertSame("Speed", Units.METRES_PER_SECOND, Units.get(Speed.class)); assertSame("LuminousIntensity", Units.CANDELA, Units.get(LuminousIntensity.class)); assertSame("LuminousFlux", Units.LUMEN, Units.get(LuminousFlux.class)); assertSame("SolidAngle", Units.STERADIAN, Units.get(SolidAngle.class)); assertSame("Angle", Units.RADIAN, Units.get(Angle.class)); assertSame("Dimensionless", Units.UNITY, Units.get(Dimensionless.class)); }
Example #2
Source File: ScalarTest.java From sis with Apache License 2.0 | 6 votes |
/** * Tests {@link Scalar#multiply(Quantity)}, {@link Scalar#divide(Quantity)} and {@link Quantity#inverse()}. * Those tests depend on proper working of {@link Quantities#create(double, Unit)}, which depends in turn on * proper declarations of {@link ScalarFactory} in {@link Units} initialization. */ @Test public void testMultiplyDivideQuantity() { final Quantity<Length> q1 = new Scalar.Length(24, Units.METRE); final Quantity<Time> q2 = new Scalar.Time ( 4, Units.SECOND); final Quantity<Speed> q3 = q1.divide(q2).asType(Speed.class); assertSame ("unit", Units.METRES_PER_SECOND, q3.getUnit()); assertEquals("value", 6, q3.getValue().doubleValue(), STRICT); assertInstanceOf("Length/Time", Scalar.Speed.class, q3); final Quantity<Area> q4 = q1.multiply(q1).asType(Area.class); assertSame ("unit", Units.SQUARE_METRE, q4.getUnit()); assertEquals("value", 576, q4.getValue().doubleValue(), STRICT); assertInstanceOf("Length⋅Length", Scalar.Area.class, q4); final Quantity<Frequency> q5 = q2.inverse().asType(Frequency.class); assertSame ("unit", Units.HERTZ, q5.getUnit()); assertEquals("value", 0.25, q5.getValue().doubleValue(), STRICT); assertInstanceOf("1/Time", Scalar.Frequency.class, q5); }
Example #3
Source File: I18nProviderImpl.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
private void initDimensionMap() { Map<SystemOfUnits, Unit<? extends Quantity<?>>> temperatureMap = new HashMap<>(); temperatureMap.put(SIUnits.getInstance(), SIUnits.CELSIUS); temperatureMap.put(ImperialUnits.getInstance(), ImperialUnits.FAHRENHEIT); dimensionMap.put(Temperature.class, temperatureMap); Map<SystemOfUnits, Unit<? extends Quantity<?>>> pressureMap = new HashMap<>(); pressureMap.put(SIUnits.getInstance(), HECTO(SIUnits.PASCAL)); pressureMap.put(ImperialUnits.getInstance(), ImperialUnits.INCH_OF_MERCURY); dimensionMap.put(Pressure.class, pressureMap); Map<SystemOfUnits, Unit<? extends Quantity<?>>> speedMap = new HashMap<>(); speedMap.put(SIUnits.getInstance(), SIUnits.KILOMETRE_PER_HOUR); speedMap.put(ImperialUnits.getInstance(), ImperialUnits.MILES_PER_HOUR); dimensionMap.put(Speed.class, speedMap); Map<SystemOfUnits, Unit<? extends Quantity<?>>> lengthMap = new HashMap<>(); lengthMap.put(SIUnits.getInstance(), SIUnits.METRE); lengthMap.put(ImperialUnits.getInstance(), ImperialUnits.INCH); dimensionMap.put(Length.class, lengthMap); Map<SystemOfUnits, Unit<? extends Quantity<?>>> intensityMap = new HashMap<>(); intensityMap.put(SIUnits.getInstance(), SmartHomeUnits.IRRADIANCE); intensityMap.put(ImperialUnits.getInstance(), SmartHomeUnits.IRRADIANCE); dimensionMap.put(Intensity.class, intensityMap); Map<SystemOfUnits, Unit<? extends Quantity<?>>> percentMap = new HashMap<>(); percentMap.put(SIUnits.getInstance(), SmartHomeUnits.ONE); percentMap.put(ImperialUnits.getInstance(), SmartHomeUnits.ONE); dimensionMap.put(Dimensionless.class, percentMap); Map<SystemOfUnits, Unit<? extends Quantity<?>>> angleMap = new HashMap<>(); angleMap.put(SIUnits.getInstance(), SmartHomeUnits.DEGREE_ANGLE); angleMap.put(ImperialUnits.getInstance(), SmartHomeUnits.DEGREE_ANGLE); dimensionMap.put(Angle.class, angleMap); }
Example #4
Source File: SmartHomeUnitsTest.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@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 #5
Source File: SmartHomeUnitsTest.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@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 #6
Source File: SmartHomeUnitsTest.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@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 #7
Source File: SmartHomeUnitsTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@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 #8
Source File: SmartHomeUnitsTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@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 #9
Source File: SmartHomeUnitsTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@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 #10
Source File: I18nProviderImpl.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private void initDimensionMap() { Map<SystemOfUnits, Unit<? extends Quantity<?>>> temperatureMap = new HashMap<>(); temperatureMap.put(SIUnits.getInstance(), SIUnits.CELSIUS); temperatureMap.put(ImperialUnits.getInstance(), ImperialUnits.FAHRENHEIT); dimensionMap.put(Temperature.class, temperatureMap); Map<SystemOfUnits, Unit<? extends Quantity<?>>> pressureMap = new HashMap<>(); pressureMap.put(SIUnits.getInstance(), HECTO(SIUnits.PASCAL)); pressureMap.put(ImperialUnits.getInstance(), ImperialUnits.INCH_OF_MERCURY); dimensionMap.put(Pressure.class, pressureMap); Map<SystemOfUnits, Unit<? extends Quantity<?>>> speedMap = new HashMap<>(); speedMap.put(SIUnits.getInstance(), SIUnits.KILOMETRE_PER_HOUR); speedMap.put(ImperialUnits.getInstance(), ImperialUnits.MILES_PER_HOUR); dimensionMap.put(Speed.class, speedMap); Map<SystemOfUnits, Unit<? extends Quantity<?>>> lengthMap = new HashMap<>(); lengthMap.put(SIUnits.getInstance(), SIUnits.METRE); lengthMap.put(ImperialUnits.getInstance(), ImperialUnits.INCH); dimensionMap.put(Length.class, lengthMap); Map<SystemOfUnits, Unit<? extends Quantity<?>>> intensityMap = new HashMap<>(); intensityMap.put(SIUnits.getInstance(), SmartHomeUnits.IRRADIANCE); intensityMap.put(ImperialUnits.getInstance(), SmartHomeUnits.IRRADIANCE); dimensionMap.put(Intensity.class, intensityMap); Map<SystemOfUnits, Unit<? extends Quantity<?>>> percentMap = new HashMap<>(); percentMap.put(SIUnits.getInstance(), SmartHomeUnits.ONE); percentMap.put(ImperialUnits.getInstance(), SmartHomeUnits.ONE); dimensionMap.put(Dimensionless.class, percentMap); Map<SystemOfUnits, Unit<? extends Quantity<?>>> angleMap = new HashMap<>(); angleMap.put(SIUnits.getInstance(), SmartHomeUnits.DEGREE_ANGLE); angleMap.put(ImperialUnits.getInstance(), SmartHomeUnits.DEGREE_ANGLE); dimensionMap.put(Angle.class, angleMap); }
Example #11
Source File: MeteoBlueHandler.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private State getStateForType(String type, BigDecimal value) { State state = new DecimalType(value); if (type.equals("Number:Temperature")) { state = new QuantityType<Temperature>(value, SIUnits.CELSIUS); } else if (type.equals("Number:Length")) { state = new QuantityType<Length>(value, MILLI(SIUnits.METRE)); } else if (type.equals("Number:Pressure")) { state = new QuantityType<Pressure>(value, HECTO(SIUnits.PASCAL)); } else if (type.equals("Number:Speed")) { state = new QuantityType<Speed>(value, SIUnits.KILOMETRE_PER_HOUR); } return state; }
Example #12
Source File: QuantityTypeTest.java From openhab-core with Eclipse Public License 2.0 | 4 votes |
@Test public void testRainfallRate() { QuantityType<Speed> rate = new QuantityType<>("3 mm/h"); assertEquals("0.1181102362204724409448818897637795 in/h", rate.toUnit("in/h").toString()); }
Example #13
Source File: UnitFormatTest.java From uom-systems with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testFormat2() { Unit<Speed> kph = Units.KILOMETRE_PER_HOUR; assertEquals("km/h", kph.toString()); }
Example #14
Source File: UnitFormatTest.java From uom-systems with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testFormat4() { Unit<Speed> kph = Units.KILOMETRE_PER_HOUR; assertEquals("km/h", kph.toString()); }
Example #15
Source File: CLDRTest.java From uom-systems with BSD 3-Clause "New" or "Revised" License | 4 votes |
@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 #16
Source File: ConvertToBindingTest.java From smarthome with Eclipse Public License 2.0 | 2 votes |
@Test public void testQuantityTypeConverter() throws ConverterException { Object convertedValue; TypeConverter<?> qTypeConverter = new QuantityTypeConverter(); floatQuantityDp.setUnit("°C"); convertedValue = qTypeConverter.convertToBinding(new QuantityType<Temperature>("99.9 °C"), floatQuantityDp); assertThat(convertedValue, is(99.9)); floatQuantityDp.setUnit("°C"); // at some points datapoints come with such unit instead of °C convertedValue = qTypeConverter.convertToBinding(new QuantityType<Temperature>("451 °F"), floatQuantityDp); assertThat(convertedValue, is(232.777778)); floatQuantityDp.setUnit("km/h"); convertedValue = qTypeConverter.convertToBinding(new QuantityType<Speed>("70.07 m/s"), floatQuantityDp); assertThat(convertedValue, is(252.252)); integerQuantityDp.setUnit("%"); convertedValue = qTypeConverter.convertToBinding(new QuantityType<Dimensionless>("99.0 %"), integerQuantityDp); assertThat(convertedValue, is(99)); convertedValue = qTypeConverter.convertToBinding(new QuantityType<Dimensionless>("99.9 %"), integerQuantityDp); assertThat(convertedValue, is(99)); convertedValue = qTypeConverter.convertToBinding(new QuantityType<Dimensionless>("1"), integerQuantityDp); assertThat(convertedValue, is(100)); floatQuantityDp.setUnit("100%"); // not really a unit, but it occurs in homematic datapoints convertedValue = qTypeConverter.convertToBinding(new QuantityType<Dimensionless>("99.0 %"), floatQuantityDp); assertThat(convertedValue, is(0.99)); convertedValue = qTypeConverter.convertToBinding(new QuantityType<Dimensionless>("99.9 %"), floatQuantityDp); assertThat(convertedValue, is(0.999)); convertedValue = qTypeConverter.convertToBinding(new QuantityType<Dimensionless>("1"), floatQuantityDp); assertThat(convertedValue, is(1.0)); integerQuantityDp.setUnit("Lux"); convertedValue = qTypeConverter.convertToBinding(new QuantityType<Illuminance>("42 lx"), integerQuantityDp); assertThat(convertedValue, is(42)); }