E
- The class of objects in list.public class RealmList<E extends RealmObject>
extends java.util.AbstractList<E>
RealmObject
.
RealmList has two modes: A managed and non-managed mode. In managed mode all objects are persisted
inside a Realm, in non-managed 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 RealmObject
.
Non-managed RealmLists can be created by the user and can contain both managed and non-managed
RealmObjects. This is useful when dealing with JSON deserializers like GSON or other
frameworks that inject values into a class. Non-managed elements in this list can be added to a
Realm using the Realm.copyToRealm(Iterable)
method.
Constructor and Description |
---|
RealmList()
Create a RealmList in non-managed mode, where the elements are not controlled by a Realm.
|
RealmList(E... objects)
Create a RealmList in non-managed mode with an initial list of elements.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E object)
Adds the specified object at the end of this List.
|
void |
add(int location,
E object)
Inserts the specified object into this List at the specified location.
|
void |
clear() |
E |
first()
Find the first object.
|
E |
get(int location) |
E |
last()
Find the last object.
|
void |
move(int oldPos,
int newPos)
Moves an object from one position to another, while maintaining a fixed sized list.
|
E |
remove(int location) |
E |
set(int location,
E object)
Replaces the element at the specified location in this list with the
specified object.
|
int |
size() |
java.lang.String |
toString() |
RealmQuery<E> |
where()
Returns a RealmQuery, which can be used to query for specific objects of this class
|
addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
public RealmList()
ArrayList
and it is not possible
to query the objects in this state.
Use Realm.copyToRealm(Iterable)
to properly persist it's elements in
Realm.
public RealmList(E... objects)
ArrayList
and it is not
possible to query the objects in this state.
Use Realm.copyToRealm(Iterable)
to properly persist all non-managed elements
in Realm.objects
- Initial objects in the list.public void add(int location, E object)
Realm.copyToRealm(RealmObject)
afterwards.Realm.copyToRealm(RealmObject)
or Realm.copyToRealmOrUpdate(RealmObject)
if it has a primary key.add
in interface java.util.List<E extends RealmObject>
add
in class java.util.AbstractList<E extends RealmObject>
location
- the index at which to insert.object
- the object to add.java.lang.IndexOutOfBoundsException
- if location < 0 || location > size()
public boolean add(E object)
Realm.copyToRealm(RealmObject)
afterwards.Realm.copyToRealm(RealmObject)
or Realm.copyToRealmOrUpdate(RealmObject)
if it has a primary key.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>
object
- the object to add.public E set(int location, E object)
Realm.copyToRealm(RealmObject)
afterwards.Realm.copyToRealm(RealmObject)
or Realm.copyToRealmOrUpdate(RealmObject)
if it has a primary key.set
in interface java.util.List<E extends RealmObject>
set
in class java.util.AbstractList<E extends RealmObject>
location
- the index at which to put the specified object.object
- the object to add.java.lang.IndexOutOfBoundsException
- if location < 0 || location >= size()
public void move(int oldPos, int newPos)
oldPos
- Index of RealmObject to move.newPos
- Target position. If newPos < oldPos the object at the location will be shifted
to the right. If oldPos < newPos, indexes > oldPos will be shifted once to the
left.java.lang.IndexOutOfBoundsException
- if any position is outside [0, size()[.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>
public E remove(int location)
remove
in interface java.util.List<E extends RealmObject>
remove
in class java.util.AbstractList<E extends RealmObject>
public E get(int location)
get
in interface java.util.List<E extends RealmObject>
get
in class java.util.AbstractList<E extends RealmObject>
public E first()
null
if the list is empty.public E last()
null
if the list is empty.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 RealmQuery<E> where()
RealmQuery
public java.lang.String toString()
toString
in class java.util.AbstractCollection<E extends RealmObject>