27
27
import java .time .temporal .ChronoField ;
28
28
import java .util .LinkedList ;
29
29
import java .util .List ;
30
- import java .util .Map .Entry ;
31
30
import java .util .Objects ;
31
+ import java .util .Map .Entry ;
32
32
import java .util .concurrent .ConcurrentHashMap ;
33
33
import java .util .concurrent .ConcurrentMap ;
34
34
import java .util .concurrent .TimeUnit ;
@@ -84,33 +84,9 @@ public class InfluxDBResultMapper {
84
84
* possible to define the values of your POJO (e.g. due to an unsupported field type).
85
85
*/
86
86
public <T > List <T > toPOJO (final QueryResult queryResult , final Class <T > clazz ) throws InfluxDBMapperException {
87
- return toPOJO (queryResult , clazz , TimeUnit .MILLISECONDS );
88
- }
89
-
90
- /**
91
- * <p>
92
- * Process a {@link QueryResult} object returned by the InfluxDB client inspecting the internal
93
- * data structure and creating the respective object instances based on the Class passed as
94
- * parameter.
95
- * </p>
96
- *
97
- * @param queryResult the InfluxDB result object
98
- * @param clazz the Class that will be used to hold your measurement data
99
- * @param precision the time precision of results
100
- * @param <T> the target type
101
- *
102
- * @return a {@link List} of objects from the same Class passed as parameter and sorted on the
103
- * same order as received from InfluxDB.
104
- *
105
- * @throws InfluxDBMapperException If {@link QueryResult} parameter contain errors,
106
- * <tt>clazz</tt> parameter is not annotated with @Measurement or it was not
107
- * possible to define the values of your POJO (e.g. due to an unsupported field type).
108
- */
109
- public <T > List <T > toPOJO (final QueryResult queryResult , final Class <T > clazz ,
110
- final TimeUnit precision ) throws InfluxDBMapperException {
111
87
throwExceptionIfMissingAnnotation (clazz );
112
88
String measurementName = getMeasurementName (clazz );
113
- return this .toPOJO (queryResult , clazz , measurementName , precision );
89
+ return this .toPOJO (queryResult , clazz , measurementName );
114
90
}
115
91
116
92
/**
@@ -134,32 +110,6 @@ public <T> List<T> toPOJO(final QueryResult queryResult, final Class<T> clazz,
134
110
*/
135
111
public <T > List <T > toPOJO (final QueryResult queryResult , final Class <T > clazz , final String measurementName )
136
112
throws InfluxDBMapperException {
137
- return toPOJO (queryResult , clazz , measurementName , TimeUnit .MILLISECONDS );
138
- }
139
-
140
- /**
141
- * <p>
142
- * Process a {@link QueryResult} object returned by the InfluxDB client inspecting the internal
143
- * data structure and creating the respective object instances based on the Class passed as
144
- * parameter.
145
- * </p>
146
- *
147
- * @param queryResult the InfluxDB result object
148
- * @param clazz the Class that will be used to hold your measurement data
149
- * @param <T> the target type
150
- * @param measurementName name of the Measurement
151
- * @param precision the time precision of results
152
- *
153
- * @return a {@link List} of objects from the same Class passed as parameter and sorted on the
154
- * same order as received from InfluxDB.
155
- *
156
- * @throws InfluxDBMapperException If {@link QueryResult} parameter contain errors,
157
- * <tt>clazz</tt> parameter is not annotated with @Measurement or it was not
158
- * possible to define the values of your POJO (e.g. due to an unsupported field type).
159
- */
160
- public <T > List <T > toPOJO (final QueryResult queryResult , final Class <T > clazz , final String measurementName ,
161
- final TimeUnit precision )
162
- throws InfluxDBMapperException {
163
113
164
114
Objects .requireNonNull (measurementName , "measurementName" );
165
115
Objects .requireNonNull (queryResult , "queryResult" );
@@ -176,7 +126,7 @@ public <T> List<T> toPOJO(final QueryResult queryResult, final Class<T> clazz, f
176
126
internalResult .getSeries ().stream ()
177
127
.filter (series -> series .getName ().equals (measurementName ))
178
128
.forEachOrdered (series -> {
179
- parseSeriesAs (series , clazz , result , precision );
129
+ parseSeriesAs (series , clazz , result );
180
130
});
181
131
});
182
132
@@ -227,11 +177,6 @@ String getMeasurementName(final Class<?> clazz) {
227
177
}
228
178
229
179
<T > List <T > parseSeriesAs (final QueryResult .Series series , final Class <T > clazz , final List <T > result ) {
230
- return parseSeriesAs (series , clazz , result , TimeUnit .MILLISECONDS );
231
- }
232
-
233
- <T > List <T > parseSeriesAs (final QueryResult .Series series , final Class <T > clazz , final List <T > result ,
234
- final TimeUnit precision ) {
235
180
int columnSize = series .getColumns ().size ();
236
181
ConcurrentMap <String , Field > colNameAndFieldMap = CLASS_FIELD_CACHE .get (clazz .getName ());
237
182
try {
@@ -243,7 +188,7 @@ <T> List<T> parseSeriesAs(final QueryResult.Series series, final Class<T> clazz,
243
188
if (object == null ) {
244
189
object = clazz .newInstance ();
245
190
}
246
- setFieldValue (object , correspondingField , row .get (i ), precision );
191
+ setFieldValue (object , correspondingField , row .get (i ));
247
192
}
248
193
}
249
194
// When the "GROUP BY" clause is used, "tags" are returned as Map<String,String> and
@@ -255,7 +200,7 @@ <T> List<T> parseSeriesAs(final QueryResult.Series series, final Class<T> clazz,
255
200
Field correspondingField = colNameAndFieldMap .get (entry .getKey ()/*InfluxDB columnName*/ );
256
201
if (correspondingField != null ) {
257
202
// I don't think it is possible to reach here without a valid "object"
258
- setFieldValue (object , correspondingField , entry .getValue (), precision );
203
+ setFieldValue (object , correspondingField , entry .getValue ());
259
204
}
260
205
}
261
206
}
@@ -278,11 +223,10 @@ <T> List<T> parseSeriesAs(final QueryResult.Series series, final Class<T> clazz,
278
223
* @param object
279
224
* @param field
280
225
* @param value
281
- * @param precision
282
226
* @throws IllegalArgumentException
283
227
* @throws IllegalAccessException
284
228
*/
285
- <T > void setFieldValue (final T object , final Field field , final Object value , final TimeUnit precision )
229
+ <T > void setFieldValue (final T object , final Field field , final Object value )
286
230
throws IllegalArgumentException , IllegalAccessException {
287
231
if (value == null ) {
288
232
return ;
@@ -292,7 +236,7 @@ <T> void setFieldValue(final T object, final Field field, final Object value, fi
292
236
if (!field .isAccessible ()) {
293
237
field .setAccessible (true );
294
238
}
295
- if (fieldValueModified (fieldType , field , object , value , precision )
239
+ if (fieldValueModified (fieldType , field , object , value )
296
240
|| fieldValueForPrimitivesModified (fieldType , field , object , value )
297
241
|| fieldValueForPrimitiveWrappersModified (fieldType , field , object , value )) {
298
242
return ;
@@ -308,8 +252,7 @@ <T> void setFieldValue(final T object, final Field field, final Object value, fi
308
252
}
309
253
}
310
254
311
- <T > boolean fieldValueModified (final Class <?> fieldType , final Field field , final T object , final Object value ,
312
- final TimeUnit precision )
255
+ <T > boolean fieldValueModified (final Class <?> fieldType , final Field field , final T object , final Object value )
313
256
throws IllegalArgumentException , IllegalAccessException {
314
257
if (String .class .isAssignableFrom (fieldType )) {
315
258
field .set (object , String .valueOf (value ));
@@ -320,11 +263,9 @@ <T> boolean fieldValueModified(final Class<?> fieldType, final Field field, fina
320
263
if (value instanceof String ) {
321
264
instant = Instant .from (ISO8601_FORMATTER .parse (String .valueOf (value )));
322
265
} else if (value instanceof Long ) {
323
- instant = Instant .ofEpochMilli (toMillis (( long ) value , precision ) );
266
+ instant = Instant .ofEpochMilli (( Long ) value );
324
267
} else if (value instanceof Double ) {
325
- instant = Instant .ofEpochMilli (toMillis (((Double ) value ).longValue (), precision ));
326
- } else if (value instanceof Integer ) {
327
- instant = Instant .ofEpochMilli (toMillis (((Integer ) value ).longValue (), precision ));
268
+ instant = Instant .ofEpochMilli (((Double ) value ).longValue ());
328
269
} else {
329
270
throw new InfluxDBMapperException ("Unsupported type " + field .getClass () + " for field " + field .getName ());
330
271
}
@@ -375,9 +316,4 @@ <T> boolean fieldValueForPrimitiveWrappersModified(final Class<?> fieldType, fin
375
316
}
376
317
return false ;
377
318
}
378
-
379
- private Long toMillis (final long value , final TimeUnit precision ) {
380
-
381
- return TimeUnit .MILLISECONDS .convert (value , precision );
382
- }
383
319
}
0 commit comments