< prev index next >
src/java.desktop/share/classes/java/awt/image/IndexColorModel.java
Print this page
*** 26,35 ****
--- 26,37 ----
package java.awt.image;
import java.awt.Transparency;
import java.awt.color.ColorSpace;
import java.math.BigInteger;
+ import java.util.Arrays;
+ import java.util.Objects;
/**
* The {@code IndexColorModel} class is a {@code ColorModel}
* class that works with pixel values consisting of a
* single sample that is an index into a fixed colormap in the default
*** 1530,1535 ****
--- 1532,1608 ----
+ " transIndex = "+transparent_index
+ " has alpha = "+supportsAlpha
+ " isAlphaPre = "+isAlphaPremultiplied
);
}
+
+ /**
+ * Tests if the specified {@code Object} is an instance
+ * of {@code IndexColorModel} and equals this
+ * {@code IndexColorModel}.
+ * @param obj the {@code Object} to test for equality
+ * @return {@code true} if the specified {@code Object}
+ * is an instance of {@code IndexColorModel} and equals this
+ * {@code IndexColorModel}; {@code false} otherwise.
+ */
+ @Override
+ public boolean equals(Object obj) {
+
+ if (!(obj instanceof IndexColorModel)) {
+ return false;
+ }
+
+ IndexColorModel cm = (IndexColorModel) obj;
+ if (this == cm) {
+ return true;
+ }
+
+ if (!super.equals(obj)) {
+ return false;
+ }
+
+ if (map_size != cm.map_size ||
+ transparent_index != cm.transparent_index)
+ {
+ return false;
+ }
+
+ if (validBits == null) {
+ if (cm.validBits != null) {
+ return false;
+ }
+ for (int i = 0; i < map_size; i++) {
+ if (rgb[i] != cm.rgb[i]) {
+ return false;
+ }
+ }
+ } else {
+ if (cm.validBits == null) {
+ return false;
+ }
+ for (int i = 0; i < map_size; i++) {
+ if (rgb[i] != cm.rgb[i] ||
+ isValid(i) != cm.isValid(i))
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Returns the hash code for IndexColorModel.
+ *
+ * @return a hash code for IndexColorModel
+ */
+ @Override
+ public int hashCode() {
+ int hash = 7;
+ hash = 43 * hash + super.hashCode();
+ hash = 43 * hash + Arrays.hashCode(this.rgb);
+ hash = 43 * hash + this.map_size;
+ hash = 43 * hash + this.transparent_index;
+ hash = 43 * hash + Objects.hashCode(this.validBits);
+ return hash;
+ }
}
< prev index next >