Skip to content

Commit 8bfc231

Browse files
committed
#15 adding equals and hash & making the vImageType configurable
1 parent 76dc6eb commit 8bfc231

2 files changed

Lines changed: 49 additions & 12 deletions

File tree

epics-vtype/vtype/src/main/java/org/epics/vtype/VImage.java

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
package org.epics.vtype;
66

7+
import java.util.Objects;
8+
79
import org.epics.util.array.ListNumber;
810

911
/**
@@ -33,18 +35,17 @@ public abstract class VImage extends VType implements AlarmProvider, TimeProvide
3335
* @return ListNumber image data
3436
*/
3537
public abstract ListNumber getData();
36-
38+
3739
/**
38-
* Describes the type in which the data is stored
39-
* {@link VImageDataType}
40+
* Describes the type in which the data is stored {@link VImageDataType}
4041
*
41-
* @return image data type
42+
* @return image data type
4243
*/
4344
public abstract VImageDataType getDataType();
4445

4546
/**
46-
* Returns the image type, The image type describes the mechanism in which
47-
* the data is encoded and how it can be converted to something that can be
47+
* Returns the image type, The image type describes the mechanism in which the
48+
* data is encoded and how it can be converted to something that can be
4849
* rendered.
4950
*
5051
* @return the image type {@link VImageType}
@@ -53,14 +54,50 @@ public abstract class VImage extends VType implements AlarmProvider, TimeProvide
5354

5455
/**
5556
* Creates a new VImage.
56-
*
57+
*
5758
* @param value the value
5859
* @param alarm the alarm
5960
* @param time the time
6061
* @param display the display
61-
* @return the new value
62+
* @return the new Image
6263
*/
63-
public static VImage of(int height, int width, final ListNumber data, VImageDataType imageDataType, Alarm alarm, Time time) {
64-
return new IVImage(height, width, data, imageDataType, VImageType.TYPE_3BYTE_BGR, alarm, time);
64+
public static VImage of(int height, int width, final ListNumber data, VImageDataType imageDataType, VImageType vImageType, Alarm alarm, Time time) {
65+
return new IVImage(height, width, data, imageDataType, vImageType, alarm, time);
66+
}
67+
68+
@Override
69+
public final boolean equals(Object obj) {
70+
if (this == obj) {
71+
return true;
72+
}
73+
74+
if (obj instanceof VImage) {
75+
VImage other = (VImage) obj;
76+
77+
return getClass().equals(other.getClass())
78+
&& getHeight() == other.getHeight()
79+
&& getWidth() == other.getWidth()
80+
&& getData().equals(other.getData())
81+
&& getDataType().equals(other.getDataType())
82+
&& getVImageType().equals(other.getVImageType())
83+
&& getAlarm().equals(other.getAlarm())
84+
&& getTime().equals(other.getTime());
85+
}
86+
87+
return false;
6588
}
89+
90+
@Override
91+
public final int hashCode() {
92+
int hash = 7;
93+
hash = 23 * hash + Objects.hashCode(getHeight());
94+
hash = 23 * hash + Objects.hashCode(getWidth());
95+
hash = 23 * hash + Objects.hashCode(getData());
96+
hash = 23 * hash + Objects.hashCode(getDataType());
97+
hash = 23 * hash + Objects.hashCode(getVImageType());
98+
hash = 23 * hash + Objects.hashCode(getAlarm());
99+
hash = 23 * hash + Objects.hashCode(getTime());
100+
return hash;
101+
}
102+
66103
}

epics-vtype/vtype/src/test/java/org/epics/vtype/VImageTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public void of() {
2727
img = ImageIO.read(VType.class.getResource("Tulips.jpg"));
2828
vImage = VImage.of(img.getHeight(), img.getWidth(),
2929
ArrayByte.of(((DataBufferByte) img.getRaster().getDataBuffer()).getData()), VImageDataType.pvByte,
30+
VImageType.TYPE_3BYTE_BGR,
3031
Alarm.none(), Time.now());
3132
BufferedImage vImg = toImage(vImage);
3233
for (int x = 0; x < vImage.getWidth(); x++) {
@@ -49,8 +50,7 @@ public void of() {
4950

5051
private static BufferedImage toImage(VImage vImage) {
5152
if (vImage.getVImageType() == VImageType.TYPE_3BYTE_BGR) {
52-
BufferedImage image = new BufferedImage(vImage.getWidth(), vImage.getHeight(),
53-
BufferedImage.TYPE_3BYTE_BGR);
53+
BufferedImage image = new BufferedImage(vImage.getWidth(), vImage.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
5454
ListNumber data = vImage.getData();
5555
for (int i = 0; i < data.size(); i++) {
5656
((DataBufferByte) image.getRaster().getDataBuffer()).getData()[i] = data.getByte(i);

0 commit comments

Comments
 (0)