2525 * (subject to change in a future version).
2626 */
2727@ 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 ;
3030 final long queryHandle ;
31- final Property property ;
31+ final Property < T > property ;
3232 final int propertyId ;
3333
3434 boolean distinct ;
@@ -41,7 +41,7 @@ public class PropertyQuery {
4141 String nullValueString ;
4242 long nullValueLong ;
4343
44- PropertyQuery (Query query , Property property ) {
44+ PropertyQuery (Query < T > query , Property < T > property ) {
4545 this .query = query ;
4646 queryHandle = query .handle ;
4747 this .property = property ;
@@ -97,7 +97,7 @@ native String nativeFindString(long handle, long cursorHandle, int propertyId, b
9797 native long nativeCount (long handle , long cursorHandle , int propertyId , boolean distinct );
9898
9999 /** Clears all values (e.g. distinct and null value). */
100- public PropertyQuery reset () {
100+ public PropertyQuery < T > reset () {
101101 distinct = false ;
102102 noCaseIfDistinct = true ;
103103 unique = false ;
@@ -115,7 +115,7 @@ public PropertyQuery reset() {
115115 * Note: strings default to case-insensitive comparision;
116116 * to change that call {@link #distinct(QueryBuilder.StringOrder)}.
117117 */
118- public PropertyQuery distinct () {
118+ public PropertyQuery < T > distinct () {
119119 distinct = true ;
120120 return this ;
121121 }
@@ -124,7 +124,7 @@ public PropertyQuery distinct() {
124124 * For string properties you can specify {@link io.objectbox.query.QueryBuilder.StringOrder#CASE_SENSITIVE} if you
125125 * want to have case sensitive distinct values (e.g. returning "foo","Foo","FOO" instead of "foo").
126126 */
127- public PropertyQuery distinct (QueryBuilder .StringOrder stringOrder ) {
127+ public PropertyQuery < T > distinct (QueryBuilder .StringOrder stringOrder ) {
128128 if (property .type != String .class ) {
129129 throw new RuntimeException ("Reserved for string properties, but got " + property );
130130 }
@@ -142,7 +142,7 @@ public PropertyQuery distinct(QueryBuilder.StringOrder stringOrder) {
142142 * <p>
143143 * Will be ignored for find methods returning multiple values, e.g. {@link #findInts()}.
144144 */
145- public PropertyQuery unique () {
145+ public PropertyQuery < T > unique () {
146146 unique = true ;
147147 return this ;
148148 }
@@ -152,7 +152,7 @@ public PropertyQuery unique() {
152152 * However, using this function, you can define an alternative value that will be returned for null values.
153153 * E.g. -1 for ins/longs or "NULL" for strings.
154154 */
155- public PropertyQuery nullValue (Object nullValue ) {
155+ public PropertyQuery < T > nullValue (Object nullValue ) {
156156 //noinspection ConstantConditions Annotation can not enforce non-null.
157157 if (nullValue == null ) {
158158 throw new IllegalArgumentException ("Null values are not allowed" );
@@ -185,7 +185,7 @@ public PropertyQuery nullValue(Object nullValue) {
185185 * @return Found strings
186186 */
187187 public String [] findStrings () {
188- return ( String []) query .callInReadTx (() -> {
188+ return query .callInReadTx (() -> {
189189 boolean distinctNoCase = distinct && noCaseIfDistinct ;
190190 long cursorHandle = query .cursorHandle ();
191191 return nativeFindStrings (queryHandle , cursorHandle , propertyId , distinct , distinctNoCase ,
@@ -205,7 +205,7 @@ public String[] findStrings() {
205205 * @return Found longs
206206 */
207207 public long [] findLongs () {
208- return ( long []) query .callInReadTx (() ->
208+ return query .callInReadTx (() ->
209209 nativeFindLongs (queryHandle , query .cursorHandle (), propertyId , distinct , enableNull , nullValueLong )
210210 );
211211 }
@@ -220,7 +220,7 @@ public long[] findLongs() {
220220 * See also: {@link #distinct()}
221221 */
222222 public int [] findInts () {
223- return ( int []) query .callInReadTx (() ->
223+ return query .callInReadTx (() ->
224224 nativeFindInts (queryHandle , query .cursorHandle (), propertyId , distinct , enableNull , (int ) nullValueLong )
225225 );
226226 }
@@ -235,7 +235,7 @@ public int[] findInts() {
235235 * See also: {@link #distinct()}
236236 */
237237 public short [] findShorts () {
238- return ( short []) query .callInReadTx (() ->
238+ return query .callInReadTx (() ->
239239 nativeFindShorts (queryHandle , query .cursorHandle (), propertyId , distinct , enableNull , (short ) nullValueLong )
240240 );
241241 }
@@ -250,7 +250,7 @@ public short[] findShorts() {
250250 * See also: {@link #distinct()}
251251 */
252252 public char [] findChars () {
253- return ( char []) query .callInReadTx (() ->
253+ return query .callInReadTx (() ->
254254 nativeFindChars (queryHandle , query .cursorHandle (), propertyId , distinct , enableNull , (char ) nullValueLong )
255255 );
256256 }
@@ -263,7 +263,7 @@ public char[] findChars() {
263263 * Note: results are not guaranteed to be in any particular order.
264264 */
265265 public byte [] findBytes () {
266- return ( byte []) query .callInReadTx (() ->
266+ return query .callInReadTx (() ->
267267 nativeFindBytes (queryHandle , query .cursorHandle (), propertyId , distinct , enableNull , (byte ) nullValueLong )
268268 );
269269 }
@@ -278,7 +278,7 @@ public byte[] findBytes() {
278278 * See also: {@link #distinct()}
279279 */
280280 public float [] findFloats () {
281- return ( float []) query .callInReadTx (() ->
281+ return query .callInReadTx (() ->
282282 nativeFindFloats (queryHandle , query .cursorHandle (), propertyId , distinct , enableNull , nullValueFloat )
283283 );
284284 }
@@ -293,13 +293,13 @@ public float[] findFloats() {
293293 * See also: {@link #distinct()}
294294 */
295295 public double [] findDoubles () {
296- return ( double []) query .callInReadTx (() ->
296+ return query .callInReadTx (() ->
297297 nativeFindDoubles (queryHandle , query .cursorHandle (), propertyId , distinct , enableNull , nullValueDouble )
298298 );
299299 }
300300
301301 public String findString () {
302- return ( String ) query .callInReadTx (() -> {
302+ return query .callInReadTx (() -> {
303303 boolean distinctCase = distinct && !noCaseIfDistinct ;
304304 return nativeFindString (queryHandle , query .cursorHandle (), propertyId , unique , distinct ,
305305 distinctCase , enableNull , nullValueString );
@@ -357,7 +357,7 @@ public Double findDouble() {
357357 * This is different from Java arithmetic where it would "wrap around" (e.g. max. value + 1 = min. value).
358358 */
359359 public long sum () {
360- return ( Long ) query .callInReadTx (
360+ return query .callInReadTx (
361361 () -> nativeSum (queryHandle , query .cursorHandle (), propertyId )
362362 );
363363 }
@@ -370,7 +370,7 @@ public long sum() {
370370 * @return 0 in case no elements matched the query
371371 */
372372 public double sumDouble () {
373- return ( Double ) query .callInReadTx (
373+ return query .callInReadTx (
374374 () -> nativeSumDouble (queryHandle , query .cursorHandle (), propertyId )
375375 );
376376 }
@@ -381,7 +381,7 @@ public double sumDouble() {
381381 * @return Long.MIN_VALUE in case no elements matched the query
382382 */
383383 public long max () {
384- return ( Long ) query .callInReadTx (
384+ return query .callInReadTx (
385385 () -> nativeMax (queryHandle , query .cursorHandle (), propertyId )
386386 );
387387 }
@@ -392,7 +392,7 @@ public long max() {
392392 * @return NaN in case no elements matched the query
393393 */
394394 public double maxDouble () {
395- return ( Double ) query .callInReadTx (
395+ return query .callInReadTx (
396396 () -> nativeMaxDouble (queryHandle , query .cursorHandle (), propertyId )
397397 );
398398 }
@@ -403,7 +403,7 @@ public double maxDouble() {
403403 * @return Long.MAX_VALUE in case no elements matched the query
404404 */
405405 public long min () {
406- return ( Long ) query .callInReadTx (
406+ return query .callInReadTx (
407407 () -> nativeMin (queryHandle , query .cursorHandle (), propertyId )
408408 );
409409 }
@@ -414,7 +414,7 @@ public long min() {
414414 * @return NaN in case no elements matched the query
415415 */
416416 public double minDouble () {
417- return ( Double ) query .callInReadTx (
417+ return query .callInReadTx (
418418 () -> nativeMinDouble (queryHandle , query .cursorHandle (), propertyId )
419419 );
420420 }
@@ -427,7 +427,7 @@ public double minDouble() {
427427 * @return NaN in case no elements matched the query
428428 */
429429 public double avg () {
430- return ( Double ) query .callInReadTx (
430+ return query .callInReadTx (
431431 () -> nativeAvg (queryHandle , query .cursorHandle (), propertyId )
432432 );
433433 }
@@ -440,7 +440,7 @@ public double avg() {
440440 * @return 0 in case no elements matched the query
441441 */
442442 public long avgLong () {
443- return ( Long ) query .callInReadTx (
443+ return query .callInReadTx (
444444 () -> nativeAvgLong (queryHandle , query .cursorHandle (), propertyId )
445445 );
446446 }
@@ -451,7 +451,7 @@ public long avgLong() {
451451 * See also: {@link #distinct()}
452452 */
453453 public long count () {
454- return ( Long ) query .callInReadTx (
454+ return query .callInReadTx (
455455 () -> nativeCount (queryHandle , query .cursorHandle (), propertyId , distinct )
456456 );
457457 }
0 commit comments