Skip to content

Commit ca87c57

Browse files
committed
Merge branch 'master' into clean
Conflicts: epics-vtype/vtype/src/main/java/org/epics/vtype/VType.java
2 parents f801496 + 2e6fad6 commit ca87c57

9 files changed

Lines changed: 844 additions & 188 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package org.epics.vtype;
2+
3+
import org.epics.util.array.ListNumber;
4+
5+
/**
6+
* An immutable implementation of the {@link VImage}
7+
*
8+
* @author Kunal Shroff
9+
*
10+
*/
11+
public class IVImage extends VImage {
12+
13+
private final Alarm alarm;
14+
private final Time time;
15+
16+
private final int height;
17+
private final int width;
18+
private final ListNumber data;
19+
private final VImageDataType imageDataType;
20+
private final VImageType imageType;
21+
22+
IVImage(int height, int width, ListNumber data, VImageDataType imageDataType, VImageType imageType, Alarm alarm,
23+
Time time) {
24+
super();
25+
VType.argumentNotNull("alarm", alarm);
26+
VType.argumentNotNull("time", time);
27+
this.alarm = alarm;
28+
this.time = time;
29+
this.height = height;
30+
this.width = width;
31+
this.data = data;
32+
this.imageDataType = imageDataType;
33+
this.imageType = imageType;
34+
}
35+
36+
public int getHeight() {
37+
return height;
38+
}
39+
40+
public int getWidth() {
41+
return width;
42+
}
43+
44+
public ListNumber getData() {
45+
return data;
46+
}
47+
48+
@Override
49+
public Alarm getAlarm() {
50+
return alarm;
51+
}
52+
53+
@Override
54+
public Time getTime() {
55+
return time;
56+
}
57+
58+
@Override
59+
public VImageDataType getDataType() {
60+
return imageDataType;
61+
}
62+
63+
@Override
64+
public VImageType getVImageType() {
65+
return imageType;
66+
}
67+
68+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Copyright (C) 2010-18 diirt developers. See COPYRIGHT.TXT
3+
* All rights reserved. Use is subject to license terms. See LICENSE.TXT
4+
*/
5+
package org.epics.vtype;
6+
7+
import java.util.List;
8+
import org.epics.util.array.ListNumber;
9+
10+
/**
11+
* An immutable table that extends {@link VTable}
12+
*
13+
* @author carcassi, shroff
14+
*/
15+
class IVTable extends VTable {
16+
17+
private final List<Class<?>> types;
18+
private final List<String> names;
19+
private final List<Object> values;
20+
private final int rowCount;
21+
22+
IVTable(List<Class<?>> types, List<String> names, List<Object> values) {
23+
this.types = types;
24+
this.names = names;
25+
this.values = values;
26+
int maxCount = 0;
27+
for (Object array : values) {
28+
maxCount = Math.max(maxCount, getDataSize(array));
29+
}
30+
this.rowCount = maxCount;
31+
}
32+
33+
private static int getDataSize(Object data) {
34+
if (data instanceof List) {
35+
return ((List) data).size();
36+
} else if (data instanceof ListNumber) {
37+
return ((ListNumber) data).size();
38+
}
39+
40+
throw new IllegalArgumentException("Object " + data + " is not supported");
41+
}
42+
43+
@Override
44+
public int getColumnCount() {
45+
return names.size();
46+
}
47+
48+
@Override
49+
public int getRowCount() {
50+
return rowCount;
51+
}
52+
53+
@Override
54+
public Class<?> getColumnType(int column) {
55+
return types.get(column);
56+
}
57+
58+
@Override
59+
public String getColumnName(int column) {
60+
return names.get(column);
61+
}
62+
63+
@Override
64+
public Object getColumnData(int column) {
65+
return values.get(column);
66+
}
67+
68+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**
2+
* Copyright (C) 2010-18 diirt developers. See COPYRIGHT.TXT
3+
* All rights reserved. Use is subject to license terms. See LICENSE.TXT
4+
*/
5+
package org.epics.vtype;
6+
7+
import java.util.Objects;
8+
9+
import org.epics.util.array.ListNumber;
10+
11+
/**
12+
* VImage represents an image.
13+
*
14+
* @author carcassi, shroff
15+
*/
16+
public abstract class VImage extends VType implements AlarmProvider, TimeProvider {
17+
18+
/**
19+
* Height of the image in pixels.
20+
*
21+
* @return image height
22+
*/
23+
public abstract int getHeight();
24+
25+
/**
26+
* Width of the image in pixels.
27+
*
28+
* @return image width
29+
*/
30+
public abstract int getWidth();
31+
32+
/**
33+
* Image data;
34+
*
35+
* @return ListNumber image data
36+
*/
37+
public abstract ListNumber getData();
38+
39+
/**
40+
* Describes the type in which the data is stored {@link VImageDataType}
41+
*
42+
* @return image data type
43+
*/
44+
public abstract VImageDataType getDataType();
45+
46+
/**
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
49+
* rendered.
50+
*
51+
* @return the image type {@link VImageType}
52+
*/
53+
public abstract VImageType getVImageType();
54+
55+
/**
56+
* Creates a new VImage.
57+
*
58+
* @param value the value
59+
* @param alarm the alarm
60+
* @param time the time
61+
* @param display the display
62+
* @return the new Image
63+
*/
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;
88+
}
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+
103+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/**
2+
* Copyright (C) 2010-18 diirt developers. See COPYRIGHT.TXT
3+
* All rights reserved. Use is subject to license terms. See LICENSE.TXT
4+
*/
5+
package org.epics.vtype;
6+
/**
7+
*
8+
* Data type description for {@link VImage} data.
9+
*
10+
* based on the the VImageDataType from org.epics.pvdata.pv
11+
* @author mrk
12+
*
13+
*/
14+
public enum VImageDataType {
15+
/**
16+
* Value has type <i>boolean</i>.
17+
*/
18+
pvBoolean,
19+
/**
20+
* Value has type <i>byte</i>.
21+
*/
22+
pvByte,
23+
/**
24+
* Value has type <i>short</i>.
25+
*/
26+
pvShort,
27+
/**
28+
* Value has type <i>int</i>.
29+
*/
30+
pvInt,
31+
/**
32+
* Value has type <i>long</i>.
33+
*/
34+
pvLong,
35+
/**
36+
* Value has type <i>ubyte</i>.
37+
*/
38+
pvUByte,
39+
/**
40+
* Value has type <i>ushort</i>.
41+
*/
42+
pvUShort,
43+
/**
44+
* Value has type <i>uint</i>.
45+
*/
46+
pvUInt,
47+
/**
48+
* Value has type <i>ulong</i>.
49+
*/
50+
pvULong,
51+
/**
52+
* value has type <i>float</i>.
53+
*/
54+
pvFloat,
55+
/**
56+
* Value has type <i>double</i>.
57+
*/
58+
pvDouble,
59+
/**
60+
* Value has type <i>string</i>.
61+
*/
62+
pvString;
63+
64+
/**
65+
* Is this an integer (signed or unsigned). true if byte, short, int, long, ubyte, ushort, uint, or ulong.
66+
* @return true if it is an integer type
67+
*/
68+
public boolean isInteger() {
69+
if( (ordinal() >= VImageDataType.pvByte.ordinal()) && (ordinal() <= VImageDataType.pvULong.ordinal()) ) {
70+
return true;
71+
}
72+
return false;
73+
}
74+
75+
/**
76+
* Is this an unsigned integer. true if ubyte, ushort, uint, or ulong.
77+
*
78+
* @return true if it is an unsigned integer type
79+
*/
80+
public boolean isUInteger() {
81+
if( (ordinal() >= VImageDataType.pvUByte.ordinal()) && (ordinal() <= VImageDataType.pvULong.ordinal()) ) {
82+
return true;
83+
}
84+
return false;
85+
}
86+
87+
/**
88+
* Is this a Java numeric type?
89+
*
90+
* @return true if the type is a Java numeric type.
91+
* The numeric types are byte, short, int, long, float, and double.
92+
*/
93+
public boolean isNumeric() {
94+
if( (ordinal() >= VImageDataType.pvByte.ordinal()) && (ordinal() <= VImageDataType.pvDouble.ordinal()) ) {
95+
return true;
96+
}
97+
return false;
98+
}
99+
100+
/**
101+
* Is this a Java primitive type?
102+
*
103+
* @return true if the type is a Java primitive type.
104+
* The numeric types and boolean are primitive types.
105+
*/
106+
public boolean isPrimitive() {
107+
if(isNumeric()) return true;
108+
if(ordinal() == VImageDataType.pvBoolean.ordinal()) return true;
109+
return false;
110+
}
111+
112+
/**
113+
* Get the VImageDataType for a string defining the type.
114+
*
115+
* @param type a character string defining the type
116+
* @return the VImageDataType or null if an illegal type
117+
*/
118+
public static VImageDataType getVImageDataType(String type) {
119+
if(type.equals("boolean")) return VImageDataType.pvBoolean;
120+
if(type.equals("byte")) return VImageDataType.pvByte;
121+
if(type.equals("short")) return VImageDataType.pvShort;
122+
if(type.equals("int")) return VImageDataType.pvInt;
123+
if(type.equals("long")) return VImageDataType.pvLong;
124+
if(type.equals("ubyte")) return VImageDataType.pvUByte;
125+
if(type.equals("ushort")) return VImageDataType.pvUShort;
126+
if(type.equals("uint")) return VImageDataType.pvUInt;
127+
if(type.equals("ulong")) return VImageDataType.pvULong;
128+
if(type.equals("float")) return VImageDataType.pvFloat;
129+
if(type.equals("double")) return VImageDataType.pvDouble;
130+
if(type.equals("string")) return VImageDataType.pvString;
131+
return null;
132+
}
133+
public String toString() {
134+
switch(this) {
135+
case pvBoolean: return "boolean";
136+
case pvByte: return "byte";
137+
case pvShort: return "short";
138+
case pvInt: return "int";
139+
case pvLong: return "long";
140+
case pvUByte: return "ubyte";
141+
case pvUShort: return "ushort";
142+
case pvUInt: return "uint";
143+
case pvULong: return "ulong";
144+
case pvFloat: return "float";
145+
case pvDouble: return "double";
146+
case pvString: return "string";
147+
}
148+
throw new IllegalArgumentException("Unknown VImageDataType");
149+
}
150+
}

0 commit comments

Comments
 (0)