public final class DynamicRealmObject extends RealmObject
Constructor and Description |
---|
DynamicRealmObject(RealmModel obj)
Creates a dynamic Realm object based on an existing object.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
<E> E |
get(String fieldName)
Returns the value for the given field.
|
byte[] |
getBlob(String fieldName)
Returns the
byte[] value for a given field. |
boolean |
getBoolean(String fieldName)
Returns the
boolean value for a given field. |
byte |
getByte(String fieldName)
Returns the
byte value for a given field. |
Date |
getDate(String fieldName)
Returns the
Date value for a given field. |
double |
getDouble(String fieldName)
Returns the
double value for a given field. |
String[] |
getFieldNames()
Returns the list of field names on this object.
|
RealmFieldType |
getFieldType(String fieldName)
Returns the type used by the underlying storage engine to represent this field.
|
float |
getFloat(String fieldName)
Returns the
float value for a given field. |
int |
getInt(String fieldName)
Returns the
int value for a given field. |
RealmList<DynamicRealmObject> |
getList(String fieldName)
Returns the
RealmList of objects being linked to from this field. |
long |
getLong(String fieldName)
Returns the
long value for a given field. |
DynamicRealmObject |
getObject(String fieldName)
Returns the object being linked to from this field.
|
short |
getShort(String fieldName)
Returns the
short value for a given field. |
String |
getString(String fieldName)
Returns the
String value for a given field. |
String |
getType()
Returns the type of object.
|
boolean |
hasField(String fieldName)
Checks whether an object has the given field or not.
|
int |
hashCode()
Returns a hash code value for the
DynamicRealmObject object. |
boolean |
isNull(String fieldName)
Checks if the value of a given field is
null . |
ProxyState |
realmGet$proxyState() |
void |
set(String fieldName,
Object value)
Sets the value for the given field.
|
void |
setBlob(String fieldName,
byte[] value)
Sets the binary value of the given field.
|
void |
setBoolean(String fieldName,
boolean value)
Sets the
boolean value of the given field. |
void |
setByte(String fieldName,
byte value)
Sets the
byte value of the given field. |
void |
setDate(String fieldName,
Date value)
Sets the
Date value of the given field. |
void |
setDouble(String fieldName,
double value)
Sets the
double value of the given field. |
void |
setFloat(String fieldName,
float value)
Sets the
float value of the given field. |
void |
setInt(String fieldName,
int value)
Sets the
int value of the given field. |
void |
setList(String fieldName,
RealmList<DynamicRealmObject> list)
Sets the reference to a
RealmList on the given field. |
void |
setLong(String fieldName,
long value)
Sets the
long value of the given field. |
void |
setNull(String fieldName)
Sets the value to
null for the given field. |
void |
setObject(String fieldName,
DynamicRealmObject value)
Sets a reference to another object on the given field.
|
void |
setShort(String fieldName,
short value)
Sets the
short value of the given field. |
void |
setString(String fieldName,
String value)
Sets the
String value of the given field. |
String |
toString() |
addChangeListener, addChangeListener, asObservable, asObservable, deleteFromRealm, deleteFromRealm, isLoaded, isLoaded, isManaged, isManaged, isValid, isValid, load, load, removeChangeListener, removeChangeListener, removeChangeListeners, removeChangeListeners
public DynamicRealmObject(RealmModel obj)
obj
- the Realm object to convert to a dynamic object. Only objects managed by Realm
can be used.IllegalArgumentException
- if object isn't managed by Realm or is a DynamicRealmObject
already.public <E> E get(String fieldName)
fieldName
- name of the field.ClassCastException
- if the field doesn't contain a field of the defined return type.public boolean getBoolean(String fieldName)
boolean
value for a given field.
If the field is nullable, use isNull(String)
to check for null
instead of using
this method.
fieldName
- the name of the field.IllegalArgumentException
- if field name doesn't exist or it doesn't contain booleans.RealmException
- if the return value would be null
.public int getInt(String fieldName)
int
value for a given field.
If the field is nullable, use isNull(String)
to check for null
instead of using
this method.
fieldName
- the name of the field.Integer.MAX_VALUE
will wrap.IllegalArgumentException
- if field name doesn't exist or it doesn't contain integers.RealmException
- if the return value would be null
.public short getShort(String fieldName)
short
value for a given field.
If the field is nullable, use isNull(String)
to check for null
instead of using
this method.
fieldName
- the name of the field.Short.MAX_VALUE
will wrap.IllegalArgumentException
- if field name doesn't exist or it doesn't contain integers.RealmException
- if the return value would be null
.public long getLong(String fieldName)
long
value for a given field.
If the field is nullable, use isNull(String)
to check for null
instead of using
this method.
fieldName
- the name of the field.Long.MAX_VALUE
will wrap.IllegalArgumentException
- if field name doesn't exist or it doesn't contain integers.RealmException
- if the return value would be null
.public byte getByte(String fieldName)
byte
value for a given field.
If the field is nullable, use isNull(String)
to check for null
instead of using
this method.
fieldName
- the name of the field.IllegalArgumentException
- if field name doesn't exist or it doesn't contain integers.RealmException
- if the return value would be null
.public float getFloat(String fieldName)
float
value for a given field.
If the field is nullable, use isNull(String)
to check for null
instead of using
this method.
fieldName
- the name of the field.IllegalArgumentException
- if field name doesn't exist or it doesn't contain floats.RealmException
- if the return value would be null
.public double getDouble(String fieldName)
double
value for a given field.
If the field is nullable, use isNull(String)
to check for null
instead of using
this method.
fieldName
- the name of the field.IllegalArgumentException
- if field name doesn't exist or it doesn't contain doubles.RealmException
- if the return value would be null
.public byte[] getBlob(String fieldName)
byte[]
value for a given field.fieldName
- the name of the field.IllegalArgumentException
- if field name doesn't exist or it doesn't contain binary data.public String getString(String fieldName)
String
value for a given field.fieldName
- the name of the field.IllegalArgumentException
- if field name doesn't exist or it doesn't contain Strings.public Date getDate(String fieldName)
Date
value for a given field.fieldName
- the name of the field.IllegalArgumentException
- if field name doesn't exist or it doesn't contain Dates.public DynamicRealmObject getObject(String fieldName)
fieldName
- the name of the field.DynamicRealmObject
representation of the linked object or null
if no object is linked.IllegalArgumentException
- if field name doesn't exist or it doesn't contain links to other objects.public RealmList<DynamicRealmObject> getList(String fieldName)
RealmList
of objects being linked to from this field.fieldName
- the name of the field.RealmList
data for this field.IllegalArgumentException
- if field name doesn't exist or it doesn't contain a list of links.public boolean isNull(String fieldName)
null
.fieldName
- the name of the field.true
if field value is null, false
otherwise.IllegalArgumentException
- if field name doesn't exist.public boolean hasField(String fieldName)
fieldName
- field name to check.true
if the object has a field with the given name, false
otherwise.public String[] getFieldNames()
public void set(String fieldName, Object value)
String
to their appropriate type. For example "10"
will be converted to 10
if the field type is int
.
Using the typed setters will be faster than using this method.
IllegalArgumentException
- if field name doesn't exist or if the input value cannot be converted
to the appropriate input type.NumberFormatException
- if a String based number cannot be converted properly.RealmException
- if the field is a PrimaryKey
field.public void setBoolean(String fieldName, boolean value)
boolean
value of the given field.fieldName
- field name to update.value
- value to insert.IllegalArgumentException
- if field name doesn't exist or field isn't a boolean field.public void setShort(String fieldName, short value)
short
value of the given field.fieldName
- field name.value
- value to insert.IllegalArgumentException
- if field name doesn't exist or field isn't an integer field.RealmException
- if the field is a PrimaryKey
field.public void setInt(String fieldName, int value)
int
value of the given field.fieldName
- field name to update.value
- value to insert.IllegalArgumentException
- if field name doesn't exist or field isn't an integer field.RealmException
- if the field is a PrimaryKey
field.public void setLong(String fieldName, long value)
long
value of the given field.fieldName
- field name.value
- value to insert.IllegalArgumentException
- if field name doesn't exist or field isn't an integer field.RealmException
- if the field is a PrimaryKey
field.public void setByte(String fieldName, byte value)
byte
value of the given field.fieldName
- field name.value
- value to insert.IllegalArgumentException
- if field name doesn't exist or field isn't an integer field.RealmException
- if the field is a PrimaryKey
field.public void setFloat(String fieldName, float value)
float
value of the given field.fieldName
- field name.value
- value to insert.IllegalArgumentException
- if field name doesn't exist or field isn't a float field.public void setDouble(String fieldName, double value)
double
value of the given field.fieldName
- field name.value
- value to insert.IllegalArgumentException
- if field name doesn't exist or field isn't a double field.public void setString(String fieldName, String value)
String
value of the given field.fieldName
- field name.value
- value to insert.IllegalArgumentException
- if field name doesn't exist or field isn't a String field.RealmException
- if the field is a PrimaryKey
field.public void setBlob(String fieldName, byte[] value)
fieldName
- field name.value
- value to insert.IllegalArgumentException
- if field name doesn't exist or field isn't a binary field.public void setDate(String fieldName, Date value)
Date
value of the given field.fieldName
- field name.value
- value to insert.IllegalArgumentException
- if field name doesn't exist or field isn't a Date field.public void setObject(String fieldName, DynamicRealmObject value)
fieldName
- field name.value
- object to link to.IllegalArgumentException
- if field name doesn't exist, it doesn't link to other Realm objects, the type
of DynamicRealmObject doesn't match or it belongs to a different Realm.public void setList(String fieldName, RealmList<DynamicRealmObject> list)
RealmList
on the given field.fieldName
- field name.list
- list of references.IllegalArgumentException
- if field name doesn't exist, it is not a list field, the type
of the object represented by the DynamicRealmObject doesn't match or any element in the list belongs to a
different Realm.public void setNull(String fieldName)
null
for the given field.fieldName
- field name.IllegalArgumentException
- if field name doesn't exist, or the field isn't nullable.RealmException
- if the field is a PrimaryKey
field.public String getType()
RealmObject
.public RealmFieldType getFieldType(String fieldName)
public int hashCode()
DynamicRealmObject
object.
By the general contract of Object.hashCode()
, any two objects for which equals(java.lang.Object)
returns true
must return the same hash code value.
Note that a RealmObject
is a live object, and it might be updated by changes from
other threads. This means that a hash code value of the object is not stable, and the value
should be neither used as a key in HashMap nor saved in HashSet.
hashCode
in class Object
equals(java.lang.Object)
public ProxyState realmGet$proxyState()