< prev index next >
src/java.desktop/share/classes/java/awt/image/ComponentSampleModel.java
Print this page
@@ -1185,23 +1185,70 @@
}
lineOffset += scanlineStride;
}
}
- public boolean equals(Object o) {
- if ((o == null) || !(o instanceof ComponentSampleModel)) {
+ /**
+ * Tests if the specified {@code Object} equals this
+ * {@code ComponentSampleModel}.
+ * 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 {@code equals}.
+ * <p>
+ * Subclasses may check additional properties, but this method
+ * will check the following basic properties for equivalence to
+ * determine if the target object equals this object:
+ *
+ * <ul>
+ * <li>Width in pixels of image data.
+ * <li>Height in pixels of image data.
+ * <li>Number of bands in the {@code ComponentSampleModel}.
+ * <li>Data type of the {@code DataBuffer} storing the pixel data.
+ * <li>Offsets for all bands in data array elements.
+ * <li>Index for each bank storing a band of image data.
+ * <li>The number of banks in the {@code ComponentSampleModel}.
+ * <li>Line stride of image data.
+ * <li>Pixel stride of image data.
+ * </ul>
+ * <p>
+ * Subclasses should override this method if they have any additional
+ * properties to compare and should use the following implementation.
+ * Note that the base {@code ComponentSampleModel} class already ensures
+ * that the target object is the same class as this object so the cast to
+ * the subclass type can be assumed if {@code super.equals(obj)} returns
+ * true.
+ * <pre>
+ * public boolean equals(Object obj) {
+ * if (!super.equals(obj)) {
+ * return false;
+ * }
+ * MyCMClass cm = (MyCMClass) obj;
+ * // test additional properties on "cm" and "this"
+ * }
+ * </pre>
+ * <p>
+ * @param obj the {@code Object} to test for equality
+ * @return {@code true} if the specified {@code Object}
+ * equals this {@code ComponentSampleModel}; {@code false} otherwise.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if ((obj == null) || (obj.getClass() != getClass())) {
return false;
}
- ComponentSampleModel that = (ComponentSampleModel)o;
+ ComponentSampleModel that = (ComponentSampleModel)obj;
return this.width == that.width &&
this.height == that.height &&
this.numBands == that.numBands &&
this.dataType == that.dataType &&
Arrays.equals(this.bandOffsets, that.bandOffsets) &&
Arrays.equals(this.bankIndices, that.bankIndices) &&
- this.numBands == that.numBands &&
this.numBanks == that.numBanks &&
this.scanlineStride == that.scanlineStride &&
this.pixelStride == that.pixelStride;
}
< prev index next >