Docs Menu
Docs Home
/ /
Atlas Device SDKs
/ / /

Class RealmSet

On this page

  • io.realm
  • Constructors
  • Method Summary
  • Inherited Methods
  • Constructor Detail
  • Method Detail
  • add
  • addAll
  • addChangeListener
  • average
  • clear
  • contains
  • containsAll
  • deleteAllFromRealm
  • freeze
  • getValueClass
  • getValueClassName
  • isEmpty
  • isFrozen
  • isLoaded
  • isManaged
  • isValid
  • iterator
  • load
  • max
  • maxDate
  • min
  • minDate
  • remove
  • removeAll
  • removeAllChangeListeners
  • removeChangeListener
  • retainAll
  • size
  • sum
  • toArray
  • where
java.lang.Object
io.realm.RealmSet

Implemented interfaces:

RealmSet is a collection that contains no duplicate elements.Similarly to RealmList s, a RealmSet can operate in managed and unmanaged modes. In managed mode a RealmSet persists all its contents inside a Realm whereas in unmanaged mode it functions like a HashSet .

Managed RealmSets can only be created by Realm and will automatically update their content whenever the underlying Realm is updated. Managed RealmSet can only be accessed using the getter that points to a RealmSet field of a RealmObject .

Unmanaged elements in this set can be added to a Realm using the Realm.copyToRealm(Iterable, ImportFlag...) method.

Warning: the following methods are not supported for classes containing set fields yet:

Constructor and Description

Instantiates a RealmSet in unmanaged mode.

Instantiates a RealmSet in unmanaged mode with another collection.

BaseRealm baseRealm,
OsSet osSet,
)

Instantiates a RealmSet in managed mode.

BaseRealm baseRealm,
OsSet osSet,
String className
)

Instantiates a RealmSet in managed mode.

Modifier and Type
Method and Description
public boolean
add (
E e
)
public boolean
public void

Adds a change listener to this RealmSet .

public void
public double
String fieldName
)

Returns the average of a given field.

public void
public boolean

Tests whether this Collection contains the specified object.

public boolean
public boolean

This deletes all objects in the collection from the underlying Realm as well as from the collection.

public RealmSet
public Class
public String
public boolean
public boolean
public boolean

Checks if a collection has finished loading its data yet.

public boolean

Checks if the collection is managed by Realm.

public boolean

Checks if the collection is still valid to use, i.e., the io.realm.Realm instance hasn't been closed.

public Iterator
public boolean
load ()

Blocks the collection until all data are available.

public Number
max (
String fieldName
)

Finds the maximum value of a field.

public Date
String fieldName
)

Finds the maximum date.

public Number
min (
String fieldName
)

Finds the minimum value of a field.

public Date
String fieldName
)

Finds the minimum date.

public boolean
public boolean
public void

Removes all user-defined change listeners.

public void

Removes the specified change listener.

public void

Removes the specified change listener.

public boolean
public int
size ()

public Number
sum (
String fieldName
)

Calculates the sum of a given field.

public T
toArray <T >(
T[] a
)
public Object
public RealmQuery

Returns a RealmQuery, which can be used to query for specific objects of this class.

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

public RealmSet ()

Instantiates a RealmSet in unmanaged mode.
public RealmSet (
)

Instantiates a RealmSet in unmanaged mode with another collection.

Parameters

  • collection - the collection with which the set will be initially populated.

public RealmSet (
BaseRealm baseRealm,
OsSet osSet,
)

Instantiates a RealmSet in managed mode. This constructor is used internally by Realm.

Parameters

  • baseRealm -

  • osSet -

  • valueClass -

public RealmSet (
BaseRealm baseRealm,
OsSet osSet,
String className
)

Instantiates a RealmSet in managed mode. This constructor is used internally by a Dynamic Realm.

Parameters

  • baseRealm -

  • osSet -

  • className -

public boolean add (
E e
)

Adds a change listener to this RealmSet .

