Class RealmList
On this page
- io.realm
- Constructors
- Field Summary
- Method Summary
- Inherited Methods
- Field Detail
baseRealm
- Constructor Detail
- Method Detail
- add
- addChangeListener
- asChangesetObservable
- asFlowable
- average
- clear
- contains
- createSnapshot
- deleteAllFromRealm
- deleteFirstFromRealm
- deleteFromRealm
- deleteLastFromRealm
- first
- freeze
- get
- getRealm
- isFrozen
- isLoaded
- isManaged
- isValid
- iterator
- last
- listIterator
- load
- max
- maxDate
- min
- minDate
- move
- remove
- removeAll
- removeAllChangeListeners
- removeChangeListener
- set
- size
- sort
- sum
- toString
- where
io.realm
Implemented interfaces:
RealmList is used to model one-to-many relationships in a io.realm.RealmObject . RealmList has two modes: A managed and unmanaged mode. In managed mode all objects are persisted inside a Realm, in unmanaged mode it works as a normal ArrayList.
Only Realm can create managed RealmLists. Managed RealmLists will automatically update the content whenever the underlying Realm is updated, and can only be accessed using the getter of a io.realm.RealmObject .
Unmanaged RealmLists can be created by the user and can contain both managed and unmanaged RealmObjects. This is useful when dealing with JSON deserializers like GSON or other frameworks that inject values into a class. Unmanaged elements in this list can be added to a Realm using the Realm.copyToRealm(Iterable, ImportFlag...) method.
RealmList can contain more elements than Integer.MAX_VALUE
. In that case, you can access only first Integer.MAX_VALUE
elements in it.
Constructors
Field Summary
Modifier and Type | Field and Description |
---|---|
public final BaseRealm | The BaseRealm instance in which this list resides. Warning: This field is only exposed for internal usage, and should not be used. |
Method Summary
Modifier and Type | Method and Description |
---|---|
public boolean | Adds the specified object at the end of this List. |
public void | Inserts the specified object into this List at the specified location. |
public void | Adds a change listener to this RealmList . |
public void | Adds a change listener to this RealmList . |
public <any> | Returns an Rx Observable that monitors changes to this RealmList. |
public <any> | asFlowable () Returns an Rx Flowable that monitors changes to this RealmList. |
public double | |
public void | clear () Removes all elements from this list, leaving it empty. |
public boolean | |
Creates a snapshot from this OrderedRealmCollection . | |
public boolean | This deletes all objects in the collection from the underlying Realm as well as from the collection. |
public boolean | Deletes the first object from the Realm. |
public void | Deletes the object at the given index from the Realm. |
public boolean | Deletes the last object from the Realm. |
public E | Gets the first object from the collection. |
public E | first () Gets the first object from the collection. |
public RealmList | freeze () |
public E | Returns the element at the specified location in this list. |
public Realm | |
public boolean | isFrozen () |
public boolean | isLoaded () Checks if a collection has finished loading its data yet. |
public boolean | isManaged () Checks if the collection is managed by Realm. |
public boolean | isValid () Checks if the collection is still valid to use, i.e., the io.realm.Realm instance hasn't been closed. |
public Iterator | iterator () |
public E | Gets the last object from the collection. |
public E | last () Gets the last object from the collection. |
public ListIterator | |
public ListIterator | listIterator () |
public boolean | load () Blocks the collection until all data are available. |
public Number | |
public Date | |
public Number | |
public Date | |
public void | Moves an object from one position to another, while maintaining a fixed sized list. |
public boolean | |
public E | Removes the object at the specified location from this list. |
public boolean | Removes all occurrences in this |
public void | Removes all user-defined change listeners. |
public void | Removes the specified change listener. |
public void | ) Removes the specified change listener. |
public E | Replaces the element at the specified location in this list with the specified object. |
public int | size () Returns the number of elements in this |
public RealmResults | Sorts a collection based on the provided fields and sort orders. |
public RealmResults | |
public RealmResults | |
public RealmResults | |
public Number | |
public String | toString () |
public RealmQuery | where () Returns a RealmQuery, which can be used to query for specific objects of this class. |
Inherited Methods
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
Field Detail
baseRealm
The BaseRealm instance in which this list resides.
Warning: This field is only exposed for internal usage, and should not be used.
Constructor Detail
public RealmList () |
---|
Creates a RealmList in unmanaged mode, where the elements are not controlled by a Realm. This effectively makes the RealmList function as a java.util.ArrayList and it is not possible to query the objects in this state. Use io.realm.Realm.copyToRealm(Iterable, ImportFlag...) to properly persist its elements in Realm. |
Creates a RealmList in unmanaged mode with an initial list of elements. A RealmList in unmanaged mode function as a java.util.ArrayList and it is not possible to query the objects in this state. Use io.realm.Realm.copyToRealm(Iterable, ImportFlag...) to properly persist all unmanaged elements in Realm. Parameters
|
Method Detail
add
Adds the specified object at the end of this List.
Parameters
Returns always Throws
Overrides
|
Inserts the specified object into this List at the specified location. The object is inserted before any previous element at the specified location. If the location is equal to the size of this List, the object is added at the end.
Parameters
Throws
Overrides
|
addChangeListener
Adds a change listener to this RealmList . Registering a change listener will not prevent the underlying RealmList from being garbage collected. If the RealmList 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.
Parameters
Throws
|
public void addChangeListener ( ) | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Adds a change listener to this RealmList . Registering a change listener will not prevent the underlying RealmList from being garbage collected. If the RealmList 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.
Parameters
Throws
|
asChangesetObservable
public <any> asChangesetObservable () | |||||
---|---|---|---|---|---|
Returns an Rx Observable that monitors changes to this RealmList. It will emit the current RealmList when subscribed. For each update to the RealmList a pair consisting of the RealmList and the OrderedCollectionChangeSet will be sent. The changeset will be RealmList will continually be emitted as the RealmList is updated - Items emitted from Realm Observables are frozen (See freeze() . This means that they are immutable and can be read on any thread. 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:
Returns RxJava Observable that only calls Throws
|
asFlowable
public <any> asFlowable () | ||||||||
---|---|---|---|---|---|---|---|---|
Returns an Rx Flowable that monitors changes to this RealmList. It will emit the current RealmList when subscribed to. RealmList will continually be emitted as the RealmList is updated - Items emitted from Realm Flowables are frozen (See freeze() . This means that they are immutable and can be read on any thread. Realm Flowables always emit items from the thread holding the live RealmList. This means that if you need to do further processing, it is recommend to observe the values on a computation scheduler:
If you would like the
Returns RxJava Observable that only calls Throws
|
average
Returns the average of a given field. Returns the average for the given field amongst objects in query results. This will be of type double for all types of number fields. If no objects exist or they all have |
clear
public void clear () |
---|
Removes all elements from this list, leaving it empty. This method doesn't remove the objects from the Realm. Throws
Overrides
|
contains
Returns If the list is not attached to a Realm, the default List.contains(Object) implementation will occur. Parameters
Returns
Overrides
|
createSnapshot
public OrderedRealmCollectionSnapshot createSnapshot () |
---|
deleteAllFromRealm
public boolean deleteAllFromRealm () |
---|
This deletes all objects in the collection from the underlying Realm as well as from the collection. Returns
|
deleteFirstFromRealm
public boolean deleteFirstFromRealm () |
---|
Deletes the first object from the Realm. This also removes it from this collection. Returns
|
deleteFromRealm
Deletes the object at the given index from the Realm. This also removes it from the collection. |
deleteLastFromRealm
public boolean deleteLastFromRealm () |
---|
Deletes the last object from the Realm. This also removes it from this collection. Returns
|
first
Gets the first object from the collection. If the collection is empty, the provided default will be used instead. Returns the first object or the provided default. |
public E first () |
---|
Gets the first object from the collection. Returns the first object. |
freeze
get
Returns the element at the specified location in this list. Parameters
Returns the element at the specified index. Throws
Overrides
|
getRealm
Returns the Realm instance to which this collection belongs. Calling Realm.close() on the returned instance is discouraged as it is the same as calling it on the original Realm instance which may cause the Realm to fully close invalidating the list. Returns Realm instance this collection belongs to or Throws
|
isFrozen
public boolean isFrozen () |
---|
isLoaded
public boolean isLoaded () |
---|
Checks if a collection has finished loading its data yet. Returns
|
isManaged
public boolean isManaged () |
---|
Checks if the collection is managed by Realm. A managed collection is just a wrapper around the data in the underlying Realm file. On Looper threads, a managed collection will be live-updated so it always points to the latest data. Managed collections are thread confined so that they cannot be accessed from other threads than the one that created them.If this method returns Returns
|
isValid
public boolean isValid () |
---|
Checks if the collection is still valid to use, i.e., the io.realm.Realm instance hasn't been closed. It will always return Returns
|
iterator
Overrides
|
last
Gets the last object from the collection. If the collection is empty, the provided default will be used instead. Returns the last object or the provided default. |
public E last () |
---|
Gets the last object from the collection. Returns the last object. |
listIterator
Overrides
|
public ListIterator listIterator () |
---|
Overrides
|
load
public boolean load () |
---|
Blocks the collection until all data are available. Returns
|
max
maxDate
min
minDate
move
Moves an object from one position to another, while maintaining a fixed sized list. RealmObjects will be shifted so no Parameters
Throws
|
remove
Removes one instance of the specified object from this Parameters
Returns
Throws
Overrides
|
Removes the object at the specified location from this list. Parameters
Returns the removed object. Throws
Overrides
|
removeAll
Removes all occurrences in this This implementation iterates over the Parameters
Returns
Throws
Overrides
|
removeAllChangeListeners
public void removeAllChangeListeners () |
---|
Removes all user-defined change listeners. Throws
|
removeChangeListener
Removes the specified change listener. Parameters
Throws
|
public void removeChangeListener ( ) |
---|
Removes the specified change listener. Parameters
Throws
|
set
Replaces the element at the specified location in this list with the specified object.
Parameters
Returns the previous element at the index. Throws
Overrides
|
size
public int size () |
---|
Returns the number of elements in this Returns the number of elements in this Throws
Overrides
|
sort
Sorts a collection based on the provided fields and sort orders. Returns a new sorted RealmResults will be created and returned. The original collection stays unchanged. |
Sorts a collection based on the provided fields and sort orders. Returns a new sorted RealmResults will be created and returned. The original collection stays unchanged. |
Sorts a collection based on the provided field and sort order. Returns a new sorted RealmResults will be created and returned. The original collection stays unchanged. |
Sorts a collection based on the provided field in ascending order. Returns a new sorted RealmResults will be created and returned. The original collection stays unchanged. |
sum
toString
Overrides
|
where
public RealmQuery where () |
---|
Returns a RealmQuery, which can be used to query for specific objects of this class. Returns a RealmQuery object. Throws
|