Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
io.realm

Class RealmResults

java.lang.Object
io.realm.OrderedRealmCollectionImpl
io.realm.RealmResults

Esta clase contiene todas las coincidencias de una consulta RealmQuery para un dominio determinado. Los objetos no se copian del dominio a la lista RealmResults, sino que se referencian desde RealmResult. Esto ahorra memoria y aumenta la velocidad.

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.

Tenga en cuenta que un RealmResults nunca es null Ni siquiera si no contiene objetos. Siempre debe usar el método RealmResults.size() para comprobar si un RealmResults está vacío.

If a RealmResults is built on RealmList through RealmList.where() , it will become empty when the source RealmList gets deleted.

RealmResults puede contener más de elementos.Integer.MAX_VALUE En ese caso, solo se puede acceder a los primeros Integer.MAX_VALUE elementos.

Tip

Modificador y Tipo
Método y descripción

public void

public void

public <any>

Devuelve un Observable Rx que supervisa los cambios en estos RealmResults.

public <any>

Devuelve un Rx Flowable que supervisa los cambios en estos RealmResults.

public String

Returns a JSON representation of the matches of a RealmQuery .

public booleano

public booleano

Devuelve false si los resultados aún no se han cargado, true si ya se han cargado.

public booleano

load ()

Makes an asynchronous query blocking.

public void

Removes all user-defined change listeners.

public void

public void

Removes the specified change listener.

public void

String fieldName,
byte[] value
)

Sets the binary value of the given field in all of the objects in the collection.

public void

String fieldName,
boolean value
)

Sets the boolean value of the given field in all of the objects in the collection.

public void

String fieldName,
byte value
)

Sets the byte value of the given field in all of the objects in the collection.

public void

String fieldName,
Date value
)

Sets the Date value of the given field in all of the objects in the collection.

public void

String fieldName,
Decimal128 value
)

Sets the Decimal128 value of the given field in all of the objects in the collection.

public void

String fieldName,
double value
)

Sets the double value of the given field in all of the objects in the collection.

public void

String fieldName,
float value
)

Sets the float value of the given field in all of the objects in the collection.

public void

String fieldName,
int value
)

Sets the int value of the given field in all of the objects in the collection.

public void

setList <T >(
)

Reemplaza el RealmList en el campo dado en todos los objetos de esta colección.

public void

String fieldName,
long value
)

Sets the long value of the given field in all of the objects in the collection.

public void

String fieldName
)

Establece el valor en null para el campo dado en todos los objetos de la colección.

public void

String fieldName,
)

Sets a reference to another object on the given field in all of the objects in the collection.

public void

String fieldName,
ObjectId value
)

Sets the ObjectId value of the given field in all of the objects in the collection.

public void

String fieldName,
short value
)

Sets the short value of the given field in all of the objects in the collection.

public void

String fieldName,
String value
)

Sets the String value of the given field in all of the objects in the collection.

public void

String fieldName,
UUID value
)

Sets the UUID value of the given field in all of the objects in the collection.

public void

String fieldName,
Object value
)

Updates the field given by fieldName in all objects inside the query result.

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

Ordena una colección en función de los campos y órdenes de clasificación enviados.

Returns a RealmQuery , which can be used to query for specific objects from this collection.

  • 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

Adds a change listener to this RealmResults .

Registering a change listener will not prevent the underlying RealmResults from being garbage collected. If the RealmResults is garbage collected, the change listener will stop being triggered. To avoid this, keep a strong reference for as long as appropriate e.g. in a class variable.

public class MyActivity extends Activity {
private RealmResults<Person> results; // Strong reference to keep listeners alive
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
results = realm.where(Person.class).findAllAsync();
results.addChangeListener(new OrderedRealmCollectionChangeListener<RealmResults<Person>>() {
@Override
public void onChange(RealmResults<Person> persons, OrderedCollectionChangeSet changeSet) {
// React to change
}
});
}
}

Parámetros

  • listener - the change listener to be notified.

Throws

Adds a change listener to this RealmResults .

Registering a change listener will not prevent the underlying RealmResults from being garbage collected. If the RealmResults is garbage collected, the change listener will stop being triggered. To avoid this, keep a strong reference for as long as appropriate e.g. in a class variable.

