Skip to content

Commit b304bca

Browse files
committed
add Box.isEmpty()
1 parent 3365c36 commit b304bca

File tree

2 files changed

+21
-5
lines changed
  • objectbox-java/src/main/java/io/objectbox
  • tests/objectbox-java-test/src/test/java/io/objectbox

2 files changed

+21
-5
lines changed

objectbox-java/src/main/java/io/objectbox/Box.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ public long count(long maxCount) {
294294
}
295295
}
296296

297+
/** Returns true if no objects are in this box. */
298+
public boolean isEmpty() {
299+
return count(1) == 0;
300+
}
301+
297302
@Temporary
298303
public List<T> find(Property property, String value) {
299304
Cursor<T> reader = getReader();
@@ -580,11 +585,6 @@ public void attach(T entity) {
580585
}
581586
}
582587

583-
// Sketching future API extension
584-
private boolean isEmpty() {
585-
return false;
586-
}
587-
588588
// Sketching future API extension
589589
private boolean isChanged(T entity) {
590590
return false;

tests/objectbox-java-test/src/test/java/io/objectbox/BoxTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,20 @@ public void testGetId() {
251251
assertEquals(entity.getId(), box.getId(entity));
252252
}
253253

254+
@Test
255+
public void testCountMaxAndIsEmpty() {
256+
assertTrue(box.isEmpty());
257+
putTestEntity("banana", 0);
258+
assertFalse(box.isEmpty());
259+
260+
assertEquals(1, box.count(1));
261+
assertEquals(1, box.count(2));
262+
putTestEntity("apple", 0);
263+
assertEquals(2, box.count(2));
264+
assertEquals(2, box.count(3));
265+
266+
box.removeAll();
267+
assertTrue(box.isEmpty());
268+
}
269+
254270
}

0 commit comments

Comments
 (0)