Skip to content

Commit cda79af

Browse files
committed
Update VEnumArray to allow indices with no label string and short[]
1 parent 9ef88ea commit cda79af

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@
55

66
import org.epics.util.array.ArrayInteger;
77
import org.epics.util.array.ListInteger;
8+
import org.epics.util.array.ListNumber;
89

910
/**
10-
* Immutable {@code VEnum} implementation.
11+
* Immutable {@code VEnumArray} implementation.
1112
*
1213
* @author carcassi, shroffk, kasemir
1314
*/
1415
public class IVEnumArray extends VEnumArray {
1516

1617
private final Alarm alarm;
1718
private final Time time;
18-
private final ListInteger indices;
19+
private final ListNumber indices;
1920
private final EnumDisplay enumDisplay;
2021

2122
private final List<String> labels;
2223

23-
IVEnumArray(ListInteger indices, EnumDisplay enumDisplay, Alarm alarm, Time time) {
24+
IVEnumArray(ListNumber indices, EnumDisplay enumDisplay, Alarm alarm, Time time) {
2425
VType.argumentNotNull("enumDisplay", enumDisplay);
2526
this.enumDisplay = enumDisplay;
2627

@@ -32,8 +33,8 @@ public class IVEnumArray extends VEnumArray {
3233
for (int i = 0; i < indices.size(); i++) {
3334
int index = indices.getInt(i);
3435
if (index < 0 || index >= enumDisplay.getChoices().size()) {
35-
throw new IndexOutOfBoundsException("VEnumArray element " + i + " has index " + index
36-
+ " outside of permitted options " + enumDisplay.getChoices());
36+
labels.add("VEnumArray element " + i + " has index " + index + " outside of permitted options "
37+
+ enumDisplay.getChoices());
3738
}
3839
labels.add(enumDisplay.getChoices().get(index));
3940
}
@@ -63,7 +64,7 @@ public List<String> getData() {
6364
}
6465

6566
@Override
66-
public ListInteger getIndexes() {
67+
public ListNumber getIndexes() {
6768
return indices;
6869
}
6970

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
import java.util.List;
44

55
import org.epics.util.array.ListInteger;
6+
import org.epics.util.array.ListNumber;
7+
import org.epics.util.array.ListShort;
68

9+
/**
10+
* Scalar enum array with alarm, timestamp, and display information.
11+
*/
712
public abstract class VEnumArray extends Array implements AlarmProvider, TimeProvider {
813

914
/**
10-
*
15+
* Return the enum label values
1116
*/
1217
@Override
1318
public abstract List<String> getData();
@@ -17,7 +22,7 @@ public abstract class VEnumArray extends Array implements AlarmProvider, TimePro
1722
*
1823
* @return an array of indexes
1924
*/
20-
public abstract ListInteger getIndexes();
25+
public abstract ListNumber getIndexes();
2126

2227
/** @return the enum display information, i.e. choices */
2328
public abstract EnumDisplay getDisplay();
@@ -33,4 +38,16 @@ public abstract class VEnumArray extends Array implements AlarmProvider, TimePro
3338
public static VEnumArray of(ListInteger data, EnumDisplay enumDisplay, Alarm alarm, Time time) {
3439
return new IVEnumArray(data, enumDisplay, alarm, time);
3540
}
41+
42+
/**
43+
* Return an instance of the VEnumArray
44+
* @param data the indices
45+
* @param enumDisplay the enum display labels
46+
* @param alarm the alarm
47+
* @param time new time
48+
* @return {@link VEnumArray} instance of VEnumArray
49+
*/
50+
public static VEnumArray of(ListShort data, EnumDisplay enumDisplay, Alarm alarm, Time time) {
51+
return new IVEnumArray(data, enumDisplay, alarm, time);
52+
}
3653
}

0 commit comments

Comments
 (0)