Class OrderedRealmCollectionSnapshot
On this page
io.realm
An OrderedRealmCollectionSnapshot is a special type of OrderedRealmCollection . It can be created by calling OrderedRealmCollection.createSnapshot() . Unlike RealmResults and RealmList , its size and order of elements will never be changed after creation.
OrderedRealmCollectionSnapshot is useful when making changes which may impact the size or order of the collection in simple loops. For example:
final RealmResults<Dog> dogs = realm.where(Dog.class).findAll(); final OrderedRealmCollectionSnapshot<Dog> snapshot = dogs.createSnapshot(); final int dogsCount = snapshot.size(); // dogs.size() == snapshot.size() == 10 realm.executeTransaction(new Realm.Transaction() { / public void execute(Realm realm) { for (int i = 0; i < dogsCount; i++) { // This won't work since RealmResults is always up-to-date, its size gets decreased by 1 after every loop. An // IndexOutOfBoundsException will be thrown after 5 loops. // dogs.deleteFromRealm(i); snapshot.deleteFromRealm(i); // Deletion on OrderedRealmCollectionSnapshot won't change the size of it. } } });
Method Summary
Modifier and Type | Method and Description |
---|---|
Creates a snapshot from this OrderedRealmCollection . | |
public boolean | This deletes all objects in the collection from the underlying Realm. |
public boolean | Deletes the first object from the Realm. |
public void | Deletes the object at the given index from the Realm. |
public boolean | Deletes the last object from the Realm. |
public OrderedRealmCollection | freeze () |
public boolean | isFrozen () |
public boolean | isLoaded () Checks if a collection has finished loading its data yet. |
public boolean | load () Blocks the collection until all data are available. |
public int | size () Returns the number of elements in this query result. |
public RealmResults | Not supported by OrderedRealmCollectionSnapshot . |
public RealmResults | |
public RealmResults | Not supported by OrderedRealmCollectionSnapshot . |
public RealmResults | Not supported by OrderedRealmCollectionSnapshot . |
public RealmQuery | where () Not supported by OrderedRealmCollectionSnapshot . |
Inherited Methods
Methods inherited from class java.lang.Object :
getClass
,hashCode
,equals
,clone
,toString
,notify
,notifyAll
,wait
,wait
,wait
,finalize
Methods inherited from class java.util.AbstractCollection :
iterator
,size
,isEmpty
,contains
,toArray
,toArray
,add
,remove
,containsAll
,addAll
,removeAll
,retainAll
,clear
,toString
Methods inherited from class java.util.AbstractList :
add
,get
,set
,add
,remove
,indexOf
,lastIndexOf
,clear
,addAll
,iterator
,listIterator
,listIterator
,subList
,equals
,hashCode
,removeRange
Methods inherited from class io.realm.OrderedRealmCollectionImpl:
isValid
,isManaged
,contains
,get
,first
,first
,last
,last
,deleteFromRealm
,deleteAllFromRealm
,iterator
,listIterator
,listIterator
,sort
,sort
,sort
,sort
,size
,min
,minDate
,max
,maxDate
,sum
,average
,remove
,remove
,removeAll
,set
,retainAll
,deleteLastFromRealm
,deleteFirstFromRealm
,clear
,add
,add
,addAll
,addAll
,createSnapshot
,getRealm
,getCollectionOperator
Method Detail
createSnapshot
public OrderedRealmCollectionSnapshot createSnapshot () |
---|
Creates a snapshot from this OrderedRealmCollection . Returns the snapshot of this collection. Overrides
|
deleteAllFromRealm
public boolean deleteAllFromRealm () |
---|
This deletes all objects in the collection from the underlying Realm. All objects in the collection snapshot will become invalid. Returns
Throws
Overrides
|
deleteFirstFromRealm
public boolean deleteFirstFromRealm () |
---|
Deletes the first object from the Realm. The first object will become invalid. Returns
Throws
Overrides
|
deleteFromRealm
Deletes the object at the given index from the Realm. The object at the given index will become invalid. Just returns if the object is invalid already. Parameters
Throws
Overrides
|
deleteLastFromRealm
public boolean deleteLastFromRealm () |
---|
Deletes the last object from the Realm. The last object will become invalid. Returns
Throws
Overrides
|
freeze
public OrderedRealmCollection freeze () |
---|
isFrozen
public boolean isFrozen () |
---|
isLoaded
public boolean isLoaded () |
---|
Checks if a collection has finished loading its data yet. Returns
|
load
public boolean load () |
---|
Blocks the collection until all data are available. Returns
|
size
public int size () |
---|
Returns the number of elements in this query result. Returns the number of elements in this query result. Overrides
|
sort
Not supported by OrderedRealmCollectionSnapshot . Use 'sort()' on the original OrderedRealmCollection instead. Returns a new sorted RealmResults will be created and returned. The original collection stays unchanged. Throws Overrides
|
Not supported by OrderedRealmCollectionSnapshot . Use 'sort()' on the original OrderedRealmCollection instead. Returns a new sorted RealmResults will be created and returned. The original collection stays unchanged. Throws Overrides
|
Not supported by OrderedRealmCollectionSnapshot . Use 'sort()' on the original OrderedRealmCollection instead. Returns a new sorted RealmResults will be created and returned. The original collection stays unchanged. Throws Overrides
|
Not supported by OrderedRealmCollectionSnapshot . Use 'sort()' on the original OrderedRealmCollection instead. Returns a new sorted RealmResults will be created and returned. The original collection stays unchanged. Throws Overrides
|
where
public RealmQuery where () |
---|
Not supported by OrderedRealmCollectionSnapshot . Use 'where()' on the original OrderedRealmCollection instead. Returns a RealmQuery object. Throws |