Search in sources :

Example 6 with Quantity

use of javax.measure.Quantity in project indriya by unitsofmeasurement.

the class TimeQuantitiesTest method ofLocalTimeTemporalAdjustTest.

@Test
public void ofLocalTimeTemporalAdjustTest() {
    LocalTime a = LocalTime.MIDNIGHT;
    TemporalAdjuster temporalAdjuster = (temporal) -> temporal.plus(12L, ChronoUnit.HOURS);
    Quantity<Time> time = TimeQuantities.getQuantity(a, () -> temporalAdjuster);
    assertEquals(Integer.valueOf(12), Integer.valueOf(time.getValue().intValue()));
    assertEquals(Units.HOUR, time.getUnit());
}
Also used : Unit(javax.measure.Unit) HERTZ(tech.units.indriya.unit.Units.HERTZ) MINUTE(tech.units.indriya.unit.Units.MINUTE) Quantity(javax.measure.Quantity) DAY(tech.units.indriya.unit.Units.DAY) TimeQuantities(tech.units.indriya.quantity.time.TimeQuantities) LocalTime(java.time.LocalTime) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Frequency(javax.measure.quantity.Frequency) Month(java.time.Month) TemporalQuantity(tech.units.indriya.quantity.time.TemporalQuantity) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) ChronoUnit(java.time.temporal.ChronoUnit) SECOND(tech.units.indriya.unit.Units.SECOND) Year(java.time.Year) Quantities(tech.units.indriya.quantity.Quantities) DayOfWeek(java.time.DayOfWeek) LocalDate(java.time.LocalDate) TemporalAdjusters(java.time.temporal.TemporalAdjusters) HOUR(tech.units.indriya.unit.Units.HOUR) TimeUnitQuantity(tech.units.indriya.quantity.time.TimeUnitQuantity) TemporalAdjuster(java.time.temporal.TemporalAdjuster) Time(javax.measure.quantity.Time) Units(tech.units.indriya.unit.Units) LocalTime(java.time.LocalTime) TemporalAdjuster(java.time.temporal.TemporalAdjuster) LocalTime(java.time.LocalTime) Time(javax.measure.quantity.Time) Test(org.junit.jupiter.api.Test)

Example 7 with Quantity

use of javax.measure.Quantity in project sis by apache.

the class QuantitiesTest method testCastOrCopy.

/**
 * Tests {@link Quantities#castOrCopy(Quantity)}.
 */
@Test
public void testCastOrCopy() {
    Quantity<Length> q = Quantities.create(5, Units.KILOMETRE);
    assertSame(q, Quantities.castOrCopy(q));
    q = new Quantity<Length>() {

        @Override
        public Number getValue() {
            return 8;
        }

        @Override
        public Unit<Length> getUnit() {
            return Units.CENTIMETRE;
        }

        @Override
        public Quantity<Length> add(Quantity<Length> ignored) {
            return null;
        }

        @Override
        public Quantity<Length> subtract(Quantity<Length> ignored) {
            return null;
        }

        @Override
        public Quantity<?> multiply(Quantity<?> ignored) {
            return null;
        }

        @Override
        public Quantity<?> divide(Quantity<?> ignored) {
            return null;
        }

        @Override
        public Quantity<Length> multiply(Number ignored) {
            return null;
        }

        @Override
        public Quantity<Length> divide(Number ignored) {
            return null;
        }

        @Override
        public Quantity<?> inverse() {
            return null;
        }

        @Override
        public Quantity<Length> to(Unit<Length> ignored) {
            return null;
        }

        @Override
        public <T extends Quantity<T>> Quantity<T> asType(Class<T> ignored) {
            return null;
        }
    };
    final Length c = Quantities.castOrCopy(q);
    assertNotSame(q, c);
    assertEquals("value", 8, c.getValue().doubleValue(), STRICT);
    assertSame("unit", Units.CENTIMETRE, c.getUnit());
}
Also used : Length(javax.measure.quantity.Length) Quantity(javax.measure.Quantity) Unit(javax.measure.Unit) Test(org.junit.Test)

Aggregations

Quantity (javax.measure.Quantity)7 Unit (javax.measure.Unit)5 Length (javax.measure.quantity.Length)3 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)2 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)2 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)2 DayOfWeek (java.time.DayOfWeek)2 LocalDate (java.time.LocalDate)2 LocalTime (java.time.LocalTime)2 Month (java.time.Month)2 Year (java.time.Year)2 ChronoUnit (java.time.temporal.ChronoUnit)2 TemporalAdjuster (java.time.temporal.TemporalAdjuster)2 TemporalAdjusters (java.time.temporal.TemporalAdjusters)2 Time (javax.measure.quantity.Time)2 Test (org.junit.Test)2 LineCap (com.revolsys.geometry.model.LineCap)1 PreparedLinearRing (com.revolsys.geometry.model.prep.PreparedLinearRing)1 CheckBox (com.revolsys.swing.field.CheckBox)1 ColorChooserField (com.revolsys.swing.field.ColorChooserField)1