下面列出了java.awt.image.IndexColorModel#equals() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static void verifyEquals(IndexColorModel m1,
IndexColorModel m2) {
if (m1.equals(null)) {
throw new RuntimeException("equals(null) returns true");
}
if (!(m1.equals(m2))) {
throw new RuntimeException("equals() method is not working"
+ " properly");
}
if (!(m2.equals(m1))) {
throw new RuntimeException("equals() method is not working"
+ " properly");
}
if (m1.hashCode() != m2.hashCode()) {
throw new RuntimeException("HashCode is not same for same"
+ " IndexColorModels");
}
}
private static void testSizeEquality() {
// test with different size for cmap.
IndexColorModel model1 = new IndexColorModel(8, 4,
new int[] {1, 2, 3, 4},
0, true, -1, DataBuffer.TYPE_BYTE);
IndexColorModel model2 = new IndexColorModel(8, 3,
new int[] {1, 2, 3},
0, true, -1, DataBuffer.TYPE_BYTE);
if (model1.equals(model2)) {
throw new RuntimeException("equals() method is determining"
+ " Map size equality improperly");
}
if (model2.equals(model1)) {
throw new RuntimeException("equals() method is determining"
+ " Map size equality improperly");
}
}
private static void testValidPixelsEquality() {
// test with different valid pixels.
/*
* In setRGBs() function of IndexColorModel we override
* transparent_index value to map to pixel value if alpha is 0x00
* so we should have atleast minimum alpha value to verify
* equality of validBits thats why we have color value as
* 16777216(2 ^ 24).
*/
int color = 16777216;
IndexColorModel model1 = new IndexColorModel(8, 3, new int[] {color,
color, color}, 0, DataBuffer.TYPE_BYTE, new BigInteger("1"));
IndexColorModel model2 = new IndexColorModel(8, 3, new int[] {color,
color, color}, 0, DataBuffer.TYPE_BYTE, new BigInteger("2"));
if (model1.equals(model2)) {
throw new RuntimeException("equals() method is determining"
+ " Valid pixels equality improperly");
}
if (model2.equals(model1)) {
throw new RuntimeException("equals() method is determining"
+ " Valid pixels equality improperly");
}
}
private static void testColorMapEquality() {
// test with different cmap values.
IndexColorModel model1 = new IndexColorModel(8, 3, new int[] {1, 2, 3},
0, true, -1, DataBuffer.TYPE_BYTE);
IndexColorModel model2 = new IndexColorModel(8, 3, new int[] {4, 5, 6},
0, true, -1, DataBuffer.TYPE_BYTE);
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 testTransparentIndexEquality() {
// test with different values for transparent_index.
IndexColorModel model1 = new IndexColorModel(8, 3, new int[] {1, 2, 3},
0, true, 1, DataBuffer.TYPE_BYTE);
IndexColorModel model2 = new IndexColorModel(8, 3, new int[] {1, 2, 3},
0, true, 2, DataBuffer.TYPE_BYTE);
if (model1.equals(model2)) {
throw new RuntimeException("equals() method is determining"
+ " TransparentIndex equality improperly");
}
if (model2.equals(model1)) {
throw new RuntimeException("equals() method is determining"
+ " TransparentIndex equality improperly");
}
}