Skip to content

Commit d300104

Browse files
committed
PropertyQuery: improve docs, e.g. clarify special return values
1 parent fbe165c commit d300104

File tree

1 file changed

+51
-17
lines changed

1 file changed

+51
-17
lines changed

objectbox-java/src/main/java/io/objectbox/query/PropertyQuery.java

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public PropertyQuery nullValue(Object nullValue) {
181181
* <p>
182182
* Note: results are not guaranteed to be in any particular order.
183183
* <p>
184-
* See also: {@link #distinct}, {@link #distinct(QueryBuilder.StringOrder)}
184+
* See also: {@link #distinct()}, {@link #distinct(QueryBuilder.StringOrder)}
185185
*
186186
* @return Found strings
187187
*/
@@ -204,7 +204,7 @@ public String[] call() {
204204
* <p>
205205
* Note: results are not guaranteed to be in any particular order.
206206
* <p>
207-
* See also: {@link #distinct}
207+
* See also: {@link #distinct()}
208208
*
209209
* @return Found longs
210210
*/
@@ -225,7 +225,7 @@ public long[] call() {
225225
* <p>
226226
* Note: results are not guaranteed to be in any particular order.
227227
* <p>
228-
* See also: {@link #distinct}
228+
* See also: {@link #distinct()}
229229
*/
230230
public int[] findInts() {
231231
return (int[]) query.callInReadTx(new Callable<int[]>() {
@@ -244,7 +244,7 @@ public int[] call() {
244244
* <p>
245245
* Note: results are not guaranteed to be in any particular order.
246246
* <p>
247-
* See also: {@link #distinct}
247+
* See also: {@link #distinct()}
248248
*/
249249
public short[] findShorts() {
250250
return (short[]) query.callInReadTx(new Callable<short[]>() {
@@ -263,7 +263,7 @@ public short[] call() {
263263
* <p>
264264
* Note: results are not guaranteed to be in any particular order.
265265
* <p>
266-
* See also: {@link #distinct}
266+
* See also: {@link #distinct()}
267267
*/
268268
public char[] findChars() {
269269
return (char[]) query.callInReadTx(new Callable<char[]>() {
@@ -299,7 +299,7 @@ public byte[] call() {
299299
* <p>
300300
* Note: results are not guaranteed to be in any particular order.
301301
* <p>
302-
* See also: {@link #distinct}
302+
* See also: {@link #distinct()}
303303
*/
304304
public float[] findFloats() {
305305
return (float[]) query.callInReadTx(new Callable<float[]>() {
@@ -318,7 +318,7 @@ public float[] call() {
318318
* <p>
319319
* Note: results are not guaranteed to be in any particular order.
320320
* <p>
321-
* See also: {@link #distinct}
321+
* See also: {@link #distinct()}
322322
*/
323323
public double[] findDoubles() {
324324
return (double[]) query.callInReadTx(new Callable<double[]>() {
@@ -383,13 +383,16 @@ public Double findDouble() {
383383
return (Double) findNumber();
384384
}
385385

386-
387386
/**
388387
* Sums up all values for the given property over all Objects matching the query.
389-
* <p>
390-
* Note: throws {@link io.objectbox.exception.NumericOverflowException NumericOverflowException} if
391-
* the sum exceeds the numbers {@link Long} can represent. This is different from Java arithmetic
392-
* where it would "wrap around" (e.g. max. value + 1 = min. value).
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).
393396
*/
394397
public long sum() {
395398
return (Long) query.callInReadTx(new Callable<Long>() {
@@ -400,7 +403,13 @@ public Long call() {
400403
});
401404
}
402405

403-
/** 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+
*/
404413
public double sumDouble() {
405414
return (Double) query.callInReadTx(new Callable<Double>() {
406415
@Override
@@ -410,7 +419,11 @@ public Double call() {
410419
});
411420
}
412421

413-
/** 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+
*/
414427
public long max() {
415428
return (Long) query.callInReadTx(new Callable<Long>() {
416429
@Override
@@ -420,7 +433,11 @@ public Long call() {
420433
});
421434
}
422435

423-
/** 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+
*/
424441
public double maxDouble() {
425442
return (Double) query.callInReadTx(new Callable<Double>() {
426443
@Override
@@ -430,7 +447,11 @@ public Double call() {
430447
});
431448
}
432449

433-
/** 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+
*/
434455
public long min() {
435456
return (Long) query.callInReadTx(new Callable<Long>() {
436457
@Override
@@ -440,7 +461,11 @@ public Long call() {
440461
});
441462
}
442463

443-
/** 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+
*/
444469
public double minDouble() {
445470
return (Double) query.callInReadTx(new Callable<Double>() {
446471
@Override
@@ -454,6 +479,8 @@ public Double call() {
454479
* Calculates the average of all values for the given number property over all Objects matching the query.
455480
* <p>
456481
* For integer properties you can also use {@link #avgLong()}.
482+
*
483+
* @return NaN in case no elements matched the query
457484
*/
458485
public double avg() {
459486
return (Double) query.callInReadTx(new Callable<Double>() {
@@ -468,6 +495,8 @@ public Double call() {
468495
* Calculates the average of all values for the given integer property over all Objects matching the query.
469496
* <p>
470497
* For floating-point properties use {@link #avg()}.
498+
*
499+
* @return 0 in case no elements matched the query
471500
*/
472501
public long avgLong() {
473502
return (Long) query.callInReadTx(new Callable<Long>() {
@@ -478,6 +507,11 @@ public Long call() {
478507
});
479508
}
480509

510+
/**
511+
* The count of non-null values.
512+
* <p>
513+
* See also: {@link #distinct()}
514+
*/
481515
public long count() {
482516
return (Long) query.callInReadTx(new Callable<Long>() {
483517
@Override

0 commit comments

Comments
 (0)