Viewport { @Override public int hashCode() { int result; long temp; temp = Double.doubleToLongBits(this.x); result = (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.y); result = 31 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.width); result = 31 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.height); result = 31 * result + (int) (temp ^ (temp >>> 32)); return result; } Viewport();  Viewport(int x, int y, int width, int height);  Viewport(Viewport viewport); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); Viewport set(int x, int y, int width, int height); Viewport set(Viewport viewport); Viewport setEmpty(); boolean isEmpty(); boolean intersects(int x, int y, int width, int height); @SuppressWarnings("UnnecessaryLocalVariable") boolean intersects(Viewport viewport); boolean intersect(int x, int y, int width, int height); @SuppressWarnings("UnnecessaryLocalVariable") boolean intersect(Viewport viewport); boolean contains(int x, int y); public int x; public int y; public int width; public int height; }
@Test public void testHashCode() throws Exception { Viewport viewport1 = new Viewport(1, 2, 3, 4); Viewport viewport2 = new Viewport(viewport1); Viewport viewport3 = new Viewport(4, 3, 2, 1); int hashCode1 = viewport1.hashCode(); int hashCode2 = viewport2.hashCode(); int hashCode3 = viewport3.hashCode(); assertEquals(hashCode1, hashCode2); assertNotEquals(hashCode1, hashCode3); }