public class MyActivity extends Activity {
private RealmResults<Person> results; // Strong reference to keep listeners alive
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
results = realm.where(Person.class).findAllAsync();
results.addChangeListener(new RealmChangeListener<RealmResults<Person>>() {
@Override
public void onChange(RealmResults<Person> persons) {
// React to change
}
});
}
}

Parámetros

  • listener - the change listener to be notified.

Throws

public <any> asChangesetObservable ()

Returns an Rx Observable that monitors changes to this RealmResults. It will emit the current RealmResults when subscribed. For each update to the RealmResult a pair consisting of the RealmResults and the OrderedCollectionChangeSet will be sent. The changeset will be null the first time an RealmResults is emitted.

RealmResults will continually be emitted as the RealmResults are updated - onComplete will never be called.

Los elementos emitidos por Realm Observables están congelados (consulta freeze() ). Esto significa que son inmutables y se pueden leer en cualquier hilo.

Realm Observables always emit items from the thread holding the live Realm. This means that if you need to do further processing, it is recommend to observe the values on a computation scheduler:

realm.where(Foo.class).findAllAsync().asChangesetObservable()
.observeOn(Schedulers.computation())
.map((rxResults, changes) -> doExpensiveWork(rxResults, changes))
.observeOn(AndroidSchedulers.mainThread())
.subscribe( ... );

Devuelve

Observable de RxJava que solo llama a onNext . Nunca llamará a onComplete ni a OnError .

Throws

public <any> asFlowable ()

Returns an Rx Flowable that monitors changes to this RealmResults. It will emit the current RealmResults when subscribed to. RealmResults will continually be emitted as the RealmResults are updated - onComplete will never be called.

Los elementos emitidos desde Realm Flowables están congelados (ver freeze()). Esto significa que son inmutables y se pueden leer en cualquier hilo.

Realm Flowables siempre emite elementos desde el hilo que mantiene los RealmResults en vivo. Esto significa que si necesitas realizar un procesamiento adicional, se recomienda observar los valores en un programador de cálculo:

realm.where(Foo.class).findAllAsync().asFlowable()
.observeOn(Schedulers.computation())
.map(rxResults -> doExpensiveWork(rxResults))
.observeOn(AndroidSchedulers.mainThread())
.subscribe( ... );

If you would like the asFlowable() to stop emitting items you can instruct RxJava to only emit only the first item by using the first() operator:

realm.where(Foo.class).findAllAsync().asFlowable()
.filter(results -> results.isLoaded())
.first()
.subscribe( ... ) // You only get the results once

Devuelve

Observable de RxJava que solo llama a onNext . Nunca llamará a onComplete ni a OnError .

Throws

public String asJSON ()

Devuelve una representación JSON de las coincidencias de una RealmQuery. Los ciclos se devolverán como índices de fila. Este método auxiliar se utiliza para inspeccionar datos o, para fines de depuración, podría extraer una cadena larga, lo que podría causar un error de memoria insuficiente.

Devuelve

string representation of a JSON array containing entries of the resulting RealmQuery .

public boolean isFrozen ()

public boolean isLoaded ()

Devuelve false si los resultados aún no se han cargado, true si ya se han cargado.

Devuelve

true if the query has completed and the data is available, false if the query is still running in the background.

public boolean load ()

Makes an asynchronous query blocking. This will also trigger any registered RealmChangeListener when the query completes.

Devuelve

true if it successfully completed the query, false otherwise.

Removes all user-defined change listeners.

Throws

Removes the specified change listener.

Parámetros

  • listener - the change listener to be removed.

Throws

Removes the specified change listener.

Parámetros

  • listener - the change listener to be removed.

Throws

public void setBlob (
String fieldName,
byte[] value
)

Sets the binary value of the given field in all of the objects in the collection.

Parámetros

  • fieldName - nombre del campo a actualizar.

  • value - nuevo valor para el campo.

Throws

public void setBoolean (
String fieldName,
boolean value
)

Sets the boolean value of the given field in all of the objects in the collection.

Parámetros

  • fieldName - nombre del campo a actualizar.

  • value - nuevo valor para el campo.

Throws

public void setByte (
String fieldName,
byte value
)

Sets the byte value of the given field in all of the objects in the collection.

Parámetros

  • fieldName - nombre del campo a actualizar.

  • value - nuevo valor para el campo.

