1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.displayers;
21
22 import java.util.BitSet;
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import com.cosylab.util.BitSetUtilities;
27 import com.cosylab.util.CommonException;
28
29
30
31
32
33
34
35
36
37
38
39 public class PatternConsumerMulticaster implements PatternConsumer,
40 LongConsumer, StringConsumer, DoubleConsumer, NumberConsumer,
41 ObjectConsumer
42 {
43
44 public static final Class[] SUPPORTED_CONSUMER_TYPES = {
45 PatternConsumer.class, LongConsumer.class, StringConsumer.class,
46 DoubleConsumer.class, NumberConsumer.class, ObjectConsumer.class
47 };
48
49
50
51
52
53
54
55
56
57
58
59 public static final PatternConsumer createDataConsumer(Class type,
60 PatternConsumer delegate)
61 {
62 if (type == PatternConsumer.class) {
63 return delegate;
64 }
65
66 if (type == NumberConsumer.class || type == StringConsumer.class
67 || type == ObjectConsumer.class || type == DoubleConsumer.class
68 || type == LongConsumer.class) {
69 return new PatternConsumerMulticaster(delegate);
70 }
71
72 return null;
73 }
74
75 PatternConsumer delegate;
76
77
78
79
80 public PatternConsumerMulticaster()
81 {
82 super();
83 }
84
85
86
87
88
89
90 public PatternConsumerMulticaster(PatternConsumer delegate)
91 {
92 this.delegate = delegate;
93 }
94
95
96
97
98 public DataConsumer getDefaultDataConsumer()
99 {
100 return delegate.getDefaultDataConsumer();
101 }
102
103
104
105
106
107
108 public PatternConsumer getDelegate()
109 {
110 return delegate;
111 }
112
113
114
115
116 public String getName()
117 {
118 return delegate.getName();
119 }
120
121
122
123
124 public String[] getSupportedCharacteristics()
125 {
126 return delegate.getSupportedCharacteristics();
127 }
128
129
130
131
132 @SuppressWarnings("unchecked")
133 public Class[] getSupportedConsumerTypes()
134 {
135 return SUPPORTED_CONSUMER_TYPES;
136 }
137
138
139
140
141 public void setCharacteristics(Map characteristics)
142 {
143 String f = (String)characteristics.get(CommonDisplayer.C_FORMAT);
144
145 if (f != null) {
146 HashMap map = new HashMap(characteristics);
147 map.put(CommonDisplayer.C_FORMAT, DisplayerUtilities.toLongFormat(f));
148 delegate.setCharacteristics(map);
149 } else {
150 delegate.setCharacteristics(characteristics);
151 }
152 }
153
154
155
156
157
158
159 public void setDelegate(PatternConsumer delegate)
160 {
161 this.delegate = delegate;
162 }
163
164
165
166
167 public void updateDataState(DataState state)
168 {
169 delegate.updateDataState(state);
170 }
171
172
173
174
175 public void updateValue(long timestamp, BitSet value)
176 throws CommonException
177 {
178 delegate.updateValue(timestamp, value);
179 }
180
181
182
183
184 public void updateValue(long timestamp, double value)
185 throws CommonException
186 {
187 delegate.updateValue(timestamp, BitSetUtilities.forLong((long)value));
188 }
189
190
191
192
193 public void updateValue(long timestamp, long value)
194 throws CommonException
195 {
196 delegate.updateValue(timestamp, BitSetUtilities.forLong(value));
197 }
198
199
200
201
202 public void updateValue(long timestamp, Number value)
203 throws CommonException
204 {
205 delegate.updateValue(timestamp,
206 BitSetUtilities.forLong(value.longValue()));
207 }
208
209
210
211
212 public void updateValue(long timestamp, Object value)
213 throws CommonException
214 {
215 delegate.updateValue(timestamp,
216 BitSetUtilities.forLong(((Number)value).longValue()));
217 }
218
219
220
221
222 public void updateValue(long timestamp, String value)
223 throws CommonException
224 {
225 delegate.updateValue(timestamp,
226 BitSetUtilities.forLong(Long.parseLong(value)));
227 }
228
229
230
231
232
233 public <D extends DataConsumer> D getDataConsumer(Class<D> type) {
234 return delegate.getDataConsumer(type);
235 }
236 }
237
238