@@ -94,6 +94,8 @@ native String nativeFindString(long handle, long cursorHandle, int propertyId, b
9494
9595 native double nativeAvg (long handle , long cursorHandle , int propertyId );
9696
97+ native long nativeAvgLong (long handle , long cursorHandle , int propertyId );
98+
9799 native long nativeCount (long handle , long cursorHandle , int propertyId , boolean distinct );
98100
99101 /** Clears all values (e.g. distinct and null value). */
@@ -179,7 +181,7 @@ public PropertyQuery nullValue(Object nullValue) {
179181 * <p>
180182 * Note: results are not guaranteed to be in any particular order.
181183 * <p>
182- * See also: {@link #distinct}, {@link #distinct(QueryBuilder.StringOrder)}
184+ * See also: {@link #distinct() }, {@link #distinct(QueryBuilder.StringOrder)}
183185 *
184186 * @return Found strings
185187 */
@@ -202,7 +204,7 @@ public String[] call() {
202204 * <p>
203205 * Note: results are not guaranteed to be in any particular order.
204206 * <p>
205- * See also: {@link #distinct}
207+ * See also: {@link #distinct() }
206208 *
207209 * @return Found longs
208210 */
@@ -223,7 +225,7 @@ public long[] call() {
223225 * <p>
224226 * Note: results are not guaranteed to be in any particular order.
225227 * <p>
226- * See also: {@link #distinct}
228+ * See also: {@link #distinct() }
227229 */
228230 public int [] findInts () {
229231 return (int []) query .callInReadTx (new Callable <int []>() {
@@ -242,7 +244,7 @@ public int[] call() {
242244 * <p>
243245 * Note: results are not guaranteed to be in any particular order.
244246 * <p>
245- * See also: {@link #distinct}
247+ * See also: {@link #distinct() }
246248 */
247249 public short [] findShorts () {
248250 return (short []) query .callInReadTx (new Callable <short []>() {
@@ -261,7 +263,7 @@ public short[] call() {
261263 * <p>
262264 * Note: results are not guaranteed to be in any particular order.
263265 * <p>
264- * See also: {@link #distinct}
266+ * See also: {@link #distinct() }
265267 */
266268 public char [] findChars () {
267269 return (char []) query .callInReadTx (new Callable <char []>() {
@@ -297,7 +299,7 @@ public byte[] call() {
297299 * <p>
298300 * Note: results are not guaranteed to be in any particular order.
299301 * <p>
300- * See also: {@link #distinct}
302+ * See also: {@link #distinct() }
301303 */
302304 public float [] findFloats () {
303305 return (float []) query .callInReadTx (new Callable <float []>() {
@@ -316,7 +318,7 @@ public float[] call() {
316318 * <p>
317319 * Note: results are not guaranteed to be in any particular order.
318320 * <p>
319- * See also: {@link #distinct}
321+ * See also: {@link #distinct() }
320322 */
321323 public double [] findDoubles () {
322324 return (double []) query .callInReadTx (new Callable <double []>() {
@@ -381,8 +383,17 @@ public Double findDouble() {
381383 return (Double ) findNumber ();
382384 }
383385
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+ */
386397 public long sum () {
387398 return (Long ) query .callInReadTx (new Callable <Long >() {
388399 @ Override
@@ -392,7 +403,13 @@ public Long call() {
392403 });
393404 }
394405
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+ */
396413 public double sumDouble () {
397414 return (Double ) query .callInReadTx (new Callable <Double >() {
398415 @ Override
@@ -402,7 +419,11 @@ public Double call() {
402419 });
403420 }
404421
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+ */
406427 public long max () {
407428 return (Long ) query .callInReadTx (new Callable <Long >() {
408429 @ Override
@@ -412,7 +433,11 @@ public Long call() {
412433 });
413434 }
414435
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+ */
416441 public double maxDouble () {
417442 return (Double ) query .callInReadTx (new Callable <Double >() {
418443 @ Override
@@ -422,7 +447,11 @@ public Double call() {
422447 });
423448 }
424449
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+ */
426455 public long min () {
427456 return (Long ) query .callInReadTx (new Callable <Long >() {
428457 @ Override
@@ -432,7 +461,11 @@ public Long call() {
432461 });
433462 }
434463
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+ */
436469 public double minDouble () {
437470 return (Double ) query .callInReadTx (new Callable <Double >() {
438471 @ Override
@@ -442,7 +475,13 @@ public Double call() {
442475 });
443476 }
444477
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+ */
446485 public double avg () {
447486 return (Double ) query .callInReadTx (new Callable <Double >() {
448487 @ Override
@@ -452,6 +491,27 @@ public Double call() {
452491 });
453492 }
454493
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+ */
455515 public long count () {
456516 return (Long ) query .callInReadTx (new Callable <Long >() {
457517 @ Override
0 commit comments