Skip to content

Commit 6f0b0b1

Browse files
committed
Adding missing types EnumArray and BooleanArray
1 parent 7dd9d7a commit 6f0b0b1

5 files changed

Lines changed: 191 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.epics.vtype;
2+
3+
import org.epics.util.array.ListBoolean;
4+
import org.epics.util.array.ListInteger;
5+
6+
public class IVBooleanArray extends VBooleanArray {
7+
8+
private final ListBoolean data;
9+
private final Alarm alarm;
10+
private final Time time;
11+
private final ListInteger sizes;
12+
13+
IVBooleanArray(ListBoolean data, ListInteger sizes, Alarm alarm, Time time) {
14+
VType.argumentNotNull("data", data);
15+
VType.argumentNotNull("sizes", sizes);
16+
VType.argumentNotNull("alarm", alarm);
17+
VType.argumentNotNull("time", time);
18+
this.data = data;
19+
this.alarm = alarm;
20+
this.time = time;
21+
this.sizes = sizes;
22+
}
23+
24+
@Override
25+
public ListInteger getSizes() {
26+
return sizes;
27+
}
28+
29+
@Override
30+
public ListBoolean getData() {
31+
return data;
32+
}
33+
34+
@Override
35+
public Alarm getAlarm() {
36+
return alarm;
37+
}
38+
39+
@Override
40+
public Time getTime() {
41+
return time;
42+
}
43+
44+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package org.epics.vtype;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.epics.util.array.ArrayInteger;
7+
import org.epics.util.array.ListInteger;
8+
9+
/**
10+
* Immutable {@code VEnum} implementation.
11+
*
12+
* @author carcassi, shroffk, kasemir
13+
*/
14+
public class IVEnumArray extends VEnumArray {
15+
16+
private final Alarm alarm;
17+
private final Time time;
18+
private final ListInteger indices;
19+
private final EnumDisplay enumDisplay;
20+
21+
private final List<String> labels;
22+
23+
IVEnumArray(ListInteger indices, EnumDisplay enumDisplay, Alarm alarm, Time time) {
24+
VType.argumentNotNull("enumDisplay", enumDisplay);
25+
this.enumDisplay = enumDisplay;
26+
27+
VType.argumentNotNull("alarm", alarm);
28+
VType.argumentNotNull("time", time);
29+
30+
labels = new ArrayList<>(indices.size());
31+
32+
for (int i = 0; i < indices.size(); i++) {
33+
int index = indices.getInt(i);
34+
if (index < 0 || index >= enumDisplay.getChoices().size()) {
35+
throw new IndexOutOfBoundsException("VEnumArray element " + i + " has index " + index
36+
+ " outside of permitted options " + enumDisplay.getChoices());
37+
}
38+
labels.add(enumDisplay.getChoices().get(index));
39+
}
40+
this.indices = indices;
41+
this.alarm = alarm;
42+
this.time = time;
43+
}
44+
45+
@Override
46+
public EnumDisplay getDisplay() {
47+
return enumDisplay;
48+
}
49+
50+
@Override
51+
public Alarm getAlarm() {
52+
return alarm;
53+
}
54+
55+
@Override
56+
public Time getTime() {
57+
return time;
58+
}
59+
60+
@Override
61+
public List<String> getData() {
62+
return labels;
63+
}
64+
65+
@Override
66+
public ListInteger getIndexes() {
67+
return indices;
68+
}
69+
70+
71+
@Override
72+
public ListInteger getSizes() {
73+
return ArrayInteger.of(labels.size());
74+
}
75+
76+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.epics.vtype;
2+
3+
import org.epics.util.array.ArrayInteger;
4+
import org.epics.util.array.ListBoolean;
5+
6+
/**
7+
* Boolean array with alarm, timestamp, display and control information.
8+
*
9+
* @author carcassi
10+
*/
11+
public abstract class VBooleanArray extends Array implements AlarmProvider, TimeProvider {
12+
13+
/**
14+
* {@inheritDoc }
15+
* @return the data
16+
*/
17+
@Override
18+
public abstract ListBoolean getData();
19+
20+
21+
/**
22+
* Creates a new VBooleanArray.
23+
*
24+
* @param data the value
25+
* @param alarm the alarm
26+
* @param time the time
27+
* @param display the display
28+
* @return the new value
29+
*/
30+
public static VBooleanArray of(final ListBoolean data, final Alarm alarm, final Time time) {
31+
return new IVBooleanArray(data, ArrayInteger.of(data.size()), alarm, time);
32+
}
33+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.epics.vtype;
2+
3+
import java.util.List;
4+
5+
import org.epics.util.array.ListInteger;
6+
7+
public abstract class VEnumArray extends Array implements AlarmProvider, TimeProvider {
8+
9+
/**
10+
*
11+
*/
12+
@Override
13+
public abstract List<String> getData();
14+
15+
/**
16+
* Returns the indexes instead of the labels.
17+
*
18+
* @return an array of indexes
19+
*/
20+
public abstract ListInteger getIndexes();
21+
22+
/** @return the enum display information, i.e. choices */
23+
public abstract EnumDisplay getDisplay();
24+
25+
/**
26+
* Return an instance of the VEnumArray
27+
* @param data
28+
* @param enumDisplay
29+
* @param alarm
30+
* @param time
31+
* @return
32+
*/
33+
public static VEnumArray of(ListInteger data, EnumDisplay enumDisplay, Alarm alarm, Time time) {
34+
return new IVEnumArray(data, enumDisplay, alarm, time);
35+
}
36+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public abstract class VType {
4242
VUByteArray.class,
4343
VByteArray.class,
4444
VStringArray.class,
45+
VBooleanArray.class,
46+
VEnumArray.class,
4547
VImage.class,
4648
VTable.class);
4749

0 commit comments

Comments
 (0)