1 package org.opentrafficsim.sim0mq.publisher;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.djunits.value.vdouble.scalar.Time;
7 import org.djutils.event.EventType;
8 import org.djutils.metadata.MetaData;
9 import org.djutils.metadata.ObjectDescriptor;
10
11
12
13
14
15
16
17
18
19
20
21 public abstract class AbstractEventTransceiver extends AbstractTransceiver
22 {
23
24
25
26
27
28
29 public AbstractEventTransceiver(final String id, final MetaData addressFields, final EventType eventType)
30 {
31 super(id, addressFields, constructResultFields(eventType));
32 }
33
34
35
36
37
38
39
40
41 public static MetaData constructResultFields(final EventType eventType) throws ClassCastException
42 {
43 List<ObjectDescriptor> resultList = new ArrayList<>();
44 resultList.add(new ObjectDescriptor("TimeStamp", "Time", Time.class));
45 for (int index = 0; index < eventType.getMetaData().size(); index++)
46 {
47 ObjectDescriptor od = eventType.getMetaData().getObjectDescriptor(index);
48 switch (od.getObjectClass().getName())
49 {
50 case "java.lang.String":
51 case "java.lang.Double":
52 case "org.djunits.value.vdouble.scalar.Acceleration":
53 case "org.djunits.value.vdouble.scalar.Direction":
54 case "org.djunits.value.vdouble.scalar.Length":
55 case "org.djunits.value.vdouble.scalar.Speed":
56 case "org.djunits.value.vdouble.scalar.Time":
57 case "org.djunits.value.vdouble.vector.PositionVector":
58 resultList.add(od);
59 break;
60
61 default:
62 throw new ClassCastException("No conversion for class " + od.getObjectClass().getName());
63 }
64 }
65
66 return new MetaData(eventType.getMetaData().getName(), eventType.getMetaData().getDescription(),
67 resultList.toArray(new ObjectDescriptor[0]));
68 }
69
70 }