Registering a change listener will not prevent the underlying RealmSet from being garbage collected. If the RealmSet 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.

public class MyActivity extends Activity {
private RealmSet<Dog> dogs; // Strong reference to keep listeners alive
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dogs = realm.where(Person.class).findFirst().getDogs();
dogs.addChangeListener(new SetChangeListener<Dog>() {
@Override
public void onChange(RealmSet<Dog> set, SetChangeSet changeSet) {
// React to change
}
});
}
}

Parameters

  • listener - the listener to be notified.

Throws

Adds a change listener to this RealmSet .

Registering a change listener will not prevent the underlying RealmSet from being garbage collected. If the RealmSet 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.

public class MyActivity extends Activity {
private RealmSet<Dog> dogs; // Strong reference to keep listeners alive
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dogs = realm.where(Person.class).findFirst().getDogs();
dogs.addChangeListener(new RealmChangeListener<RealmSet<Dog>>() {
@Override
public void onChange(RealmSet<Dog> map) {
// React to change
}
});
}
}

Parameters

  • listener - the listener to be notified.

Throws

public double average (
String fieldName
)

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 null as the value for the given field, 0 will be returned. When computing the average, objects with null values are ignored.

public void clear ()

public boolean contains (
)

Tests whether this Collection contains the specified object. Returns true if and only if at least one element elem in this Collection meets following requirement: (object==null ? elem==null : object.equals(elem)) .

Returns

true if object is an element of this Collection , false otherwise.

public boolean deleteAllFromRealm ()

This deletes all objects in the collection from the underlying Realm as well as from the collection.

Returns

true if objects was deleted, false otherwise.

public RealmSet freeze ()

public boolean isEmpty ()

public boolean isFrozen ()

public boolean isLoaded ()

Checks if a collection has finished loading its data yet.

Returns

true if data has been loaded and is available, false if data is still being loaded.

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 false , the collection is unmanaged. An unmanaged collection is just a normal java collection, so it will not be live updated.

Returns

true if this is a managed RealmCollection , false otherwise.

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 true for an unmanaged collection.

Returns

true if it is still valid to use or an unmanaged collection, false otherwise.

public Iterator iterator ()

public boolean load ()

Blocks the collection until all data are available.

Returns

true if the data could be successfully loaded, false otherwise.

public Number max (
String fieldName
)

Finds the maximum value of a field.

Returns

if no objects exist or they all have null as the value for the given field, null will be returned. Otherwise the maximum value is returned. When determining the maximum value, objects with null values are ignored.

public Date maxDate (
String fieldName
)

Finds the maximum date.

Returns

if no objects exist or they all have null as the value for the given date field, null will be returned. Otherwise the maximum date is returned. When determining the maximum date, objects with null values are ignored.

public Number min (
String fieldName
)

Finds the minimum value of a field.

Returns

if no objects exist or they all have null as the value for the given field, null will be returned. Otherwise the minimum value is returned. When determining the minimum value, objects with null values are ignored.

public Date minDate (
String fieldName
)

Finds the minimum date.

Returns

if no objects exist or they all have null as the value for the given date field, null will be returned. Otherwise the minimum date is returned. When determining the minimum date, objects with null values are ignored.

public boolean remove (
)

Removes all user-defined change listeners.

Throws

Tip

See also:

Removes the specified change listener.

Parameters

  • listener - the change listener to be removed.

Throws

Removes the specified change listener.

Parameters

  • listener - the change listener to be removed.

Throws

public int size ()

public Number sum (
String fieldName
)

Calculates the sum of a given field.

Returns

the sum. If no objects exist or they all have null as the value for the given field, 0 will be returned. When computing the sum, objects with null values are ignored.

public T toArray <T >(
T[] a
)
public Object toArray ()

public RealmQuery where ()

Returns a RealmQuery, which can be used to query for specific objects of this class.

Returns

a RealmQuery object.

Throws

Tip

See also:

Back

RealmSchema