/** * Indicates whether another object is exactly equal to this instance. * @param obj The object to compare to this instance. * @return {@code true} if {@code obj} is an instance of this type and represents the same value as this instance; otherwise, {@code false}. */ @Override public boolean equals(Object obj) { return obj instanceof BoundingRectangle && equalsType((BoundingRectangle) obj); }
/** * Returns {@code true} if the two instances are exactly equal. * @param left The instance to compare to {@code right}. * @param right The instance to compare to {@code left}. * @return {@code true} if {@code left} represents the same value as {@code right}; otherwise, {@code false}. */ @CS2JInfo("This method implements the functionality of the overloaded operator: 'System.Boolean ==(BoundingRectangle,BoundingRectangle)'") public static boolean equals(@Nonnull BoundingRectangle left, @Nonnull BoundingRectangle right) { return left.equalsType(right); }
/** * Returns {@code true} if the two instances are not exactly equal. * @param left The instance to compare to {@code right}. * @param right The instance to compare to {@code left}. * @return {@code true} if {@code left} does not represent the same value as {@code right}; otherwise, {@code false}. */ @CS2JInfo("This method implements the functionality of the overloaded operator: 'System.Boolean !=(BoundingRectangle,BoundingRectangle)'") public static boolean notEquals(@Nonnull BoundingRectangle left, @Nonnull BoundingRectangle right) { return !left.equalsType(right); }
/** * Tests the equality and inequality methods and operators. */ @Test public final void equalityTest() { BoundingRectangle boundingRectangle = new BoundingRectangle(1D, 2D, 3D, 4D); BoundingRectangle sameBoundingRectangle = new BoundingRectangle(1D, 2D, 3D, 4D); BoundingRectangle diffBoundingRectangle = new BoundingRectangle(2D, 3D, 4D, 5D); Assert.assertTrue(boundingRectangle.equalsType(sameBoundingRectangle)); Assert.assertFalse(boundingRectangle.equalsType(diffBoundingRectangle)); Assert.assertTrue(BoundingRectangle.equals(boundingRectangle, sameBoundingRectangle)); Assert.assertTrue(BoundingRectangle.notEquals(boundingRectangle, diffBoundingRectangle)); Object nonBoundingRectangleObject = new Object(); Assert.assertFalse(boundingRectangle.equals(nonBoundingRectangleObject)); Object boundingRectangleObject = boundingRectangle; Assert.assertTrue(boundingRectangle.equals(boundingRectangleObject)); }