use of io.realm.entities.AnnotationIndexTypes in project realm-java by realm.
the class RealmResultsTests method distinctAsync_withNullValues.
@Test
@RunTestInLooperThread
public void distinctAsync_withNullValues() throws Throwable {
final AtomicInteger changeListenerCalled = new AtomicInteger(2);
final Realm realm = looperThread.realm;
final long numberOfBlocks = 25;
// Must be greater than 1
final long numberOfObjects = 10;
populateForDistinct(realm, numberOfBlocks, numberOfObjects, true);
final RealmResults<AnnotationIndexTypes> distinctDate = realm.where(AnnotationIndexTypes.class).findAll().distinctAsync(AnnotationIndexTypes.FIELD_INDEX_DATE);
final RealmResults<AnnotationIndexTypes> distinctString = realm.where(AnnotationIndexTypes.class).findAll().distinctAsync(AnnotationIndexTypes.FIELD_INDEX_STRING);
assertFalse(distinctDate.isLoaded());
assertTrue(distinctDate.isValid());
assertTrue(distinctDate.isEmpty());
assertFalse(distinctString.isLoaded());
assertTrue(distinctString.isValid());
assertTrue(distinctString.isEmpty());
final Runnable endTest = new Runnable() {
@Override
public void run() {
if (changeListenerCalled.decrementAndGet() == 0) {
looperThread.testComplete();
}
}
};
looperThread.keepStrongReference.add(distinctDate);
looperThread.keepStrongReference.add(distinctString);
distinctDate.addChangeListener(new RealmChangeListener<RealmResults<AnnotationIndexTypes>>() {
@Override
public void onChange(RealmResults<AnnotationIndexTypes> object) {
assertEquals("distinctDate", 1, distinctDate.size());
endTest.run();
}
});
distinctString.addChangeListener(new RealmChangeListener<RealmResults<AnnotationIndexTypes>>() {
@Override
public void onChange(RealmResults<AnnotationIndexTypes> object) {
assertEquals("distinctString", 1, distinctString.size());
endTest.run();
}
});
}
use of io.realm.entities.AnnotationIndexTypes in project realm-java by realm.
the class RealmResultsTests method distinctAsync.
@Test
@RunTestInLooperThread
public void distinctAsync() throws Throwable {
final AtomicInteger changeListenerCalled = new AtomicInteger(4);
final Realm realm = looperThread.realm;
final long numberOfBlocks = 25;
// Must be greater than 1
final long numberOfObjects = 10;
populateForDistinct(realm, numberOfBlocks, numberOfObjects, false);
final RealmResults<AnnotationIndexTypes> distinctBool = realm.where(AnnotationIndexTypes.class).findAll().distinctAsync(AnnotationIndexTypes.FIELD_INDEX_BOOL);
final RealmResults<AnnotationIndexTypes> distinctLong = realm.where(AnnotationIndexTypes.class).findAll().distinctAsync(AnnotationIndexTypes.FIELD_INDEX_LONG);
final RealmResults<AnnotationIndexTypes> distinctDate = realm.where(AnnotationIndexTypes.class).findAll().distinctAsync(AnnotationIndexTypes.FIELD_INDEX_DATE);
final RealmResults<AnnotationIndexTypes> distinctString = realm.where(AnnotationIndexTypes.class).findAll().distinctAsync(AnnotationIndexTypes.FIELD_INDEX_STRING);
assertFalse(distinctBool.isLoaded());
assertTrue(distinctBool.isValid());
assertTrue(distinctBool.isEmpty());
assertFalse(distinctLong.isLoaded());
assertTrue(distinctLong.isValid());
assertTrue(distinctLong.isEmpty());
assertFalse(distinctDate.isLoaded());
assertTrue(distinctDate.isValid());
assertTrue(distinctDate.isEmpty());
assertFalse(distinctString.isLoaded());
assertTrue(distinctString.isValid());
assertTrue(distinctString.isEmpty());
final Runnable endTest = new Runnable() {
@Override
public void run() {
if (changeListenerCalled.decrementAndGet() == 0) {
looperThread.testComplete();
}
}
};
looperThread.keepStrongReference.add(distinctBool);
looperThread.keepStrongReference.add(distinctLong);
looperThread.keepStrongReference.add(distinctDate);
looperThread.keepStrongReference.add(distinctString);
distinctBool.addChangeListener(new RealmChangeListener<RealmResults<AnnotationIndexTypes>>() {
@Override
public void onChange(RealmResults<AnnotationIndexTypes> object) {
assertEquals(2, distinctBool.size());
endTest.run();
}
});
distinctLong.addChangeListener(new RealmChangeListener<RealmResults<AnnotationIndexTypes>>() {
@Override
public void onChange(RealmResults<AnnotationIndexTypes> object) {
assertEquals(numberOfBlocks, distinctLong.size());
endTest.run();
}
});
distinctDate.addChangeListener(new RealmChangeListener<RealmResults<AnnotationIndexTypes>>() {
@Override
public void onChange(RealmResults<AnnotationIndexTypes> object) {
assertEquals(numberOfBlocks, distinctDate.size());
endTest.run();
}
});
distinctString.addChangeListener(new RealmChangeListener<RealmResults<AnnotationIndexTypes>>() {
@Override
public void onChange(RealmResults<AnnotationIndexTypes> object) {
assertEquals(numberOfBlocks, distinctString.size());
endTest.run();
}
});
}
Aggregations