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 RealmAny

java.lang.Object
io.realm.RealmAny

io.realm.RealmAny is used to represent a polymorphic Realm value.

At any particular moment an instance of this class stores a definite value of a definite type. If, for instance, that is an double value, you may call asDouble() to extract that value. You may call getType() to discover what type of value is currently stored. Calling asDouble() on an instance that does not store an double would raise a java.lang.ClassCastException .

RealmAny behaves like a value type on all the supported types except on Realm objects. It means that Realm will not persist any change to the RealmAny value except when the type is Realm object. When a RealmAny holds a Realm object, it just holds the reference to it, not a copy of the object. So modifications to the Realm object are reflected in the RealmAny value, including if the object is deleted. Because RealmAny instances are immutable, a new instance is needed to update a RealmAny attribute.

anObject.realmAnyAttribute = RealmAny.valueOf(5);
anObject.realmAnyAttribute = RealmAny.valueOf(10.f);

Es crucial entender que el acto de extraer un valor de un tipo específico requiere un conocimiento definido sobre el tipo almacenado. Invocar un método getter para cualquier tipo en particular, que no sea del mismo tipo que el valor almacenado, puede provocar una excepción. Nuestra recomendación para gestionar el polimorfismo RealmAny es guardar un caso switch alrededor del tipo RealmAny y su clase de valor interno.

RealmAny realmAny = aRealmObject.realmAnyAttribute;
switch (realmAny.getType()) {
case OBJECT:
if (realmAny.getValueClass().equals(DogRealmModel.class)) {
DogRealmModel value = realmAny.asRealmModel(DogRealmModel.class);
}
case INTEGER:
performAction(realmAny.asInteger());
break;
case BOOLEAN:
performAction(realmAny.asBoolean());
break;
case STRING:
performAction(realmAny.asString());
break;
case BINARY:
performAction(realmAny.asBinary());
break;
case DATE:
performAction(realmAny.asDate());
break;
case FLOAT:
performAction(realmAny.asFloat());
break;
case DOUBLE:
performAction(realmAny.asDouble());
break;
case DECIMAL128:
performAction(realmAny.asDecimal128());
break;
case OBJECT_ID:
performAction(realmAny.asObjectId());
break;
case UUID:
performAction(realmAny.asUUID());
break;
case NULL:
performNullAction();
break;
}

getValueClass() retorna la clase Java que representa el valor interno envuelto por la instancia RealmAny. Si la clase resultante es una realización de io.realm.RealmModel, se puede llamar asRealmModel() para convertir el valor de RealmAny en una referencia de objeto Realm.

RealmAny values can also be sorted. The sorting order used between different RealmAny types, from lowest to highest, is:

  1. Booleano

  2. Byte/Short/Integer/Long/Float/Double/Decimal128

  3. byte[]/String

  4. fecha

  5. ObjectId

  6. UUID

  7. RealmObject

Esto tiene implicaciones en el funcionamiento de RealmQuery.sort(String), RealmQuery.minRealmAny(String) y RealmQuery.maxRealmAny(String). Especialmente min() y max() no solo tendrá en cuenta los campos numéricos, sino que utilizará el orden de clasificación para determinar el valor "más grande" o "más bajo".

Modificador y Tipo
Clase y descripción

public static final

Modificador y Tipo
Método y descripción

public byte

Obtiene este valor como un byte[] si lo es, de lo contrario lanza una excepción.

public Boolean

Gets this value as a Boolean if it is one, otherwise throws exception.

public Byte

Obtiene este valor como un Byte si lo es; de lo contrario, lanza una excepción.

public Date

Gets this value as a Date if it is one, otherwise throws exception.

público Decimal128

Obtiene este valor como un Decimal128 si lo es, de lo contrario lanza una excepción.

public Double

Gets this value as a Double if it is one, otherwise throws exception.

public Float

Gets this value as a Float if it is one, otherwise throws exception.

public Integer

Obtiene este valor como Integer si es uno, de lo contrario lanza excepciones.

public Long

Gets this value as a Long if it is one, otherwise throws exception.

public ObjectId

Gets this value as a ObjectId if it is one, otherwise throws exception.

public T

Gets this value as a RealmModel if it is one, otherwise throws exception.

public Short

Obtiene este valor como Short si lo es, de lo contrario, lanza una excepción.

public String

Obtiene este valor como una cadena si es uno, de lo contrario arroja una excepción.

public UUID

