25
25
* (subject to change in a future version).
26
26
*/
27
27
@ SuppressWarnings ("WeakerAccess" ) // WeakerAccess: allow inner class access without accessor
28
- public class PropertyQuery {
29
- final Query query ;
28
+ public class PropertyQuery < T > {
29
+ final Query < T > query ;
30
30
final long queryHandle ;
31
- final Property property ;
31
+ final Property < T > property ;
32
32
final int propertyId ;
33
33
34
34
boolean distinct ;
@@ -41,7 +41,7 @@ public class PropertyQuery {
41
41
String nullValueString ;
42
42
long nullValueLong ;
43
43
44
- PropertyQuery (Query query , Property property ) {
44
+ PropertyQuery (Query < T > query , Property < T > property ) {
45
45
this .query = query ;
46
46
queryHandle = query .handle ;
47
47
this .property = property ;
@@ -97,7 +97,7 @@ native String nativeFindString(long handle, long cursorHandle, int propertyId, b
97
97
native long nativeCount (long handle , long cursorHandle , int propertyId , boolean distinct );
98
98
99
99
/** Clears all values (e.g. distinct and null value). */
100
- public PropertyQuery reset () {
100
+ public PropertyQuery < T > reset () {
101
101
distinct = false ;
102
102
noCaseIfDistinct = true ;
103
103
unique = false ;
@@ -115,7 +115,7 @@ public PropertyQuery reset() {
115
115
* Note: strings default to case-insensitive comparision;
116
116
* to change that call {@link #distinct(QueryBuilder.StringOrder)}.
117
117
*/
118
- public PropertyQuery distinct () {
118
+ public PropertyQuery < T > distinct () {
119
119
distinct = true ;
120
120
return this ;
121
121
}
@@ -124,7 +124,7 @@ public PropertyQuery distinct() {
124
124
* For string properties you can specify {@link io.objectbox.query.QueryBuilder.StringOrder#CASE_SENSITIVE} if you
125
125
* want to have case sensitive distinct values (e.g. returning "foo","Foo","FOO" instead of "foo").
126
126
*/
127
- public PropertyQuery distinct (QueryBuilder .StringOrder stringOrder ) {
127
+ public PropertyQuery < T > distinct (QueryBuilder .StringOrder stringOrder ) {
128
128
if (property .type != String .class ) {
129
129
throw new RuntimeException ("Reserved for string properties, but got " + property );
130
130
}
@@ -142,7 +142,7 @@ public PropertyQuery distinct(QueryBuilder.StringOrder stringOrder) {
142
142
* <p>
143
143
* Will be ignored for find methods returning multiple values, e.g. {@link #findInts()}.
144
144
*/
145
- public PropertyQuery unique () {
145
+ public PropertyQuery < T > unique () {
146
146
unique = true ;
147
147
return this ;
148
148
}
@@ -152,7 +152,7 @@ public PropertyQuery unique() {
152
152
* However, using this function, you can define an alternative value that will be returned for null values.
153
153
* E.g. -1 for ins/longs or "NULL" for strings.
154
154
*/
155
- public PropertyQuery nullValue (Object nullValue ) {
155
+ public PropertyQuery < T > nullValue (Object nullValue ) {
156
156
//noinspection ConstantConditions Annotation can not enforce non-null.
157
157
if (nullValue == null ) {
158
158
throw new IllegalArgumentException ("Null values are not allowed" );
@@ -185,7 +185,7 @@ public PropertyQuery nullValue(Object nullValue) {
185
185
* @return Found strings
186
186
*/
187
187
public String [] findStrings () {
188
- return ( String []) query .callInReadTx (() -> {
188
+ return query .callInReadTx (() -> {
189
189
boolean distinctNoCase = distinct && noCaseIfDistinct ;
190
190
long cursorHandle = query .cursorHandle ();
191
191
return nativeFindStrings (queryHandle , cursorHandle , propertyId , distinct , distinctNoCase ,
@@ -205,7 +205,7 @@ public String[] findStrings() {
205
205
* @return Found longs
206
206
*/
207
207
public long [] findLongs () {
208
- return ( long []) query .callInReadTx (() ->
208
+ return query .callInReadTx (() ->
209
209
nativeFindLongs (queryHandle , query .cursorHandle (), propertyId , distinct , enableNull , nullValueLong )
210
210
);
211
211
}
@@ -220,7 +220,7 @@ public long[] findLongs() {
220
220
* See also: {@link #distinct()}
221
221
*/
222
222
public int [] findInts () {
223
- return ( int []) query .callInReadTx (() ->
223
+ return query .callInReadTx (() ->
224
224
nativeFindInts (queryHandle , query .cursorHandle (), propertyId , distinct , enableNull , (int ) nullValueLong )
225
225
);
226
226
}
@@ -235,7 +235,7 @@ public int[] findInts() {
235
235
* See also: {@link #distinct()}
236
236
*/
237
237
public short [] findShorts () {
238
- return ( short []) query .callInReadTx (() ->
238
+ return query .callInReadTx (() ->
239
239
nativeFindShorts (queryHandle , query .cursorHandle (), propertyId , distinct , enableNull , (short ) nullValueLong )
240
240
);
241
241
}
@@ -250,7 +250,7 @@ public short[] findShorts() {
250
250
* See also: {@link #distinct()}
251
251
*/
252
252
public char [] findChars () {
253
- return ( char []) query .callInReadTx (() ->
253
+ return query .callInReadTx (() ->
254
254
nativeFindChars (queryHandle , query .cursorHandle (), propertyId , distinct , enableNull , (char ) nullValueLong )
255
255
);
256
256
}
@@ -263,7 +263,7 @@ public char[] findChars() {
263
263
* Note: results are not guaranteed to be in any particular order.
264
264
*/
265
265
public byte [] findBytes () {
266
- return ( byte []) query .callInReadTx (() ->
266
+ return query .callInReadTx (() ->
267
267
nativeFindBytes (queryHandle , query .cursorHandle (), propertyId , distinct , enableNull , (byte ) nullValueLong )
268
268
);
269
269
}
@@ -278,7 +278,7 @@ public byte[] findBytes() {
278
278
* See also: {@link #distinct()}
279
279
*/
280
280
public float [] findFloats () {
281
- return ( float []) query .callInReadTx (() ->
281
+ return query .callInReadTx (() ->
282
282
nativeFindFloats (queryHandle , query .cursorHandle (), propertyId , distinct , enableNull , nullValueFloat )
283
283
);
284
284
}
@@ -293,13 +293,13 @@ public float[] findFloats() {
293
293
* See also: {@link #distinct()}
294
294
*/
295
295
public double [] findDoubles () {
296
- return ( double []) query .callInReadTx (() ->
296
+ return query .callInReadTx (() ->
297
297
nativeFindDoubles (queryHandle , query .cursorHandle (), propertyId , distinct , enableNull , nullValueDouble )
298
298
);
299
299
}
300
300
301
301
public String findString () {
302
- return ( String ) query .callInReadTx (() -> {
302
+ return query .callInReadTx (() -> {
303
303
boolean distinctCase = distinct && !noCaseIfDistinct ;
304
304
return nativeFindString (queryHandle , query .cursorHandle (), propertyId , unique , distinct ,
305
305
distinctCase , enableNull , nullValueString );
@@ -357,7 +357,7 @@ public Double findDouble() {
357
357
* This is different from Java arithmetic where it would "wrap around" (e.g. max. value + 1 = min. value).
358
358
*/
359
359
public long sum () {
360
- return ( Long ) query .callInReadTx (
360
+ return query .callInReadTx (
361
361
() -> nativeSum (queryHandle , query .cursorHandle (), propertyId )
362
362
);
363
363
}
@@ -370,7 +370,7 @@ public long sum() {
370
370
* @return 0 in case no elements matched the query
371
371
*/
372
372
public double sumDouble () {
373
- return ( Double ) query .callInReadTx (
373
+ return query .callInReadTx (
374
374
() -> nativeSumDouble (queryHandle , query .cursorHandle (), propertyId )
375
375
);
376
376
}
@@ -381,7 +381,7 @@ public double sumDouble() {
381
381
* @return Long.MIN_VALUE in case no elements matched the query
382
382
*/
383
383
public long max () {
384
- return ( Long ) query .callInReadTx (
384
+ return query .callInReadTx (
385
385
() -> nativeMax (queryHandle , query .cursorHandle (), propertyId )
386
386
);
387
387
}
@@ -392,7 +392,7 @@ public long max() {
392
392
* @return NaN in case no elements matched the query
393
393
*/
394
394
public double maxDouble () {
395
- return ( Double ) query .callInReadTx (
395
+ return query .callInReadTx (
396
396
() -> nativeMaxDouble (queryHandle , query .cursorHandle (), propertyId )
397
397
);
398
398
}
@@ -403,7 +403,7 @@ public double maxDouble() {
403
403
* @return Long.MAX_VALUE in case no elements matched the query
404
404
*/
405
405
public long min () {
406
- return ( Long ) query .callInReadTx (
406
+ return query .callInReadTx (
407
407
() -> nativeMin (queryHandle , query .cursorHandle (), propertyId )
408
408
);
409
409
}
@@ -414,7 +414,7 @@ public long min() {
414
414
* @return NaN in case no elements matched the query
415
415
*/
416
416
public double minDouble () {
417
- return ( Double ) query .callInReadTx (
417
+ return query .callInReadTx (
418
418
() -> nativeMinDouble (queryHandle , query .cursorHandle (), propertyId )
419
419
);
420
420
}
@@ -427,7 +427,7 @@ public double minDouble() {
427
427
* @return NaN in case no elements matched the query
428
428
*/
429
429
public double avg () {
430
- return ( Double ) query .callInReadTx (
430
+ return query .callInReadTx (
431
431
() -> nativeAvg (queryHandle , query .cursorHandle (), propertyId )
432
432
);
433
433
}
@@ -440,7 +440,7 @@ public double avg() {
440
440
* @return 0 in case no elements matched the query
441
441
*/
442
442
public long avgLong () {
443
- return ( Long ) query .callInReadTx (
443
+ return query .callInReadTx (
444
444
() -> nativeAvgLong (queryHandle , query .cursorHandle (), propertyId )
445
445
);
446
446
}
@@ -451,7 +451,7 @@ public long avgLong() {
451
451
* See also: {@link #distinct()}
452
452
*/
453
453
public long count () {
454
- return ( Long ) query .callInReadTx (
454
+ return query .callInReadTx (
455
455
() -> nativeCount (queryHandle , query .cursorHandle (), propertyId , distinct )
456
456
);
457
457
}
0 commit comments