< prev index next >

src/java.desktop/share/classes/java/awt/image/PackedColorModel.java

Print this page

        

*** 25,34 **** --- 25,35 ---- package java.awt.image; import java.awt.Transparency; import java.awt.color.ColorSpace; + import java.util.Arrays; /** * The {@code PackedColorModel} class is an abstract * {@link ColorModel} class that works with pixel values which represent * color and alpha information as separate samples and which pack all
*** 86,95 **** --- 87,97 ---- public abstract class PackedColorModel extends ColorModel { int[] maskArray; int[] maskOffsets; float[] scaleFactors; + private volatile int hashCode; /** * Constructs a {@code PackedColorModel} from a color mask array, * which specifies which bits in an {@code int} pixel representation * contain each of the color samples, and an alpha mask. Color
*** 383,405 **** raster.getHeight(), x, y, band); } /** ! * Tests if the specified {@code Object} is an instance ! * of {@code PackedColorModel} and equals this * {@code PackedColorModel}. * @param obj the {@code Object} to test for equality * @return {@code true} if the specified {@code Object} ! * is an instance of {@code PackedColorModel} and equals this ! * {@code PackedColorModel}; {@code false} otherwise. */ public boolean equals(Object obj) { ! if (!(obj instanceof PackedColorModel)) { ! return false; ! } ! if (!super.equals(obj)) { return false; } PackedColorModel cm = (PackedColorModel) obj; --- 385,410 ---- raster.getHeight(), x, y, band); } /** ! * Tests if the specified {@code Object} equals this * {@code PackedColorModel}. + * In order to protect the symmetry property of + * {@code (a.equals(b) == b.equals(a))}, + * the target object must be the same class(and not a subclass) + * as this object to evaluate as {equals}. * @param obj the {@code Object} to test for equality * @return {@code true} if the specified {@code Object} ! * equals this {@code PackedColorModel}; {@code false} otherwise. */ + @Override public boolean equals(Object obj) { ! /* ! * We verify the type of argument obj in super.equals() where we check ! * for equality of class name. ! */ if (!super.equals(obj)) { return false; } PackedColorModel cm = (PackedColorModel) obj;
*** 410,419 **** --- 415,440 ---- } } return true; } + /** + * Returns the hash code for this PackedColorModel. + * + * @return a hash code for this PackedColorModel. + */ + @Override + public int hashCode() { + int result = hashCode; + if (result == 0) { + result = super.hashCode(); + result = 89 * result + Arrays.hashCode(this.maskArray); + hashCode = result; + } + return result; + } + private static final int[] createBitsArray(int[]colorMaskArray, int alphaMask) { int numColors = colorMaskArray.length; int numAlpha = (alphaMask == 0 ? 0 : 1); int[] arr = new int[numColors+numAlpha];
< prev index next >