public interface OrderedRealmCollection<E extends RealmModel> extends java.util.List<E>, RealmCollection<E>
OrderedRealmCollection
is a collection which maintains an ordering for its elements. Every
element in the OrderedRealmCollection
has an index. Each element can thus be accessed by its
index, with the first index being zero. Normally, OrderedRealmCollection
s allow duplicate
elements, as compared to Sets, where elements have to be unique.Modifier and Type | Method and Description |
---|---|
boolean |
deleteFirstFromRealm()
Deletes the first object from the Realm.
|
void |
deleteFromRealm(int location)
Deletes the object at the given index from the Realm.
|
boolean |
deleteLastFromRealm()
Deletes the last object from the Realm.
|
E |
first()
Gets the first object from the collection.
|
E |
last()
Gets the last object from the collection.
|
RealmResults<E> |
sort(java.lang.String fieldName)
Sorts a collection based on the provided field in ascending order.
|
RealmResults<E> |
sort(java.lang.String[] fieldNames,
Sort[] sortOrders)
Sorts a collection based on the provided fields and sort orders.
|
RealmResults<E> |
sort(java.lang.String fieldName,
Sort sortOrder)
Sorts a collection based on the provided field and sort order.
|
RealmResults<E> |
sort(java.lang.String fieldName1,
Sort sortOrder1,
java.lang.String fieldName2,
Sort sortOrder2)
Sorts a collection based on the provided fields and sort orders.
|
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray
E first()
java.lang.IndexOutOfBoundsException
- if the collection is empty.E last()
java.lang.IndexOutOfBoundsException
- if the collection is empty.RealmResults<E> sort(java.lang.String fieldName)
fieldName
- the field name to sort by. Only fields of type boolean, short, int, long, float, double, Date,
and String are supported.java.lang.IllegalArgumentException
- if field name does not exist or it has an invalid type.java.lang.IllegalStateException
- if the Realm is closed, called on the wrong thread or the collection is
an un-managed collection.RealmResults<E> sort(java.lang.String fieldName, Sort sortOrder)
fieldName
- the field name to sort by. Only fields of type boolean, short, int, long, float, double, Date,
and String are supported.sortOrder
- the direction to sort by.java.lang.IllegalArgumentException
- if field name does not exist or has an invalid type.java.lang.IllegalStateException
- if the Realm is closed, called on the wrong thread or the collection is
an un-managed collection.RealmResults<E> sort(java.lang.String fieldName1, Sort sortOrder1, java.lang.String fieldName2, Sort sortOrder2)
fieldName1
- first field name. Only fields of type boolean, short, int, long, float,
double, Date, and String are supported.sortOrder1
- sort order for first field.fieldName2
- second field name. Only fields of type boolean, short, int, long, float,
double, Date, and String are supported.sortOrder2
- sort order for second field.java.lang.IllegalArgumentException
- if a field name does not exist or has an invalid type.java.lang.IllegalStateException
- if the Realm is closed, called on the wrong thread or the collection is
an un-managed collection.RealmResults<E> sort(java.lang.String[] fieldNames, Sort[] sortOrders)
fieldNames
- an array of field names to sort by. Only fields of type boolean, short, int, long, float,
double, Date, and String are supported.sortOrders
- the directions to sort by.java.lang.IllegalArgumentException
- if a field name does not exist or has an invalid type.java.lang.IllegalStateException
- if the Realm is closed, called on the wrong thread or the collection is
an un-managed collection.void deleteFromRealm(int location)
location
- the array index identifying the object to be removed.java.lang.IndexOutOfBoundsException
- if location < 0 || location >= size()
.java.lang.IllegalStateException
- if the Realm is closed or the method is called from the wrong thread.java.lang.UnsupportedOperationException
- if the collection is un-managed.boolean deleteFirstFromRealm()
true
if an object was deleted, false
otherwise.java.lang.IllegalStateException
- if the Realm is closed or the method is called on the wrong thread.java.lang.UnsupportedOperationException
- if the collection is un-managed.boolean deleteLastFromRealm()
true
if an object was deleted, false
otherwise.java.lang.IllegalStateException
- if the Realm is closed or the method is called from the wrong thread.java.lang.UnsupportedOperationException
- if the collection is un-managed.