/** * Determines if this time interval is equal to another time interval, using an epsilon to compare the {@code Start} ({@link #getStart get}) and {@code Stop} ({@link #getStop get}) properties of the two intervals. The dates are considered equal if they are within {@code epsilon} seconds of each other. All other properties must be identical. * @param other The time interval to compare to this time interval. * @param epsilon The largest difference between the {@code Start} ({@link #getStart get}) and {@code Stop} ({@link #getStop get}) dates, in seconds, such that they will be considered equal. * @return true if the {@code Start} ({@link #getStart get}) and {@code Stop} ({@link #getStop get}) dates of the intervals are equal as defined by the epsilon value and all other properties are identical. */ @CS2JWarning("Unhandled attribute removed: Pure") public final boolean equalsEpsilon(TimeInterval other, double epsilon) { if (ObjectHelper.referenceEquals(null, other)) { return false; } if (ObjectHelper.referenceEquals(this, other)) { return true; } if (getIsEmpty() && other.getIsEmpty()) { return true; } return m_start.equalsEpsilon(other.m_start, epsilon) && m_stop.equalsEpsilon(other.m_stop, epsilon); }
/** * Tests that the {@link JulianDate#equalsEpsilon} method returns true when the difference is exactly epsilon. */ @Test public final void testEqualsEpsilonExact() { JulianDate first = new JulianDate(2451545, 0.2); JulianDate second = new JulianDate(2451545, 0.2); Assert.assertTrue(second.equalsEpsilon(first, 0D)); }
/** * Tests conversion of a {@link ZonedDateTime} to a {@link JulianDate} when the {@link ZonedDateTime} is specified as a local time instead of as UTC. */ @Test public final void testLocalDateTimeToJulian() { ZonedDateTime localNow = DateTimeHelper.now(); ZonedDateTime utcNow = DateTimeHelper.toUniversalTime(localNow); JulianDate localJulianDate = new JulianDate(localNow); JulianDate utcJulianDate = new JulianDate(utcNow); Assert.assertTrue(localJulianDate.equalsEpsilon(utcJulianDate, Constants.Epsilon14)); localNow = DateTimeHelper.now(); utcNow = DateTimeHelper.toUniversalTime(localNow); localJulianDate = new JulianDate(localNow, TimeStandard.INTERNATIONAL_ATOMIC_TIME); utcJulianDate = new JulianDate(utcNow, TimeStandard.INTERNATIONAL_ATOMIC_TIME); Assert.assertTrue(localJulianDate.equalsEpsilon(utcJulianDate, Constants.Epsilon14)); }
/** * Tests the check for EXACT equality and the check for equality within a specified tolerance. */ @Test public final void testEquality() { JulianDate first = new JulianDate(2451545, 0.2); JulianDate second = new JulianDate(2451545, 0.2); AssertHelper.assertEquals(first, second); Assert.assertTrue(first.equalsType(second)); Assert.assertTrue(second.equalsType(first)); Assert.assertEquals((int) 0, (int) first.compareTo(second)); Assert.assertEquals((int) 0, (int) second.compareTo(first)); AssertHelper.assertNotEqual(first, 5); first = new JulianDate(2451545, 0.00001); second = new JulianDate(2451544, 86399.99999); AssertHelper.assertNotEqual(first, second); Assert.assertFalse(first.equalsType(second)); Assert.assertFalse(second.equalsType(first)); AssertHelper.assertNotEqual(0, first.compareTo(second)); AssertHelper.assertNotEqual(0, second.compareTo(first)); Assert.assertTrue(first.equalsEpsilon(second, 1e-4)); Assert.assertTrue(second.equalsEpsilon(first, 1e-4)); }