E
- The class of objects in this listpublic class RealmResults<E extends RealmObject>
extends java.util.AbstractList<E>
RealmQuery
for a given Realm. The objects
are not copied from the Realm to the RealmResults list, but are just referenced from the
RealmResult instead. This saves memory and increases speed.
RealmResults are live views, which means that if it is on an Looper
thread,
it will automatically update its query results after a transaction has been committed. If on a
non-looper thread, Realm.refresh()
must be called to update the results.
Updates to RealmObjects from a RealmResults list must be done from within a transaction and the modified objects are persisted to the Realm file during the commit of the transaction.
A RealmResults object cannot be passed between different threads.
Notice that a RealmResults is never null not even in the case where it contains no objects. You should always use the size() method to check if a RealmResults is empty or not.
Modifier and Type | Field and Description |
---|---|
static boolean |
SORT_ORDER_ASCENDING |
static boolean |
SORT_ORDER_DESCENDING |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E element)
Deprecated.
|
void |
add(int index,
E element)
Deprecated.
|
double |
average(java.lang.String fieldName)
Returns the average of a given field.
|
void |
clear()
Removes all objects from the list.
|
E |
first()
Get the first object from the list.
|
E |
get(int rowIndex) |
int |
indexOf(java.lang.Object o) |
java.util.Iterator<E> |
iterator()
Returns an iterator for the results of a query.
|
E |
last()
Get the last object from the list.
|
java.util.ListIterator<E> |
listIterator()
Returns a list iterator for the results of a query.
|
java.util.ListIterator<E> |
listIterator(int location)
Returns a list iterator on the results of a query.
|
java.lang.Number |
max(java.lang.String fieldName)
Find the maximum value of a field.
|
java.util.Date |
maxDate(java.lang.String fieldName)
Find the maximum date.
|
java.lang.Number |
min(java.lang.String fieldName)
Find the minimum value of a field.
|
java.util.Date |
minDate(java.lang.String fieldName)
Find the minimum date.
|
E |
remove(int index)
Removes an object at a given index.
|
void |
removeLast()
Removes and returns the last object in the list.
|
int |
size() |
void |
sort(java.lang.String fieldName)
Sort (ascending) an existing
RealmResults . |
void |
sort(java.lang.String[] fieldNames,
boolean[] sortAscending)
Sort existing
RealmResults . |
void |
sort(java.lang.String fieldName,
boolean sortAscending)
Sort existing
RealmResults . |
void |
sort(java.lang.String fieldName1,
boolean sortAscending1,
java.lang.String fieldName2,
boolean sortAscending2)
Sort existing
RealmResults using two fields. |
void |
sort(java.lang.String fieldName1,
boolean sortAscending1,
java.lang.String fieldName2,
boolean sortAscending2,
java.lang.String fieldName3,
boolean sortAscending3)
Sort existing
RealmResults using three fields. |
java.lang.Number |
sum(java.lang.String fieldName)
Calculate the sum of a given field.
|
RealmQuery<E> |
where()
Returns a typed
RealmQuery , which can be used to query for specific
objects of this type. |
addAll, equals, hashCode, lastIndexOf, removeRange, set, subList
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
public static final boolean SORT_ORDER_ASCENDING
public static final boolean SORT_ORDER_DESCENDING
public RealmQuery<E> where()
RealmQuery
, which can be used to query for specific
objects of this type.RealmQuery
public E get(int rowIndex)
get
in interface java.util.List<E extends RealmObject>
get
in class java.util.AbstractList<E extends RealmObject>
public int indexOf(java.lang.Object o)
indexOf
in interface java.util.List<E extends RealmObject>
indexOf
in class java.util.AbstractList<E extends RealmObject>
public E first()
public E last()
public java.util.Iterator<E> iterator()
ConcurrentModificationException
if accessed.iterator
in interface java.lang.Iterable<E extends RealmObject>
iterator
in interface java.util.Collection<E extends RealmObject>
iterator
in interface java.util.List<E extends RealmObject>
iterator
in class java.util.AbstractList<E extends RealmObject>
Iterator
public java.util.ListIterator<E> listIterator()
ConcurrentModificationException
if accessed.listIterator
in interface java.util.List<E extends RealmObject>
listIterator
in class java.util.AbstractList<E extends RealmObject>
ListIterator
public java.util.ListIterator<E> listIterator(int location)
ConcurrentModificationException
if accessed.listIterator
in interface java.util.List<E extends RealmObject>
listIterator
in class java.util.AbstractList<E extends RealmObject>
location
- the index at which to start the iteration.java.lang.IndexOutOfBoundsException
- if location < 0 || location > size()
ListIterator
public void sort(java.lang.String fieldName)
RealmResults
.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.public void sort(java.lang.String fieldName, boolean sortAscending)
RealmResults
.fieldName
- The field name to sort by. Only fields of type boolean, short, int,
long, float, double, Date, and String are supported.sortAscending
- The direction to sort by; if true ascending, otherwise descending
You can use the constants SORT_ORDER_ASCENDING and SORT_ORDER_DESCENDING
for readability.java.lang.IllegalArgumentException
- if field name does not exist.public void sort(java.lang.String[] fieldNames, boolean[] sortAscending)
RealmResults
.fieldNames
- an array of field names to sort by. Only fields of type boolean, short, int,
long, float, double, Date, and String are supported.sortAscending
- The directions to sort by; if true ascending, otherwise descending
You can use the constants SORT_ORDER_ASCENDING and SORT_ORDER_DESCENDING
for readability.java.lang.IllegalArgumentException
- if a field name does not exist.public void sort(java.lang.String fieldName1, boolean sortAscending1, java.lang.String fieldName2, boolean sortAscending2)
RealmResults
using two fields.fieldName1
- first field name.sortAscending1
- sort order for first field.fieldName2
- second field name.sortAscending2
- sort order for second field.java.lang.IllegalArgumentException
- if a field name does not exist.public void sort(java.lang.String fieldName1, boolean sortAscending1, java.lang.String fieldName2, boolean sortAscending2, java.lang.String fieldName3, boolean sortAscending3)
RealmResults
using three fields.fieldName1
- first field name.sortAscending1
- sort order for first field.fieldName2
- second field name.sortAscending2
- sort order for second field.fieldName3
- third field name.sortAscending3
- sort order for third field.java.lang.IllegalArgumentException
- if a field name does not exist.public int size()
size
in interface java.util.Collection<E extends RealmObject>
size
in interface java.util.List<E extends RealmObject>
size
in class java.util.AbstractCollection<E extends RealmObject>
public java.lang.Number min(java.lang.String fieldName)
fieldName
- The field to look for a minimum on. Only int, float, and double
are supported.java.lang.IllegalArgumentException
- if field is not int, float or double.public java.util.Date minDate(java.lang.String fieldName)
fieldName
- The field to look for the minimum date. If fieldName is not of Date type,
an exception is thrown.java.lang.IllegalArgumentException
- if fieldName is not a Date field.public java.lang.Number max(java.lang.String fieldName)
fieldName
- The field to look for a maximum on. Only int, float, and double are supported.java.lang.IllegalArgumentException
- if field is not int, float or double.public java.util.Date maxDate(java.lang.String fieldName)
fieldName
- The field to look for the maximum date. If fieldName is not of Date type,
an exception is thrown.java.lang.IllegalArgumentException
- if fieldName is not a Date field.public java.lang.Number sum(java.lang.String fieldName)
fieldName
- The field to sum. Only int, float, and double are supported.java.lang.IllegalArgumentException
- if field is not int, float or double.public double average(java.lang.String fieldName)
fieldName
- The field to calculate average on. Only properties of type int,
float and double are supported.java.lang.IllegalArgumentException
- if field is not int, float or double.public E remove(int index)
RealmResults.RealmResultsIterator.remove()
instead.remove
in interface java.util.List<E extends RealmObject>
remove
in class java.util.AbstractList<E extends RealmObject>
index
- The array index identifying the object to be removed.public void removeLast()
removeLast()
instead.public void clear()
clear
in interface java.util.Collection<E extends RealmObject>
clear
in interface java.util.List<E extends RealmObject>
clear
in class java.util.AbstractList<E extends RealmObject>
@Deprecated public boolean add(E element)
add
in interface java.util.Collection<E extends RealmObject>
add
in interface java.util.List<E extends RealmObject>
add
in class java.util.AbstractList<E extends RealmObject>
@Deprecated public void add(int index, E element)
add
in interface java.util.List<E extends RealmObject>
add
in class java.util.AbstractList<E extends RealmObject>