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
40 public class LongConsumerMulticaster implements DoubleConsumer, NumberConsumer,
41 LongConsumer, StringConsumer, ObjectConsumer, PatternConsumer
42 {
43
44 public static final Class[] SUPPORTED_CONSUMER_TYPES = {
45 DoubleConsumer.class, LongConsumer.class, NumberConsumer.class,
46 ObjectConsumer.class, StringConsumer.class, PatternConsumer.class
47 };
48 LongConsumer delegate;
49
50
51
52
53
54
55
56
57
58
59
60 public static final LongConsumer createDataConsumer(Class type,
61 LongConsumer delegate)
62 {
63 if (type == LongConsumer.class) {
64 return delegate;
65 }
66
67 if (type == NumberConsumer.class || type == StringConsumer.class
68 || type == ObjectConsumer.class || type == DoubleConsumer.class || type==PatternConsumer.class) {
69 return new LongConsumerMulticaster(delegate);
70 }
71
72 return null;
73 }
74
75
76
77
78
79
80 public LongConsumerMulticaster(LongConsumer delegate)
81 {
82 this.delegate = delegate;
83 }
84
85
86
87
88 public LongConsumerMulticaster()
89 {
90 }
91
92
93
94
95
96
97 public LongConsumer getDelegate()
98 {
99 return delegate;
100 }
101
102
103
104
105
106
107 public void setDelegate(LongConsumer delegate)
108 {
109 this.delegate = delegate;
110 }
111
112
113
114
115 public void updateValue(long timestamp, double value)
116 throws CommonException
117 {
118 delegate.updateValue(timestamp, (long)value);
119 }
120
121
122
123
124 public void updateValue(long timestamp, Number value)
125 throws CommonException
126 {
127 delegate.updateValue(timestamp, value.longValue());
128 }
129
130
131
132
133 public void updateValue(long timestamp, long value)
134 throws CommonException
135 {
136 delegate.updateValue(timestamp, value);
137 }
138
139
140
141
142 public DataConsumer getDataConsumer(Class type)
143 {
144 return delegate.getDataConsumer(type);
145 }
146
147
148
149
150 public DataConsumer getDefaultDataConsumer()
151 {
152 return delegate.getDefaultDataConsumer();
153 }
154
155
156
157
158 public String getName()
159 {
160 return delegate.getName();
161 }
162
163
164
165
166 public void setCharacteristics(Map characteristics)
167 {
168 String f = (String)characteristics.get(CommonDisplayer.C_FORMAT);
169
170 if (f != null) {
171 HashMap map = new HashMap(characteristics);
172 map.put(CommonDisplayer.C_FORMAT, DisplayerUtilities.toLongFormat(f));
173 delegate.setCharacteristics(map);
174 } else {
175 delegate.setCharacteristics(characteristics);
176 }
177 }
178
179
180
181
182 public void updateDataState(DataState state)
183 {
184 delegate.updateDataState(state);
185 }
186
187
188
189
190 public void updateValue(long timestamp, String value)
191 throws CommonException
192 {
193 delegate.updateValue(timestamp, Long.parseLong(value));
194 }
195
196
197
198
199 public void updateValue(long timestamp, Object value)
200 throws CommonException
201 {
202 delegate.updateValue(timestamp, ((Number)value).longValue());
203 }
204
205
206
207
208 public void updateValue(long timestamp, BitSet value)
209 throws CommonException
210 {
211 delegate.updateValue(timestamp, BitSetUtilities.toLong(value));
212 }
213
214
215
216
217 public String[] getSupportedCharacteristics()
218 {
219 return delegate.getSupportedCharacteristics();
220 }
221
222
223
224
225 public Class[] getSupportedConsumerTypes()
226 {
227 return SUPPORTED_CONSUMER_TYPES;
228 }
229 }
230
231