Docs Menu
Docs Home
/ /
Atlas Device SDKs
/ / /

Class OrderedRealmCollectionSnapshot

On this page

  • io.realm
  • Method Summary
  • Inherited Methods
  • Method Detail
  • createSnapshot
  • deleteAllFromRealm
  • deleteFirstFromRealm
  • deleteFromRealm
  • deleteLastFromRealm
  • freeze
  • isFrozen
  • isLoaded
  • load
  • size
  • sort
  • where
java.lang.Object
io.realm.OrderedRealmCollectionImpl
io.realm.OrderedRealmCollectionSnapshot

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() {
/@Override
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.
}
}
});
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
int location
)

Deletes the object at the given index from the Realm.

public boolean

Deletes the last object from the Realm.

public boolean
public boolean

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.

java.lang.String[] fieldNames,
io.realm.Sort[] sortOrders
)

Not supported by OrderedRealmCollectionSnapshot .

String fieldName1,
Sort sortOrder1,
String fieldName2,
Sort sortOrder2
)

Not supported by OrderedRealmCollectionSnapshot .

String fieldName,
Sort sortOrder
)

Not supported by OrderedRealmCollectionSnapshot .

String fieldName
)

Not supported by OrderedRealmCollectionSnapshot .

public RealmQuery
  • 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

Creates a snapshot from this OrderedRealmCollection .

Returns

the snapshot of this collection.

Overrides

createSnapshot in class OrderedRealmCollectionImpl

public boolean deleteAllFromRealm ()

This deletes all objects in the collection from the underlying Realm. All objects in the collection snapshot will become invalid.

Returns

true if objects was deleted, false otherwise.

Throws

Overrides

deleteAllFromRealm in class OrderedRealmCollectionImpl

public boolean deleteFirstFromRealm ()

Deletes the first object from the Realm. The first object will become invalid.

Returns

true if an object was deleted, false otherwise.

Throws

Overrides

deleteFirstFromRealm in class OrderedRealmCollectionImpl

public void deleteFromRealm (
int location
)

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

  • location - the array index identifying the object to be removed.

Throws

Overrides

deleteFromRealm in class OrderedRealmCollectionImpl

public boolean deleteLastFromRealm ()

Deletes the last object from the Realm. The last object will become invalid.

Returns

true if an object was deleted, false otherwise.

Throws

Overrides

deleteLastFromRealm in class OrderedRealmCollectionImpl

public boolean isFrozen ()

public boolean isLoaded ()

Checks if a collection has finished loading its data yet.

Returns

true if data has been loaded and is available, false if data is still being loaded.

public boolean load ()

Blocks the collection until all data are available.

Returns

true if the data could be successfully loaded, false otherwise.

public int size ()

Returns the number of elements in this query result.

Returns

the number of elements in this query result.

Overrides

size in class OrderedRealmCollectionImpl

java.lang.String[] fieldNames,
io.realm.Sort[] sortOrders
)

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

sort in class OrderedRealmCollectionImpl

String fieldName1,
Sort sortOrder1,
String fieldName2,
Sort sortOrder2
)

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

sort in class OrderedRealmCollectionImpl

String fieldName,
Sort sortOrder
)

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

sort in class OrderedRealmCollectionImpl

String fieldName
)

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

sort in class OrderedRealmCollectionImpl

public RealmQuery where ()

Not supported by OrderedRealmCollectionSnapshot . Use 'where()' on the original OrderedRealmCollection instead.

Returns

a RealmQuery object.

Throws

Back

OrderedRealmCollectionChangeListener