/** * Returns {@code true} if this {@link Duration} exactly equals another {@link Duration}, within the limits of floating point precision. To be considered equal, the {@code Days} ({@link #getDays get}) property must be identical and the difference between the {@code Seconds} ({@link #getSeconds get}) properties must be less than 1.0e-10. * @param obj The other {@link Duration}. * @return {@code true} if this {@link Duration} exactly equals the {@code obj} {@link Duration}, within the limits of floating point precision. */ @Override public boolean equals(Object obj) { return obj instanceof Duration && equalsType((Duration) obj); }
/** * Returns {@code true} if two {@link Duration Durations} are exactly equal, within the limits of floating point precision. To be considered equal, the {@code Days} ({@link #getDays get}) property must be identical and the difference between the {@code Seconds} ({@link #getSeconds get}) properties must be less than 1.0e-10. * @param left The left {@link Duration}. * @param right The second {@link Duration}. * @return {@code true} if the {@link Duration Durations} are equal, otherwise {@code false}. */ @CS2JInfo("This method implements the functionality of the overloaded operator: 'System.Boolean ==(Duration,Duration)'") public static boolean equals(@Nonnull Duration left, @Nonnull Duration right) { return left.equalsType(right); }
/** * Returns {@code true} if two {@link Duration Durations} are NOT exactly equal, within the limits of floating point precision. To be considered equal, the {@code Days} ({@link #getDays get}) property must be identical (or one must be null) and the difference between the {@code Seconds} ({@link #getSeconds get}) properties must be less than 1.0e-10. * @param left The first {@link Duration}. * @param right The second {@link Duration}. * @return {@code true} if the {@link Duration Durations} are not equal, otherwise {@code false}. */ @CS2JInfo("This method implements the functionality of the overloaded operator: 'System.Boolean !=(Duration,Duration)'") public static boolean notEquals(@Nonnull Duration left, @Nonnull Duration right) { return !left.equalsType(right); }
Duration second = new Duration(5, 565.0); AssertHelper.assertEquals(first, second); Assert.assertTrue(first.equalsType(second)); Assert.assertTrue(second.equalsType(first)); Assert.assertTrue(Duration.equals(first, second)); Assert.assertTrue(Duration.equals(second, first)); second = new Duration(4, 86399.99999); AssertHelper.assertNotEqual(first, second); Assert.assertFalse(first.equalsType(second)); Assert.assertFalse(second.equalsType(first)); Assert.assertFalse(Duration.equals(first, second)); Assert.assertFalse(Duration.equals(second, first));