< prev index next >

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

Print this page

        

*** 29,42 **** import java.awt.color.ColorSpace; import java.awt.color.ICC_ColorSpace; import sun.java2d.cmm.CMSManager; import sun.java2d.cmm.ColorTransform; import sun.java2d.cmm.PCMM; ! import java.awt.Toolkit; import java.util.Collections; import java.util.Map; import java.util.WeakHashMap; /** * The {@code ColorModel} abstract class encapsulates the * methods for translating a pixel value to color components * (for example, red, green, and blue) and an alpha component. --- 29,43 ---- import java.awt.color.ColorSpace; import java.awt.color.ICC_ColorSpace; import sun.java2d.cmm.CMSManager; import sun.java2d.cmm.ColorTransform; import sun.java2d.cmm.PCMM; ! import java.util.Arrays; import java.util.Collections; import java.util.Map; import java.util.WeakHashMap; + import java.util.Objects; /** * The {@code ColorModel} abstract class encapsulates the * methods for translating a pixel value to color components * (for example, red, green, and blue) and an alpha component.
*** 1439,1470 **** return getNormalizedComponents(components, 0, normComponents, normOffset); } /** ! * Tests if the specified {@code Object} is an instance of ! * {@code ColorModel} and if it equals this * {@code ColorModel}. * @param obj the {@code Object} to test for equality * @return {@code true} if the specified {@code Object} ! * is an instance of {@code ColorModel} and equals this ! * {@code ColorModel}; {@code false} otherwise. */ public boolean equals(Object obj) { ! if (!(obj instanceof ColorModel)) { return false; } - ColorModel cm = (ColorModel) obj; ! if (this == cm) { ! return true; ! } if (supportsAlpha != cm.hasAlpha() || isAlphaPremultiplied != cm.isAlphaPremultiplied() || pixel_bits != cm.getPixelSize() || transparency != cm.getTransparency() || ! numComponents != cm.getNumComponents()) { return false; } int[] nb = cm.getComponentSize(); --- 1440,1476 ---- return getNormalizedComponents(components, 0, normComponents, normOffset); } /** ! * Tests if the specified {@code Object} equals this * {@code ColorModel}. + * In order to protect the symmetry property of + * {@code (a.equals(b) == b.equals(a))}, + * the target object must be the exact same class 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 ColorModel}; {@code false} otherwise. */ + @Override public boolean equals(Object obj) { ! if (this == obj) { ! return true; ! } ! if ((obj == null) || (obj.getClass() != getClass())) { return false; } ! ColorModel cm = (ColorModel) obj; if (supportsAlpha != cm.hasAlpha() || isAlphaPremultiplied != cm.isAlphaPremultiplied() || pixel_bits != cm.getPixelSize() || transparency != cm.getTransparency() || ! numComponents != cm.getNumComponents() || ! colorSpace != cm.colorSpace || ! transferType != cm.transferType) { return false; } int[] nb = cm.getComponentSize();
*** 1485,1511 **** /** * Returns the hash code for this ColorModel. * * @return a hash code for this ColorModel. */ public int hashCode() { ! ! int result = 0; ! ! result = (supportsAlpha ? 2 : 3) + ! (isAlphaPremultiplied ? 4 : 5) + ! pixel_bits * 6 + ! transparency * 7 + ! numComponents * 8; ! ! if (nBits != null) { ! for (int i = 0; i < numComponents; i++) { ! result = result + nBits[i] * (i + 9); ! } ! } ! ! return result; } /** * Returns the {@code ColorSpace} associated with this * {@code ColorModel}. --- 1491,1512 ---- /** * Returns the hash code for this ColorModel. * * @return a hash code for this ColorModel. */ + @Override public int hashCode() { ! int hash = 7; ! hash = 89 * hash + this.pixel_bits; ! hash = 89 * hash + Arrays.hashCode(this.nBits); ! hash = 89 * hash + this.transparency; ! hash = 89 * hash + (this.supportsAlpha ? 1 : 0); ! hash = 89 * hash + (this.isAlphaPremultiplied ? 1 : 0); ! hash = 89 * hash + this.numComponents; ! hash = 89 * hash + Objects.hashCode(this.colorSpace); ! hash = 89 * hash + this.transferType; ! return hash; } /** * Returns the {@code ColorSpace} associated with this * {@code ColorModel}.
< prev index next >