|
22 | 22 | import java.util.ListIterator;
|
23 | 23 | import java.util.NoSuchElementException;
|
24 | 24 |
|
| 25 | +import javax.annotation.Nullable; |
| 26 | + |
25 | 27 | import io.objectbox.Box;
|
26 | 28 | import io.objectbox.exception.DbException;
|
27 | 29 |
|
28 | 30 | /**
|
29 |
| - * A thread-safe, unmodifiable list that reads entities lazily once they are accessed. |
30 |
| - * A lazy list can be cached or not. |
31 |
| - * Cached lazy lists store the previously accessed objects to avoid loading entities more than once. |
32 |
| - * Some features of the list are limited to cached lists (e.g. features that require the entire list). |
| 31 | + * A thread-safe, unmodifiable {@link List} that gets Objects from their Box not until they are accessed. |
| 32 | + * Internally the list is backed by an array of Object IDs. |
| 33 | + * <p> |
| 34 | + * If the list is set to not cache retrieved Objects, each operation will get the latest version of an Object |
| 35 | + * from its Box. However, in this mode only a limited set of {@link List} operations, |
| 36 | + * like get or iterator are supported. |
33 | 37 | * <p>
|
34 |
| - * Note: this list gives an semiconsitent view on the data at the moment it was created. |
35 |
| - * If you remove objects from their object box after this list was created, this list will null instead of an object. |
36 |
| - * However, if you add objects to their object box after this list was created, this list will not be extended. |
| 38 | + * If the list is set to cache retrieved Objects, operations will return a previously fetched version of an Object, |
| 39 | + * which might not equal the latest version in its Box. However, in this mode almost all {@link List} |
| 40 | + * operations are supported. Note that operations that require the whole list, like contains, will fetch all |
| 41 | + * Objects in this list from the Box at once. |
| 42 | + * <p> |
| 43 | + * Note: as Objects are fetched on demand, this list returns a null Object if the Object was removed from its Box |
| 44 | + * after this list was created. |
37 | 45 | *
|
38 | 46 | * @param <E> Object type (entity).
|
39 |
| - * @author Markus |
40 | 47 | */
|
41 |
| -// Threading note: locking is tailored to ArrayList assuming that concurrent positional gets/sets are OK. |
42 |
| -// To enable this, the internal ArrayList is prepopulated with null. |
| 48 | +/* |
| 49 | + Threading note: locking is tailored to ArrayList assuming that concurrent positional gets/sets are OK. |
| 50 | + To enable this, the internal ArrayList is prepopulated with null. |
| 51 | +*/ |
43 | 52 | public class LazyList<E> implements List<E> {
|
44 | 53 | protected class LazyIterator implements ListIterator<E> {
|
45 | 54 | private int index;
|
@@ -206,9 +215,11 @@ public boolean containsAll(Collection<?> collection) {
|
206 | 215 | }
|
207 | 216 |
|
208 | 217 | /**
|
209 |
| - * @return An object for the given ID, or null if the object was already removed from its box |
210 |
| - * (and was not cached before). |
| 218 | + * Gets and returns the Object at the specified position in this list from its Box. Returns null if the |
| 219 | + * Object was removed from its Box. If this list is caching retrieved Objects, returns the previously |
| 220 | + * fetched version. |
211 | 221 | */
|
| 222 | + @Nullable |
212 | 223 | @Override
|
213 | 224 | public E get(int location) {
|
214 | 225 | if (location < 0 || location > size) {
|
|
0 commit comments