1
2
3
4
5 package org.epics.pvmanager.jca;
6
7 import gov.aps.jca.dbr.DBR_LABELS_Enum;
8 import gov.aps.jca.dbr.DBR_TIME_Enum;
9 import java.util.Arrays;
10 import java.util.List;
11 import org.epics.vtype.VEnum;
12 import org.epics.vtype.VTypeToString;
13
14
15
16
17
18 class VEnumFromDbr extends VMetadata<DBR_TIME_Enum> implements VEnum {
19
20 private final DBR_LABELS_Enum metadata;
21
22 public VEnumFromDbr(DBR_TIME_Enum dbrValue, DBR_LABELS_Enum metadata, JCAConnectionPayload connPayload) {
23 super(dbrValue, connPayload);
24 this.metadata = metadata;
25 }
26
27 @Override
28 public String getValue() {
29
30
31 if (metadata.getLabels() == null) {
32 return Integer.toString(getIndex());
33 }
34
35
36
37 if (getIndex() >= metadata.getLabels().length || getIndex() < 0) {
38 return Integer.toString(getIndex());
39 }
40
41 return getLabels().get(getIndex());
42 }
43
44 @Override
45 public int getIndex() {
46 return dbrValue.getEnumValue()[0];
47 }
48
49 @Override
50 public List<String> getLabels() {
51 if (metadata.getLabels() == null)
52 throw new RuntimeException("Metadata returned no labels");
53 return Arrays.asList(metadata.getLabels());
54 }
55
56 @Override
57 public String toString() {
58 return VTypeToString.toString(this);
59 }
60
61 }