TARGET - Object type (entity).public class ToMany<TARGET>
extends java.lang.Object
implements java.util.List<TARGET>, java.io.Serializable
Box.put(Object) of the source entity of this relation or using
applyChangesToDb().
If this relation is a backlink from a ToOne relation, a DB sync will also update ToOne objects
(but not vice versa).
ToMany is thread-safe by default (only if the default CopyOnWriteArrayList is used).
| Constructor and Description |
|---|
ToMany(java.lang.Object sourceEntity,
RelationInfo<?,TARGET> relationInfo) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(int location,
TARGET object)
See
add(Object) for general comments. |
boolean |
add(TARGET object)
Adds the given entity to the list and tracks the addition so it can be later applied to the database
(e.g.
|
boolean |
addAll(java.util.Collection<? extends TARGET> objects)
See
add(Object) for general comments. |
boolean |
addAll(int index,
java.util.Collection<? extends TARGET> objects)
See
add(Object) for general comments. |
void |
applyChangesToDb()
Applies (persists) tracked changes (added and removed entities) to the target box
and/or updates standalone relations.
|
void |
clear() |
boolean |
contains(java.lang.Object object) |
boolean |
containsAll(java.util.Collection<?> collection) |
TARGET |
get(int location) |
int |
getAddCount() |
TARGET |
getById(long id)
Gets an object by its entity ID.
|
ListFactory |
getListFactory() |
int |
getRemoveCount() |
boolean |
hasA(QueryFilter<TARGET> filter)
Returns true if at least one of the entities matches the given filter.
|
boolean |
hasAll(QueryFilter<TARGET> filter)
Returns true if all of the entities match the given filter.
|
boolean |
hasPendingDbChanges()
Returns true if there are pending changes for the DB.
|
int |
indexOf(java.lang.Object object) |
int |
indexOfId(long id)
Gets the index of the object with the given entity ID.
|
void |
internalApplyToDb(io.objectbox.Cursor<?> sourceCursor,
io.objectbox.Cursor<TARGET> targetCursor)
For internal use only; do not use in your app.
|
boolean |
internalCheckApplyToDbRequired()
For internal use only; do not use in your app.
|
boolean |
isEmpty() |
boolean |
isResolved() |
java.util.Iterator<TARGET> |
iterator() |
int |
lastIndexOf(java.lang.Object object) |
java.util.ListIterator<TARGET> |
listIterator() |
java.util.ListIterator<TARGET> |
listIterator(int location)
The returned iterator does not track any potential calls to
Iterator.remove(). |
TARGET |
remove(int location) |
boolean |
remove(java.lang.Object object) |
boolean |
removeAll(java.util.Collection<?> objects) |
TARGET |
removeById(long id)
Removes an object by its entity ID.
|
void |
reset()
Resets the already loaded entities so they will be re-loaded on their next access.
|
boolean |
retainAll(java.util.Collection<?> objects) |
TARGET |
set(int location,
TARGET object) |
void |
setComparator(java.util.Comparator<TARGET> comparator)
Set an comparator to define the order of entities.
|
void |
setListFactory(ListFactory listFactory)
Currently only used for non-persisted entities (id == 0).
|
void |
setRemoveFromTargetBox(boolean removeFromTargetBox)
On put, this also deletes removed entities from the target Box.
|
int |
size() |
void |
sortById()
Sorts the list by the "natural" ObjectBox order for to-many list (by entity ID).
|
java.util.List<TARGET> |
subList(int start,
int end)
The returned sub list does not do any change tracking.
|
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] array) |
public ToMany(java.lang.Object sourceEntity,
RelationInfo<?,TARGET> relationInfo)
@Experimental public void setListFactory(ListFactory listFactory)
@Experimental public void setComparator(java.util.Comparator<TARGET> comparator)
@Experimental public void setRemoveFromTargetBox(boolean removeFromTargetBox)
public ListFactory getListFactory()
public boolean add(TARGET object)
Box.put(Object) of the entity owning the ToMany, or via applyChangesToDb()).
Note that the given entity will remain unchanged at this point (e.g. to-ones are not updated).public void add(int location,
TARGET object)
add(Object) for general comments.add in interface java.util.List<TARGET>public boolean addAll(java.util.Collection<? extends TARGET> objects)
add(Object) for general comments.public boolean addAll(int index,
java.util.Collection<? extends TARGET> objects)
add(Object) for general comments.addAll in interface java.util.List<TARGET>public void clear()
public boolean contains(java.lang.Object object)
public boolean containsAll(java.util.Collection<?> collection)
public TARGET get(int location)
get in interface java.util.List<TARGET>public int indexOf(java.lang.Object object)
indexOf in interface java.util.List<TARGET>public boolean isEmpty()
@Nonnull public java.util.Iterator<TARGET> iterator()
public int lastIndexOf(java.lang.Object object)
lastIndexOf in interface java.util.List<TARGET>@Nonnull public java.util.ListIterator<TARGET> listIterator()
listIterator in interface java.util.List<TARGET>@Nonnull public java.util.ListIterator<TARGET> listIterator(int location)
Iterator.remove().
Thus these removes will NOT be synced to the target Box.listIterator in interface java.util.List<TARGET>public boolean remove(java.lang.Object object)
public TARGET removeById(long id)
public boolean removeAll(java.util.Collection<?> objects)
public boolean retainAll(java.util.Collection<?> objects)
public TARGET set(int location, TARGET object)
set in interface java.util.List<TARGET>public int size()
@Nonnull public java.util.List<TARGET> subList(int start, int end)
subList in interface java.util.List<TARGET>@Nonnull public java.lang.Object[] toArray()
@Nonnull public <T> T[] toArray(T[] array)
public void reset()
public boolean isResolved()
public int getAddCount()
public int getRemoveCount()
public void sortById()
reset()).
Note that non persisted entities (ID is zero) will be put to the end as they are still to get an ID.public void applyChangesToDb()
java.lang.IllegalStateException - If the source entity of this to-many relation was not previously persisted@Beta public boolean hasA(QueryFilter<TARGET> filter)
For use with QueryBuilder.filter(QueryFilter) inside a QueryFilter to check
to-many relation entities.
@Beta public boolean hasAll(QueryFilter<TARGET> filter)
For use with QueryBuilder.filter(QueryFilter) inside a QueryFilter to check
to-many relation entities.
@Beta public TARGET getById(long id)
@Beta public int indexOfId(long id)
public boolean hasPendingDbChanges()
applyChangesToDb() is made.@Internal public boolean internalCheckApplyToDbRequired()
internalApplyToDb(Cursor, Cursor)@Internal
public void internalApplyToDb(io.objectbox.Cursor<?> sourceCursor,
io.objectbox.Cursor<TARGET> targetCursor)
internalCheckApplyToDbRequired() must be called before this call as it prepares .