Gets this value as a UUID if it is one, otherwise throws exception.

public final boolean

public final boolean

Object other
)

Dos RealmAny son .equals si y solo si su contenido es igual.

público RealmAny.Type

Obtiene el tipo interno de este objeto RealmAny.

public Class

Returns the Java class that represents the inner value wrapped by this RealmAny value.

public final int

A RealmAny 's hash code is, exactly, the hash code of its value.

public booleano

Returns true if the inner value is null, false otherwise.

public static RealmAny

Creates a new RealmAny of a null value.

public String

public static RealmAny

Decimal128 value
)

Crea un nuevo RealmAny con el valor especificado.

public static RealmAny

ObjectId value
)

Crea un nuevo RealmAny con el valor especificado.

public static RealmAny

Date value
)

Crea un nuevo RealmAny con el valor especificado.

public static RealmAny

byte[] value
)

Crea un nuevo RealmAny con el valor especificado.

public static RealmAny

String value
)

Crea un nuevo RealmAny con el valor especificado.

public static RealmAny

Double value
)

Crea un nuevo RealmAny con el valor especificado.

public static RealmAny

Float value
)

Crea un nuevo RealmAny con el valor especificado.

public static RealmAny

Crea un nuevo RealmAny con el valor especificado.

public static RealmAny

Long value
)

Crea un nuevo RealmAny con el valor especificado.

public static RealmAny

Crea un nuevo RealmAny con el valor especificado.

public static RealmAny

Short value
)

Crea un nuevo RealmAny con el valor especificado.

public static RealmAny

Byte value
)

Crea un nuevo RealmAny con el valor especificado.

  • Methods inherited from class java.lang.Object : getClass , hashCode , equals , clone , toString , notify , notifyAll , wait , wait , wait , finalize

public byte asBinary ()

Obtiene este valor como un byte[] si lo es, de lo contrario lanza una excepción.

Devuelve

a byte[].

Throws

public Boolean asBoolean ()

Gets this value as a Boolean if it is one, otherwise throws exception.

Devuelve

a Boolean.

Throws

public Byte asByte ()

Obtiene este valor como un Byte si lo es; de lo contrario, lanza una excepción.

Devuelve

a Byte.

Throws

public Date asDate ()

Gets this value as a Date if it is one, otherwise throws exception.

Devuelve

a Date.

Throws

public Decimal128 asDecimal128 ()

Obtiene este valor como un Decimal128 si lo es, de lo contrario lanza una excepción.

Devuelve

a Decimal128.

Throws

public Double asDouble ()

Gets this value as a Double if it is one, otherwise throws exception.

Devuelve

un Doble.

Throws

public Float asFloat ()

Gets this value as a Float if it is one, otherwise throws exception.

Devuelve

un flotador.

Throws

public Integer asInteger ()

Obtiene este valor como Integer si es uno, de lo contrario lanza excepciones.

Devuelve

an Integer.

Throws

public Long asLong ()

Gets this value as a Long if it is one, otherwise throws exception.

Devuelve

a Long.

Throws

public ObjectId asObjectId ()

Gets this value as a ObjectId if it is one, otherwise throws exception.

Devuelve

an ObjectId.

Throws

public T asRealmModel <T >(
)

Gets this value as a RealmModel if it is one, otherwise throws exception.

Type Parameters

  • T - el tipo RealmModel para convertir el valor interno.

Devuelve

a RealmModel of the T type.

Throws

public Short asShort ()

Obtiene este valor como Short si lo es, de lo contrario, lanza una excepción.

Devuelve

un Short.

Throws

public String asString ()

Obtiene este valor como una cadena si es uno, de lo contrario arroja una excepción.

Devuelve

Una string.

Throws

public UUID asUUID ()

Gets this value as a UUID if it is one, otherwise throws exception.

Devuelve

un UUID.

Throws

public final boolean coercedEquals (
RealmAny other
)
public final boolean equals (
Object other
)

Dos RealmAny son .equals si y solo si su contenido es igual.

Parámetros

  • other - comparar objetivo

Devuelve

verdadero si el objetivo tiene el mismo valor

Anulaciones

equals en la clase Objeto

Obtiene el tipo interno de este objeto RealmAny.

Devuelve

the inner RealmAny.Type

Returns the Java class that represents the inner value wrapped by this RealmAny value.

Devuelve

la clase que representa el valor interno envuelto por este valor RealmAny.

public final int hashCode ()

