/** * Returns true if this date exactly equals another date. To be considered equal, the {@code Day} ({@link #getDay get}) and {@code SecondsOfDay} ({@link #getSecondsOfDay get}) properties must be identical when converted to a common time standard. It is highly recommended that you use {@link #equalsEpsilon} or {@link #isIdentical} instead of this method. * @param obj The object to compare to this instance. * @return {@code true} if {@code obj} represents the same value as this instance; otherwise, {@code false}. */ @Override public boolean equals(Object obj) { return obj instanceof JulianDate && equalsType((JulianDate) obj); }
/** * Returns true if the two dates are NOT exactly equal. To be considered equal, the {@code Day} ({@link #getDay get}) and {@code SecondsOfDay} ({@link #getSecondsOfDay get}) properties must be identical when converted to a common time standard. It is highly recommended that you use {@link #equalsEpsilon} or {@link #isIdentical} instead of this method. * @param left The date on the left side. * @param right The date on the right side. * @return {@code true} if the dates are not equal, otherwise {@code false}. */ @CS2JInfo("This method implements the functionality of the overloaded operator: 'System.Boolean !=(JulianDate,JulianDate)'") public static boolean notEquals(@Nonnull JulianDate left, @Nonnull JulianDate right) { return !left.equalsType(right); }
/** * Returns true if the two dates are exactly equal. To be considered equal, the {@code Day} ({@link #getDay get}) and {@code SecondsOfDay} ({@link #getSecondsOfDay get}) properties must be identical when converted to a common time standard. It is highly recommended that you use {@link #equalsEpsilon} or {@link #isIdentical} instead of this method. * @param left The date on the left side. * @param right The date on the right side. * @return {@code true} if the dates are equal, otherwise {@code false}. */ @CS2JInfo("This method implements the functionality of the overloaded operator: 'System.Boolean ==(JulianDate,JulianDate)'") public static boolean equals(@Nonnull JulianDate left, @Nonnull JulianDate right) { return left.equalsType(right); }
/** * Indicates whether another instance of this type is exactly equal to this instance. * @param other The instance to compare to this instance. * @return {@code true} if {@code other} represents the same value as this instance; otherwise, {@code false}. */ public final boolean equalsType(TimeInterval other) { if (ObjectHelper.referenceEquals(null, other)) { return false; } if (ObjectHelper.referenceEquals(this, other)) { return true; } if (getIsEmpty() && other.getIsEmpty()) { return true; } return m_start.equalsType(other.m_start) && m_stop.equalsType(other.m_stop); }
@Test public final void testEqualityOfLeapSeconds() { JulianDate leapSecond = new JulianDate(2453736, 43233D, TimeStandard.INTERNATIONAL_ATOMIC_TIME); JulianDate utcDate = new JulianDate(2453736, 43233D, TimeStandard.COORDINATED_UNIVERSAL_TIME); Assert.assertFalse(utcDate.equalsType(leapSecond)); Assert.assertFalse(leapSecond.equalsType(utcDate)); }
/** * 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)); }