Search in sources :

Example 41 with Length

use of javax.measure.quantity.Length in project smarthome by eclipse.

the class SmartHomeUnitsTest method testM2Ft.

@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)));
}
Also used : Length(javax.measure.quantity.Length) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 42 with Length

use of javax.measure.quantity.Length in project tutorials by eugenp.

the class WaterTankTests method givenQuantity_whenGetUnitAndConvertValue_thenSuccess.

@Test
public void givenQuantity_whenGetUnitAndConvertValue_thenSuccess() {
    WaterTank waterTank = new WaterTank();
    waterTank.setCapacityMeasure(Quantities.getQuantity(9.2, LITRE));
    assertEquals(LITRE, waterTank.getCapacityMeasure().getUnit());
    Quantity<Volume> waterCapacity = waterTank.getCapacityMeasure();
    double volumeInLitre = waterCapacity.getValue().doubleValue();
    assertEquals(9.2, volumeInLitre, 0.0f);
    double volumeInMilliLitre = waterCapacity.to(MetricPrefix.MILLI(LITRE)).getValue().doubleValue();
    assertEquals(9200.0, volumeInMilliLitre, 0.0f);
    // compilation error
    // volumeInMilliLitre = waterCapacity.to(MetricPrefix.MILLI(KILOGRAM));
    Unit<Length> Kilometer = MetricPrefix.KILO(METRE);
// compilation error
// Unit<Length> Centimeter = MetricPrefix.CENTI(LITRE);
}
Also used : Volume(javax.measure.quantity.Volume) Length(javax.measure.quantity.Length) WaterTank(com.baeldung.measurement.WaterTank) Test(org.junit.Test)

Example 43 with Length

use of javax.measure.quantity.Length in project indriya by unitsofmeasurement.

the class EBNFFormatTest method testTransformed.

@Test
public void testTransformed() {
    final String ANGSTROEM_SYM = "\u212B";
    final Unit<Length> ANGSTROEM = new TransformedUnit<Length>(ANGSTROEM_SYM, METRE, METRE, new RationalConverter(BigInteger.ONE, BigInteger.TEN.pow(10)));
    final String s = format.format(ANGSTROEM);
    assertEquals(ANGSTROEM_SYM, s);
}
Also used : Length(javax.measure.quantity.Length) RationalConverter(tech.units.indriya.function.RationalConverter) TransformedUnit(tech.units.indriya.unit.TransformedUnit) Test(org.junit.jupiter.api.Test)

Example 44 with Length

use of javax.measure.quantity.Length in project indriya by unitsofmeasurement.

the class SimpleFormatTest method testTransformed.

@Test
public void testTransformed() {
    final String ANGSTROEM_SYM = "\u212B";
    final Unit<Length> ANGSTROEM = new TransformedUnit<Length>(ANGSTROEM_SYM, METRE, METRE, new RationalConverter(BigInteger.ONE, BigInteger.TEN.pow(10)));
    final String s = format.format(ANGSTROEM);
    assertEquals(ANGSTROEM_SYM, s);
}
Also used : Length(javax.measure.quantity.Length) RationalConverter(tech.units.indriya.function.RationalConverter) TransformedUnit(tech.units.indriya.unit.TransformedUnit) Test(org.junit.jupiter.api.Test)

Aggregations

Length (javax.measure.quantity.Length)44 Angle (javax.measure.quantity.Angle)7 Test (org.junit.Test)7 Color (java.awt.Color)5 Unit (javax.measure.Unit)5 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 AffineTransform (java.awt.geom.AffineTransform)4 ArrayList (java.util.ArrayList)4 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)3 BoundingBox (com.revolsys.geometry.model.BoundingBox)3 LineString (com.revolsys.geometry.model.LineString)3 Point (com.revolsys.geometry.model.Point)3 Shape (java.awt.Shape)3 Rectangle2D (java.awt.geom.Rectangle2D)3 Path (java.nio.file.Path)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Quantity (javax.measure.Quantity)3 CloseableAffineTransform (com.revolsys.awt.CloseableAffineTransform)2 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)2 ChainedCoordinatesOperation (com.revolsys.geometry.cs.projection.ChainedCoordinatesOperation)2