Skip to content

Commit e4e76d8

Browse files
committed
PropertyQuery: added remaining find number methods
1 parent 2be1723 commit e4e76d8

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,52 @@ public Integer findUniqueInt() {
278278
return (Integer) findNumber(true);
279279
}
280280

281+
public Short findFirstShort() {
282+
return (Short) findNumber(false);
283+
}
284+
285+
public Short findUniqueShort() {
286+
return (Short) findNumber(true);
287+
}
288+
289+
public Character findFirstChar() {
290+
return (Character) findNumber(false);
291+
}
292+
293+
public Character findUniqueChar() {
294+
return (Character) findNumber(true);
295+
}
296+
297+
public Byte findFirstByte() {
298+
return (Byte) findNumber(false);
299+
}
300+
301+
public Byte findUniqueByte() {
302+
return (Byte) findNumber(true);
303+
}
304+
305+
public Boolean findFirstBoolean() {
306+
return (Boolean) findNumber(false);
307+
}
308+
309+
public Boolean findUniqueBoolean() {
310+
return (Boolean) findNumber(true);
311+
}
312+
313+
public Float findFirstFloat() {
314+
return (Float) findNumber(false);
315+
}
316+
317+
public Float findUniqueFloat() {
318+
return (Float) findNumber(true);
319+
}
320+
321+
public Double findFirstDouble() {
322+
return (Double) findNumber(false);
323+
}
324+
325+
public Double findUniqueDouble() {
326+
return (Double) findNumber(true);
327+
}
328+
281329
}

tests/objectbox-java-test/src/main/java/io/objectbox/query/PropertyQueryTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ public void testFindLong() {
154154
assertNull(query.property(simpleLong).findFirstLong());
155155
assertNull(query.property(simpleLong).findUniqueLong());
156156
putTestEntities(5);
157-
long result = query.property(simpleLong).findFirstLong();
158-
assertEquals(1003, result);
157+
assertEquals(1003, (long) query.property(simpleLong).findFirstLong());
159158

160159
query = box.query().greater(simpleLong, 1004).build();
161160
assertEquals(1005, (long) query.property(simpleLong).distinct().findUniqueLong());
@@ -174,8 +173,7 @@ public void testFindInt() {
174173
assertNull(query.property(simpleInt).findFirstInt());
175174
assertNull(query.property(simpleInt).findUniqueInt());
176175
putTestEntities(5);
177-
int result = query.property(simpleInt).findFirstInt();
178-
assertEquals(3, result);
176+
assertEquals(3, (int) query.property(simpleInt).findFirstInt());
179177

180178
query = box.query().greater(simpleLong, 1004).build();
181179
assertEquals(5, (int) query.property(simpleInt).distinct().findUniqueInt());
@@ -197,6 +195,18 @@ public void testFindInt_uniqueFails() {
197195
box.query().build().property(simpleInt).findUniqueInt();
198196
}
199197

198+
@Test
199+
public void testFindDouble() {
200+
Query<TestEntity> query = box.query().greater(simpleLong, 1002).build();
201+
assertNull(query.property(simpleDouble).findFirstDouble());
202+
assertNull(query.property(simpleDouble).findUniqueDouble());
203+
putTestEntities(5);
204+
assertEquals(2000.03, query.property(simpleDouble).findFirstDouble(), 0.001);
205+
206+
query = box.query().greater(simpleLong, 1004).build();
207+
assertEquals(2000.05, query.property(simpleDouble).distinct().findUniqueDouble(), 0.001);
208+
}
209+
200210
// TODO add test for other types of single object find methods
201211

202212
@Test

0 commit comments

Comments
 (0)