Skip to content

Commit 3fd484a

Browse files
committed
Add Box.count() with max count
1 parent aa97fba commit 3fd484a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,18 @@ public Map<Long, T> getMap(Iterable<Long> ids) {
276276
* Returns the count of all stored objects in this box.
277277
*/
278278
public long count() {
279+
return count(0);
280+
}
281+
282+
/**
283+
* Returns the count of all stored objects in this box or the given maxCount, whichever is lower.
284+
*
285+
* @param maxCount maximum value to count or 0 (zero) to have no maximum limit
286+
*/
287+
public long count(long maxCount) {
279288
Cursor<T> reader = getReader();
280289
try {
281-
return reader.count();
290+
return reader.count(maxCount);
282291
} finally {
283292
releaseReader(reader);
284293
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public abstract class Cursor<T> implements Closeable {
5858

5959
static native Object nativeFirstEntity(long cursor);
6060

61-
static native long nativeCount(long cursor);
61+
static native long nativeCount(long cursor, long maxCountOrZero);
6262

6363
static native List nativeFindScalarPropertyId(long cursor, int propertyId, long value);
6464

@@ -215,8 +215,8 @@ public boolean seek(long key) {
215215
return nativeSeek(cursor, key);
216216
}
217217

218-
public long count() {
219-
return nativeCount(cursor);
218+
public long count(long maxCountOrZero) {
219+
return nativeCount(cursor, maxCountOrZero);
220220
}
221221

222222
@Override

0 commit comments

Comments
 (0)