Throws

public void setDate (
String fieldName,
Date value
)

Sets the Date value of the given field in all of the objects in the collection.

Parámetros

  • fieldName - nombre del campo a actualizar.

  • value - nuevo valor para el campo.

Throws

public void setDecimal128 (
String fieldName,
Decimal128 value
)

Sets the Decimal128 value of the given field in all of the objects in the collection.

Parámetros

  • fieldName - nombre del campo a actualizar.

  • value - nuevo valor para el campo.

Throws

public void setDouble (
String fieldName,
double value
)

Sets the double value of the given field in all of the objects in the collection.

Parámetros

  • fieldName - nombre del campo a actualizar.

  • value - nuevo valor para el campo.

Throws

  • IllegalArgumentException - si el nombre del campo no existe, es una propiedad de llave primaria o no es un campo double.

public void setFloat (
String fieldName,
float value
)

Sets the float value of the given field in all of the objects in the collection.

Parámetros

  • fieldName - nombre del campo a actualizar.

  • value - nuevo valor para el campo.

Throws

public void setInt (
String fieldName,
int value
)

Sets the int value of the given field in all of the objects in the collection.

Parámetros

  • fieldName - nombre del campo a actualizar.

  • value - nuevo valor para el campo.

Throws

public void setList <T >(
)

Reemplaza el RealmList en el campo dado en todos los objetos de esta colección.

Parámetros

  • fieldName - nombre del campo a actualizar.

  • list - nuevo valor para el campo.

Throws

  • IllegalArgumentException: si el nombre del campo no existe, no es un campo RealmList, si los objetos en la lista no se administran o el tipo de los objetos en la lista es incorrecto.

public void setLong (
String fieldName,
long value
)

Sets the long value of the given field in all of the objects in the collection.

Parámetros

  • fieldName - nombre del campo a actualizar.

  • value - nuevo valor para el campo.

Throws

public void setNull (
String fieldName
)

Establece el valor en null para el campo dado en todos los objetos de la colección.

Parámetros

  • fieldName - nombre del campo a actualizar.

Throws

public void setObject (
String fieldName,
)

Sets a reference to another object on the given field in all of the objects in the collection.

Parámetros

  • fieldName - nombre del campo a actualizar.

  • value - new object referenced by this field.

Throws

public void setObjectId (
String fieldName,
ObjectId value
)

Sets the ObjectId value of the given field in all of the objects in the collection.

Parámetros

  • fieldName - nombre del campo a actualizar.

  • value - nuevo valor para el campo.

Throws

public void setShort (
String fieldName,
short value
)

Sets the short value of the given field in all of the objects in the collection.

Parámetros

  • fieldName - nombre del campo a actualizar.

  • value - nuevo valor para el campo.

Throws

public void setString (
String fieldName,
String value
)

Sets the String value of the given field in all of the objects in the collection.

Parámetros

  • fieldName - nombre del campo a actualizar.

  • value - nuevo valor para el campo.

Throws

public void setUUID (
String fieldName,
UUID value
)

Sets the UUID value of the given field in all of the objects in the collection.

Parámetros

  • fieldName - nombre del campo a actualizar.

  • value - nuevo valor para el campo.

Throws

public void setValue (
String fieldName,
Object value
)

Updates the field given by fieldName in all objects inside the query result.

Este método intentará automáticamente convertir números y booleanos que se entregan como String a su tipo correspondiente. Por ejemplo, "10" se convertirá en 10 si el tipo del campo es RealmFieldType.INTEGER .

Using the typed setters like setInt(String, int) will be faster than using this method.

Parámetros

  • fieldName - campo a actualizar

  • value - valor a actualizar.

Throws

  • IllegalArgumentException - if the field could not be found, could not be updated or the argument didn't match the field type or could not be converted to match the underlying field type.

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

Ordena una colección en función de los campos y órdenes de clasificación enviados.

Devuelve

se creará y devolverá un nuevo RealmResults ordenado. La colección original permanece sin cambios.

Anulaciones

sort en la clase OrderedRealmCollectionImpl

public RealmQuery where ()

Returns a RealmQuery , which can be used to query for specific objects from this collection.

Devuelve

un objeto de RealmQuery.

Volver

RealmQuery

En esta página