Skip to content

Commit b5a023b

Browse files
committed
Box.getAll(): always return mutable list (ArrayList), simplify
1 parent 4917cfc commit b5a023b

File tree

1 file changed

+5
-15
lines changed
  • objectbox-java/src/main/java/io/objectbox

1 file changed

+5
-15
lines changed

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -303,26 +303,16 @@ public boolean isEmpty() {
303303

304304
/**
305305
* Returns all stored Objects in this Box.
306+
* @return since 2.4 the returned list is always mutable (before an empty result list was immutable)
306307
*/
307308
public List<T> getAll() {
309+
ArrayList<T> list = new ArrayList<>();
308310
Cursor<T> cursor = getReader();
309311
try {
310-
T first = cursor.first();
311-
if (first == null) {
312-
return Collections.emptyList();
313-
} else {
314-
ArrayList<T> list = new ArrayList<>();
315-
list.add(first);
316-
while (true) {
317-
T next = cursor.next();
318-
if (next != null) {
319-
list.add(next);
320-
} else {
321-
break;
322-
}
323-
}
324-
return list;
312+
for (T object = cursor.first(); object != null; object = cursor.next()) {
313+
list.add(object);
325314
}
315+
return list;
326316
} finally {
327317
releaseReader(cursor);
328318
}

0 commit comments

Comments
 (0)