Package io.realm
Interface RealmCollection<E>
-
- Type Parameters:
E- type ofRealmObjectstored in the collection.
- All Superinterfaces:
Collection<E>,io.realm.internal.Freezable<RealmCollection<E>>,Iterable<E>,io.realm.internal.ManageableObject
- All Known Subinterfaces:
OrderedRealmCollection<E>
- All Known Implementing Classes:
OrderedRealmCollectionSnapshot,RealmList,RealmResults,RealmSet
public interface RealmCollection<E> extends Collection<E>, io.realm.internal.ManageableObject, io.realm.internal.Freezable<RealmCollection<E>>
RealmCollectionis the root of the collection hierarchy that Realm supports. It defines operations on data collections and the behavior that they will have in all implementations ofRealmCollections.Realm collections are "live" views to the underlying data. This means that they automatically will be kept up to date. As a consequence, using methods like
Collections.unmodifiableCollection(Collection)will not prevent a collection from being modified.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description doubleaverage(String fieldName)Returns the average of a given field.booleancontains(Object object)Tests whether thisCollectioncontains the specified object.booleandeleteAllFromRealm()This deletes all objects in the collection from the underlying Realm as well as from the collection.booleanisLoaded()Checks if a collection has finished loading its data yet.booleanisManaged()Checks if the collection is managed by Realm.booleanisValid()Checks if the collection is still valid to use, i.e., theRealminstance hasn't been closed.booleanload()Blocks the collection until all data are available.Numbermax(String fieldName)Finds the maximum value of a field.DatemaxDate(String fieldName)Finds the maximum date.Numbermin(String fieldName)Finds the minimum value of a field.DateminDate(String fieldName)Finds the minimum date.Numbersum(String fieldName)Calculates the sum of a given field.RealmQuery<E>where()Returns aRealmQuery, which can be used to query for specific objects from this collection.-
Methods inherited from interface java.util.Collection
add, addAll, clear, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArray
-
-
-
-
Method Detail
-
where
RealmQuery<E> where()
Returns aRealmQuery, which can be used to query for specific objects from this collection.- Returns:
- a RealmQuery object.
- Throws:
IllegalStateException- if the Realm instance has been closed or queries are not otherwise available.- See Also:
RealmQuery
-
min
@Nullable Number min(String fieldName)
Finds the minimum value of a field.- Parameters:
fieldName- the field to look for a minimum on. Only number fields are supported.- Returns:
- if no objects exist or they all have
nullas the value for the given field,nullwill be returned. Otherwise the minimum value is returned. When determining the minimum value, objects withnullvalues are ignored. - Throws:
IllegalArgumentException- if the field is not a number type.IllegalStateException- if the Realm has been closed or called from an incorrect thread.
-
max
@Nullable Number max(String fieldName)
Finds the maximum value of a field.- Parameters:
fieldName- the field to look for a maximum on. Only number fields are supported.- Returns:
- if no objects exist or they all have
nullas the value for the given field,nullwill be returned. Otherwise the maximum value is returned. When determining the maximum value, objects withnullvalues are ignored. - Throws:
IllegalArgumentException- if the field is not a number type.IllegalStateException- if the Realm has been closed or called from an incorrect thread.
-
sum
Number sum(String fieldName)
Calculates the sum of a given field.- Parameters:
fieldName- the field to sum. Only number fields are supported.- Returns:
- the sum. If no objects exist or they all have
nullas the value for the given field,0will be returned. When computing the sum, objects withnullvalues are ignored. - Throws:
IllegalArgumentException- if the field is not a number type.IllegalStateException- if the Realm has been closed or called from an incorrect thread.
-
average
double average(String fieldName)
Returns the average of a given field.- Parameters:
fieldName- the field to calculate average on. Only number fields are supported.- 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
nullas the value for the given field,0will be returned. When computing the average, objects withnullvalues are ignored. - Throws:
IllegalArgumentException- if the field is not a number type.IllegalStateException- if the Realm has been closed or called from an incorrect thread.
-
maxDate
@Nullable Date maxDate(String fieldName)
Finds the maximum date.- Parameters:
fieldName- the field to look for the maximum date. If fieldName is not of Date type, an exception is thrown.- Returns:
- if no objects exist or they all have
nullas the value for the given date field,nullwill be returned. Otherwise the maximum date is returned. When determining the maximum date, objects withnullvalues are ignored. - Throws:
IllegalArgumentException- if fieldName is not a Date field.IllegalStateException- if the Realm has been closed or called from an incorrect thread.
-
minDate
@Nullable Date minDate(String fieldName)
Finds the minimum date.- Parameters:
fieldName- the field to look for the minimum date. If fieldName is not of Date type, an exception is thrown.- Returns:
- if no objects exist or they all have
nullas the value for the given date field,nullwill be returned. Otherwise the minimum date is returned. When determining the minimum date, objects withnullvalues are ignored. - Throws:
IllegalArgumentException- if fieldName is not a Date field.IllegalStateException- if the Realm has been closed or called from an incorrect thread.
-
deleteAllFromRealm
boolean deleteAllFromRealm()
This deletes all objects in the collection from the underlying Realm as well as from the collection.- Returns:
trueif objects was deleted,falseotherwise.- Throws:
IllegalStateException- if the corresponding Realm is closed or in an incorrect thread.IllegalStateException- if the Realm has been closed or called from an incorrect thread.
-
isLoaded
boolean isLoaded()
Checks if a collection has finished loading its data yet.- Returns:
trueif data has been loaded and is available,falseif data is still being loaded.
-
load
boolean load()
Blocks the collection until all data are available.- Returns:
trueif the data could be successfully loaded,falseotherwise.
-
isValid
boolean isValid()
Checks if the collection is still valid to use, i.e., theRealminstance hasn't been closed. It will always returntruefor an unmanaged collection.- Specified by:
isValidin interfaceio.realm.internal.ManageableObject- Returns:
trueif it is still valid to use or an unmanaged collection,falseotherwise.
-
isManaged
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
false, the collection is unmanaged. An unmanaged collection is just a normal java collection, so it will not be live updated.- Specified by:
isManagedin interfaceio.realm.internal.ManageableObject- Returns:
trueif this is a managedRealmCollection,falseotherwise.
-
contains
boolean contains(@Nullable Object object)
Tests whether thisCollectioncontains the specified object. Returnstrueif and only if at least one elementelemin thisCollectionmeets following requirement:(object==null ? elem==null : object.equals(elem)).- Specified by:
containsin interfaceCollection<E>- Parameters:
object- the object to search for.- Returns:
trueif object is an element of thisCollection,falseotherwise.- Throws:
NullPointerException- if the object to look for isnulland thisCollectiondoesn't supportnullelements.
-
-