--- old/src/java.desktop/share/classes/java/awt/image/ComponentColorModel.java 2016-04-20 18:01:09.633158635 +0530 +++ new/src/java.desktop/share/classes/java/awt/image/ComponentColorModel.java 2016-04-20 18:01:08.964824636 +0530 @@ -2927,22 +2927,42 @@ } /** - * Compares this color model with another for equality. - * - * @param obj The object to compare with this color model. - * @return {@code true} if the color model objects are equal, - * {@code false} if they are not. + * Tests if the specified {@code Object} is an instance + * of {@code ComponentColorModel} and equals this + * {@code ComponentColorModel}. + * @param obj the {@code Object} to test for equality + * @return {@code true} if the specified {@code Object} + * is an instance of {@code ComponentColorModel} and equals this + * {@code ComponentColorModel}; {@code false} otherwise. */ + @Override public boolean equals(Object obj) { - if (!super.equals(obj)) { + + if (!(obj instanceof ComponentColorModel)) { return false; } + + ComponentColorModel cm = (ComponentColorModel) obj; + if (this == cm) { + return true; + } - if (obj.getClass() != getClass()) { + if (!super.equals(obj)) { return false; } - return true; } + /** + * Returns the hash code for this ComponentColorModel. + * + * @return a hash code for this ComponentColorModel. + */ + @Override + public int hashCode() { + int hash = 7; + hash = 79 * hash + super.hashCode(); + return hash; + } + } --- old/src/java.desktop/share/classes/java/awt/image/PackedColorModel.java 2016-04-20 18:01:11.093888636 +0530 +++ new/src/java.desktop/share/classes/java/awt/image/PackedColorModel.java 2016-04-20 18:01:10.717700636 +0530 @@ -27,6 +27,7 @@ import java.awt.Transparency; import java.awt.color.ColorSpace; +import java.util.Arrays; /** * The {@code PackedColorModel} class is an abstract @@ -393,16 +394,22 @@ * is an instance of {@code PackedColorModel} and equals this * {@code PackedColorModel}; {@code false} otherwise. */ + @Override public boolean equals(Object obj) { + if (!(obj instanceof PackedColorModel)) { return false; } + PackedColorModel cm = (PackedColorModel) obj; + if (this == cm) { + return true; + } + if (!super.equals(obj)) { return false; } - PackedColorModel cm = (PackedColorModel) obj; int numC = cm.getNumComponents(); for(int i=0; i < numC; i++) { if (maskArray[i] != cm.getMask(i)) { @@ -412,6 +419,19 @@ return true; } + /** + * Returns the hash code for this PackedColorModel. + * + * @return a hash code for this PackedColorModel. + */ + @Override + public int hashCode() { + int hash = 3; + hash = 89 * hash + super.hashCode(); + hash = 89 * hash + Arrays.hashCode(this.maskArray); + return hash; + } + private static final int[] createBitsArray(int[]colorMaskArray, int alphaMask) { int numColors = colorMaskArray.length; --- old/src/java.desktop/share/classes/java/awt/image/PixelInterleavedSampleModel.java 2016-04-20 18:01:12.706694636 +0530 +++ new/src/java.desktop/share/classes/java/awt/image/PixelInterleavedSampleModel.java 2016-04-20 18:01:12.134408636 +0530 @@ -164,8 +164,42 @@ scanlineStride, newBandOffsets); } - // Differentiate hash code from other ComponentSampleModel subclasses + /** + * Tests if the specified {@code Object} is an instance + * of {@code PixelInterleavedSampleModel} and equals this + * {@code PixelInterleavedSampleModel}. + * @param obj the {@code Object} to test for equality + * @return {@code true} if the specified {@code Object} + * is an instance of {@code PixelInterleavedSampleModel} and equals this + * {@code PixelInterleavedSampleModel}; {@code false} otherwise. + */ + @Override + public boolean equals(Object obj) { + + if (!(obj instanceof PixelInterleavedSampleModel)) { + return false; + } + + PixelInterleavedSampleModel cm = (PixelInterleavedSampleModel) obj; + if (this == cm) { + return true; + } + + if (!super.equals(obj)) { + return false; + } + return true; + } + + /** + * Returns the hash code for this PixelInterleavedSampleModel. + * + * @return a hash code for this PixelInterleavedSampleModel. + */ + @Override public int hashCode() { - return super.hashCode() ^ 0x1; + int hash = 3; + hash = 11 * hash + super.hashCode(); + return hash; } } --- old/src/java.desktop/share/classes/java/awt/image/BandedSampleModel.java 2016-04-20 18:01:14.667674636 +0530 +++ new/src/java.desktop/share/classes/java/awt/image/BandedSampleModel.java 2016-04-20 18:01:14.023352635 +0530 @@ -842,8 +842,42 @@ return bankIndices; } - // Differentiate hash code from other ComponentSampleModel subclasses + /** + * Tests if the specified {@code Object} is an instance + * of {@code BandedSampleModel} and equals this + * {@code BandedSampleModel}. + * @param obj the {@code Object} to test for equality + * @return {@code true} if the specified {@code Object} + * is an instance of {@code BandedSampleModel} and equals this + * {@code BandedSampleModel}; {@code false} otherwise. + */ + @Override + public boolean equals(Object obj) { + + if (!(obj instanceof BandedSampleModel)) { + return false; + } + + BandedSampleModel cm = (BandedSampleModel) obj; + if (this == cm) { + return true; + } + + if (!super.equals(obj)) { + return false; + } + return true; + } + + /** + * Returns the hash code for this BandedSampleModel. + * + * @return a hash code for this BandedSampleModel. + */ + @Override public int hashCode() { - return super.hashCode() ^ 0x2; + int hash = 5; + hash = 13 * hash + super.hashCode(); + return hash; } } --- /dev/null 2016-04-20 11:11:33.642641000 +0530 +++ new/test/java/awt/image/ComponentColorModel/ComponentColorModelEqualsTest.java 2016-04-20 18:01:15.416048636 +0530 @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8153943 + * @summary Test verifies whether equals() and hashCode() methods in + * ComponentColorModel works properly. + * @run main ComponentColorModelEqualsTest + */ + +import java.awt.Transparency; +import java.awt.color.ColorSpace; +import java.awt.image.ComponentColorModel; +import java.awt.image.DataBuffer; + +public class ComponentColorModelEqualsTest { + + private static void testConstructor1() { + /* + * verify equality with constructor + * ComponentColorModel(ColorSpace colorSpace, + * int[] bits, + * boolean hasAlpha, + * boolean isAlphaPremultiplied, + * int transparency, + * int transferType) + */ + ComponentColorModel model1 = + new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), + new int[] {8, 8, 8}, + false, + false, + Transparency.OPAQUE, + DataBuffer.TYPE_BYTE); + ComponentColorModel model2 = + new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), + new int[] {8, 8, 8}, + false, + false, + Transparency.OPAQUE, + DataBuffer.TYPE_BYTE); + if (model1.equals(null)) { + throw new RuntimeException("equals(null) returns true"); + } + if (!(model1.equals(model2))) { + throw new RuntimeException("equals() method is not working" + + " properly"); + } + if (!(model2.equals(model1))) { + throw new RuntimeException("equals() method is not working" + + " properly"); + } + if (model1.hashCode() != model2.hashCode()) { + throw new RuntimeException("HashCode is not same for same" + + " ComponentColorModels"); + } + } + + private static void testConstructor2() { + /* + * verify equality with constructor + * ComponentColorModel(ColorSpace colorSpace, + * boolean hasAlpha, + * boolean isAlphaPremultiplied, + * int transparency, + * int transferType) + */ + ComponentColorModel model1 = + new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), + false, + false, + Transparency.OPAQUE, + DataBuffer.TYPE_BYTE); + ComponentColorModel model2 = + new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), + false, + false, + Transparency.OPAQUE, + DataBuffer.TYPE_BYTE); + if (model1.equals(null)) { + throw new RuntimeException("equals(null) returns true"); + } + if (!(model1.equals(model2))) { + throw new RuntimeException("equals() method is not working" + + " properly"); + } + if (!(model2.equals(model1))) { + throw new RuntimeException("equals() method is not working" + + " properly"); + } + if (model1.hashCode() != model2.hashCode()) { + throw new RuntimeException("HashCode is not same for same" + + " ComponentColorModels"); + } + } + + private static void testSameComponentColorModel() { + testConstructor1(); + testConstructor2(); + } + public static void main(String[] args) { + // verify ComponentColorModel equality using different constructors. + testSameComponentColorModel(); + } +} \ No newline at end of file --- /dev/null 2016-04-20 11:11:33.642641000 +0530 +++ new/test/java/awt/image/PackedColorModel/PackedColorModelEqualsTest.java 2016-04-20 18:01:16.776728636 +0530 @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8153943 + * @summary Test verifies whether equals() and hashCode() methods in + * PackedColorModel works properly. + * @run main PackedColorModelEqualsTest + */ + +import java.awt.color.ColorSpace; +import java.awt.image.DataBuffer; +import java.awt.image.DirectColorModel; + +public class PackedColorModelEqualsTest { + + private static void testMaskArrayEquality() { + /* + * Test with different maskArray values, since PackedColorModel + * is abstract we use subclass DirectColorModel. + */ + DirectColorModel model1 = + new DirectColorModel(24, 0x00FF0000, 0x0000FF00, 0x000000FF); + DirectColorModel model2 = + new DirectColorModel(24, 0x000000FF, 0x0000FF00, 0x00FF0000); + if (model1.equals(model2)) { + throw new RuntimeException("equals() method is determining" + + " ColorMap equality improperly"); + } + if (model2.equals(model1)) { + throw new RuntimeException("equals() method is determining" + + " ColorMap equality improperly"); + } + } + + private static void testConstructor1() { + /* + * verify equality with constructor + * DirectColorModel(int bits, int rmask, int gmask, int bmask, + * int amask) + */ + DirectColorModel model1 = + new DirectColorModel(32, 0xFF000000, 0x00FF0000, + 0x0000FF00, 0x000000FF); + DirectColorModel model2 = + new DirectColorModel(32, 0xFF000000, 0x00FF0000, + 0x0000FF00, 0x000000FF); + if (model1.equals(null)) { + throw new RuntimeException("equals(null) returns true"); + } + if (!(model1.equals(model2))) { + throw new RuntimeException("equals() method is not working" + + " properly"); + } + if (!(model2.equals(model1))) { + throw new RuntimeException("equals() method is not working" + + " properly"); + } + if (model1.hashCode() != model2.hashCode()) { + throw new RuntimeException("HashCode is not same for same" + + " PackedColorModels"); + } + } + + private static void testConstructor2() { + /* + * verify equality with constructor + * DirectColorModel(ColorSpace space, int bits, int rmask, int gmask, + * int bmask, int amask, boolean isAlphaPremultiplied, int transferType) + */ + DirectColorModel model1 = + new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), + 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF, + false, DataBuffer.TYPE_BYTE); + DirectColorModel model2 = + new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), + 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF, + false, DataBuffer.TYPE_BYTE); + if (model1.equals(null)) { + throw new RuntimeException("equals(null) returns true"); + } + if (!(model1.equals(model2))) { + throw new RuntimeException("equals() method is not working" + + " properly"); + } + if (!(model2.equals(model1))) { + throw new RuntimeException("equals() method is not working" + + " properly"); + } + if (model1.hashCode() != model2.hashCode()) { + throw new RuntimeException("HashCode is not same for same" + + " PackedColorModels"); + } + } + + private static void testSamePackedColorModel() { + testConstructor1(); + testConstructor2(); + } + public static void main(String[] args) { + // test with different mask array. + testMaskArrayEquality(); + // verify PackedColorModel equality using different constructors. + testSamePackedColorModel(); + } +} \ No newline at end of file --- /dev/null 2016-04-20 11:11:33.642641000 +0530 +++ new/test/java/awt/image/PixelInterleavedSampleModel/PixelInterleavedSampleModelEqualsTest.java 2016-04-20 18:01:18.465572635 +0530 @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8153943 + * @summary Test verifies whether equals() and hashCode() methods in + * PixelInterleavedSampleModel works properly. + * @run main PixelInterleavedSampleModelEqualsTest + */ + +import java.awt.image.DataBuffer; +import java.awt.image.PixelInterleavedSampleModel; + +public class PixelInterleavedSampleModelEqualsTest { + + private static void testSamePixelInterleavedSampleModel() { + /* + * verify equality with only one present constructor + * PixelInterleavedSampleModel(int dataType, int w, int h, + * int pixelStride, int scanlineStride, int[] bandOffsets) + */ + PixelInterleavedSampleModel model1 = + new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, 50, 50, + 1, 50, new int[] {0}); + PixelInterleavedSampleModel model2 = + new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, 50, 50, + 1, 50, new int[] {0}); + if (model1.equals(null)) { + throw new RuntimeException("equals(null) returns true"); + } + if (!(model1.equals(model2))) { + throw new RuntimeException("equals() method is not working" + + " properly"); + } + if (!(model2.equals(model1))) { + throw new RuntimeException("equals() method is not working" + + " properly"); + } + if (model1.hashCode() != model2.hashCode()) { + throw new RuntimeException("HashCode is not same for same" + + " PixelInterleavedSampleModels"); + } + } + + public static void main(String[] args) { + /* + * verify PixelInterleavedSampleModel equality using different + * constructors. + */ + testSamePixelInterleavedSampleModel(); + } +} \ No newline at end of file --- /dev/null 2016-04-20 11:11:33.642641000 +0530 +++ new/test/java/awt/image/BandedSampleModel/BandedSampleModelEqualsTest.java 2016-04-20 18:01:19.970324636 +0530 @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8153943 + * @summary Test verifies whether equals() and hashCode() methods in + * BandedSampleModel works properly. + * @run main BandedSampleModelEqualsTest + */ + +import java.awt.image.BandedSampleModel; +import java.awt.image.DataBuffer; + +public class BandedSampleModelEqualsTest { + + private static void testConstructor1() { + /* + * verify equality with constructor + * BandedSampleModel(int dataType, int w, int h, int numBands) + */ + BandedSampleModel model1 = + new BandedSampleModel(DataBuffer.TYPE_BYTE, 50, 50, 1); + BandedSampleModel model2 = + new BandedSampleModel(DataBuffer.TYPE_BYTE, 50, 50, 1); + if (model1.equals(null)) { + throw new RuntimeException("equals(null) returns true"); + } + if (!(model1.equals(model2))) { + throw new RuntimeException("equals() method is not working" + + " properly"); + } + if (!(model2.equals(model1))) { + throw new RuntimeException("equals() method is not working" + + " properly"); + } + if (model1.hashCode() != model2.hashCode()) { + throw new RuntimeException("HashCode is not same for same" + + " BandedSampleModels"); + } + } + + private static void testConstructor2() { + /* + * verify equality with constructor + * BandedSampleModel(int dataType, int w, int h, int scanlineStride, + * int[] bankIndices, int[] bandOffsets) + */ + BandedSampleModel model1 = + new BandedSampleModel(DataBuffer.TYPE_BYTE, 50, 50, 50, + new int[] {0}, new int[] {0}); + BandedSampleModel model2 = + new BandedSampleModel(DataBuffer.TYPE_BYTE, 50, 50, 50, + new int[] {0}, new int[] {0}); + if (model1.equals(null)) { + throw new RuntimeException("equals(null) returns true"); + } + if (!(model1.equals(model2))) { + throw new RuntimeException("equals() method is not working" + + " properly"); + } + if (!(model2.equals(model1))) { + throw new RuntimeException("equals() method is not working" + + " properly"); + } + if (model1.hashCode() != model2.hashCode()) { + throw new RuntimeException("HashCode is not same for same" + + " BandedSampleModels"); + } + } + + public static void testSameBandedSampleModel() { + testConstructor1(); + testConstructor2(); + } + public static void main(String[] args) { + /* + * verify BandedSampleModel equality using different + * constructors. + */ + testSameBandedSampleModel(); + } +} \ No newline at end of file