@@ -94,6 +94,8 @@ native String nativeFindString(long handle, long cursorHandle, int propertyId, b
94
94
95
95
native double nativeAvg (long handle , long cursorHandle , int propertyId );
96
96
97
+ native long nativeAvgLong (long handle , long cursorHandle , int propertyId );
98
+
97
99
native long nativeCount (long handle , long cursorHandle , int propertyId , boolean distinct );
98
100
99
101
/** Clears all values (e.g. distinct and null value). */
@@ -179,7 +181,7 @@ public PropertyQuery nullValue(Object nullValue) {
179
181
* <p>
180
182
* Note: results are not guaranteed to be in any particular order.
181
183
* <p>
182
- * See also: {@link #distinct}, {@link #distinct(QueryBuilder.StringOrder)}
184
+ * See also: {@link #distinct() }, {@link #distinct(QueryBuilder.StringOrder)}
183
185
*
184
186
* @return Found strings
185
187
*/
@@ -202,7 +204,7 @@ public String[] call() {
202
204
* <p>
203
205
* Note: results are not guaranteed to be in any particular order.
204
206
* <p>
205
- * See also: {@link #distinct}
207
+ * See also: {@link #distinct() }
206
208
*
207
209
* @return Found longs
208
210
*/
@@ -223,7 +225,7 @@ public long[] call() {
223
225
* <p>
224
226
* Note: results are not guaranteed to be in any particular order.
225
227
* <p>
226
- * See also: {@link #distinct}
228
+ * See also: {@link #distinct() }
227
229
*/
228
230
public int [] findInts () {
229
231
return (int []) query .callInReadTx (new Callable <int []>() {
@@ -242,7 +244,7 @@ public int[] call() {
242
244
* <p>
243
245
* Note: results are not guaranteed to be in any particular order.
244
246
* <p>
245
- * See also: {@link #distinct}
247
+ * See also: {@link #distinct() }
246
248
*/
247
249
public short [] findShorts () {
248
250
return (short []) query .callInReadTx (new Callable <short []>() {
@@ -261,7 +263,7 @@ public short[] call() {
261
263
* <p>
262
264
* Note: results are not guaranteed to be in any particular order.
263
265
* <p>
264
- * See also: {@link #distinct}
266
+ * See also: {@link #distinct() }
265
267
*/
266
268
public char [] findChars () {
267
269
return (char []) query .callInReadTx (new Callable <char []>() {
@@ -297,7 +299,7 @@ public byte[] call() {
297
299
* <p>
298
300
* Note: results are not guaranteed to be in any particular order.
299
301
* <p>
300
- * See also: {@link #distinct}
302
+ * See also: {@link #distinct() }
301
303
*/
302
304
public float [] findFloats () {
303
305
return (float []) query .callInReadTx (new Callable <float []>() {
@@ -316,7 +318,7 @@ public float[] call() {
316
318
* <p>
317
319
* Note: results are not guaranteed to be in any particular order.
318
320
* <p>
319
- * See also: {@link #distinct}
321
+ * See also: {@link #distinct() }
320
322
*/
321
323
public double [] findDoubles () {
322
324
return (double []) query .callInReadTx (new Callable <double []>() {
@@ -381,8 +383,17 @@ public Double findDouble() {
381
383
return (Double ) findNumber ();
382
384
}
383
385
384
-
385
- /** Sums up all values for the given property over all Objects matching the query. */
386
+ /**
387
+ * Sums up all values for the given property over all Objects matching the query.
388
+ *
389
+ * Note: this method is not recommended for properties of type long unless you know the contents of the DB not to
390
+ * overflow. Use {@link #sumDouble()} instead if you cannot guarantee the sum to be in the long value range.
391
+ *
392
+ * @return 0 in case no elements matched the query
393
+ * @throws io.objectbox.exception.NumericOverflowException if the sum exceeds the numbers {@link Long} can
394
+ * represent.
395
+ * This is different from Java arithmetic where it would "wrap around" (e.g. max. value + 1 = min. value).
396
+ */
386
397
public long sum () {
387
398
return (Long ) query .callInReadTx (new Callable <Long >() {
388
399
@ Override
@@ -392,7 +403,13 @@ public Long call() {
392
403
});
393
404
}
394
405
395
- /** Sums up all values for the given property over all Objects matching the query. */
406
+ /**
407
+ * Sums up all values for the given property over all Objects matching the query.
408
+ *
409
+ * Note: for integer types int and smaller, {@link #sum()} is usually preferred for sums.
410
+ *
411
+ * @return 0 in case no elements matched the query
412
+ */
396
413
public double sumDouble () {
397
414
return (Double ) query .callInReadTx (new Callable <Double >() {
398
415
@ Override
@@ -402,7 +419,11 @@ public Double call() {
402
419
});
403
420
}
404
421
405
- /** Finds the maximum value for the given property over all Objects matching the query. */
422
+ /**
423
+ * Finds the maximum value for the given property over all Objects matching the query.
424
+ *
425
+ * @return Long.MIN_VALUE in case no elements matched the query
426
+ */
406
427
public long max () {
407
428
return (Long ) query .callInReadTx (new Callable <Long >() {
408
429
@ Override
@@ -412,7 +433,11 @@ public Long call() {
412
433
});
413
434
}
414
435
415
- /** Finds the maximum value for the given property over all Objects matching the query. */
436
+ /**
437
+ * Finds the maximum value for the given property over all Objects matching the query.
438
+ *
439
+ * @return NaN in case no elements matched the query
440
+ */
416
441
public double maxDouble () {
417
442
return (Double ) query .callInReadTx (new Callable <Double >() {
418
443
@ Override
@@ -422,7 +447,11 @@ public Double call() {
422
447
});
423
448
}
424
449
425
- /** Finds the minimum value for the given property over all Objects matching the query. */
450
+ /**
451
+ * Finds the minimum value for the given property over all Objects matching the query.
452
+ *
453
+ * @return Long.MAX_VALUE in case no elements matched the query
454
+ */
426
455
public long min () {
427
456
return (Long ) query .callInReadTx (new Callable <Long >() {
428
457
@ Override
@@ -432,7 +461,11 @@ public Long call() {
432
461
});
433
462
}
434
463
435
- /** Finds the minimum value for the given property over all Objects matching the query. */
464
+ /**
465
+ * Finds the minimum value for the given property over all objects matching the query.
466
+ *
467
+ * @return NaN in case no elements matched the query
468
+ */
436
469
public double minDouble () {
437
470
return (Double ) query .callInReadTx (new Callable <Double >() {
438
471
@ Override
@@ -442,7 +475,13 @@ public Double call() {
442
475
});
443
476
}
444
477
445
- /** Calculates the average of all values for the given property over all Objects matching the query. */
478
+ /**
479
+ * Calculates the average of all values for the given number property over all Objects matching the query.
480
+ * <p>
481
+ * For integer properties you can also use {@link #avgLong()}.
482
+ *
483
+ * @return NaN in case no elements matched the query
484
+ */
446
485
public double avg () {
447
486
return (Double ) query .callInReadTx (new Callable <Double >() {
448
487
@ Override
@@ -452,6 +491,27 @@ public Double call() {
452
491
});
453
492
}
454
493
494
+ /**
495
+ * Calculates the average of all values for the given integer property over all Objects matching the query.
496
+ * <p>
497
+ * For floating-point properties use {@link #avg()}.
498
+ *
499
+ * @return 0 in case no elements matched the query
500
+ */
501
+ public long avgLong () {
502
+ return (Long ) query .callInReadTx (new Callable <Long >() {
503
+ @ Override
504
+ public Long call () {
505
+ return nativeAvgLong (queryHandle , query .cursorHandle (), propertyId );
506
+ }
507
+ });
508
+ }
509
+
510
+ /**
511
+ * The count of non-null values.
512
+ * <p>
513
+ * See also: {@link #distinct()}
514
+ */
455
515
public long count () {
456
516
return (Long ) query .callInReadTx (new Callable <Long >() {
457
517
@ Override
0 commit comments