A RealmAny 's hash code is, exactly, the hash code of its value.

Devuelve

verdadero si el objetivo tiene el mismo valor

Throws

Anulaciones

hashCode en la clase Objeto

public boolean isNull ()

Returns true if the inner value is null, false otherwise.

Devuelve

Verdadero si el valor interno es nulo, falso en caso contrario.

public static RealmAny nullValue ()

Creates a new RealmAny of a null value.

Devuelve

a new RealmAny instance of a null value.

public String toString ()

Anulaciones

toString en la clase Objeto

public static RealmAny valueOf (
Decimal128 value
)

Creates a new RealmAny with the specified value. If the value is not null the type will be RealmAny.Type.DECIMAL128 , RealmAny.Type.NULL otherwise.

Parámetros

  • value - the RealmAny value.

Devuelve

a new RealmAny of a Decimal128.

public static RealmAny valueOf (
ObjectId value
)

Creates a new RealmAny with the specified value. If the value is not null the type will be RealmAny.Type.OBJECT_ID , RealmAny.Type.NULL otherwise.

Parámetros

  • value - the RealmAny value.

Devuelve

un nuevo RealmAny de un ObjectId.

public static RealmAny valueOf (
Date value
)

Creates a new RealmAny with the specified value. If the value is not null the type will be RealmAny.Type.DATE , RealmAny.Type.NULL otherwise.

Parámetros

  • value - the RealmAny value.

Devuelve

a new RealmAny of a Date.

public static RealmAny valueOf (
byte[] value
)

Crea un nuevo RealmAny con el valor especificado. Si el valor no es nulo, el tipo será RealmAny.Type.BINARY; en caso contrario, RealmAny.Type.NULL.

Parámetros

  • value - the RealmAny value.

Devuelve

a new RealmAny of a byte[].

public static RealmAny valueOf (
String value
)

Crea un nuevo RealmAny con el valor especificado. Si el valor no es nulo, el tipo será RealmAny.Type.STRING , RealmAny.Type.NULL en caso contrario.

Parámetros

  • value - the RealmAny value.

Devuelve

a new RealmAny of a String.

public static RealmAny valueOf (
Double value
)

Creates a new RealmAny with the specified value. If the value is not null the type will be RealmAny.Type.DOUBLE , RealmAny.Type.NULL otherwise.

Parámetros

  • value - the RealmAny value.

Devuelve

a new RealmAny of a Double.

public static RealmAny valueOf (
Float value
)

Crea un nuevo RealmAny con el valor especificado. Si el valor no es nulo, el tipo será RealmAny.Type.FLOAT , si no, será RealmAny.Type.NULL .

Parámetros

  • value - the RealmAny value.

Devuelve

a new RealmAny of a Float.

public static RealmAny valueOf (
Boolean value
)

Creates a new RealmAny with the specified value. If the value is not null the type will be RealmAny.Type.BOOLEAN , RealmAny.Type.NULL otherwise.

Parámetros

  • value - the RealmAny value.

Devuelve

a new RealmAny of a Boolean.

public static RealmAny valueOf (
Long value
)

Crea un nuevo RealmAny con el valor especificado. Si el valor no es nulo, el tipo será RealmAny.Type.INTEGER , en caso contrario, RealmAny.Type.NULL.

Parámetros

  • value - the RealmAny value.

Devuelve

a new RealmAny of a Long.

public static RealmAny valueOf (
Integer value
)

Crea un nuevo RealmAny con el valor especificado. Si el valor no es nulo, el tipo será RealmAny.Type.INTEGER , en caso contrario, RealmAny.Type.NULL.

Parámetros

  • value - the RealmAny value.

Devuelve

un nuevo ReinoCualquiera de un entero.

public static RealmAny valueOf (
Short value
)

Crea un nuevo RealmAny con el valor especificado. Si el valor no es nulo, el tipo será RealmAny.Type.INTEGER , en caso contrario, RealmAny.Type.NULL.

Parámetros

  • value - the RealmAny value.

Devuelve

a new RealmAny of a Short.

public static RealmAny valueOf (
Byte value
)

Crea un nuevo RealmAny con el valor especificado. Si el valor no es nulo, el tipo será RealmAny.Type.INTEGER , en caso contrario, RealmAny.Type.NULL.

Parámetros

  • value - the RealmAny value.

Devuelve

a new RealmAny containing a Byte value.

Volver

Realm.transacción.OnSuccess

En esta página