use of io.realm.internal.util.Pair in project realm-java by realm.
the class SyncSession method removeProgressListener.
/**
* Removes a progress listener. If the listener wasn't registered, this method will do nothing.
*
* @param listener listener to remove.
*/
public synchronized void removeProgressListener(ProgressListener listener) {
// noinspection ConstantConditions
if (listener == null) {
return;
}
// If an exception is thrown somewhere in here, we will most likely leave the various
// maps in an inconsistent manner. Not much we can do about it.
Long token = progressListenerToOsTokenMap.remove(listener);
if (token != null) {
Iterator<Map.Entry<Long, Pair<ProgressListener, Progress>>> it = listenerIdToProgressListenerMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Long, Pair<ProgressListener, Progress>> entry = it.next();
if (entry.getValue().first.equals(listener)) {
it.remove();
break;
}
}
nativeRemoveProgressListener(appNativePointer, configuration.getPath(), token);
}
}
use of io.realm.internal.util.Pair in project realm-java by realm.
the class RxJavaTests method realmResults_readableAcrossThreads.
@Test
@RunTestInLooperThread
public void realmResults_readableAcrossThreads() {
final long TEST_SIZE = 10;
Realm realm = looperThread.getRealm();
realm.beginTransaction();
for (int i = 0; i < TEST_SIZE; i++) {
realm.createObject(AllTypes.class).setColumnLong(1);
}
realm.commitTransaction();
AtomicLong startingThread = new AtomicLong(Thread.currentThread().getId());
AtomicLong subscriberThread = new AtomicLong();
subscription = realm.where(AllTypes.class).sort(AllTypes.FIELD_LONG).findAllAsync().asFlowable().doOnSubscribe((r) -> {
subscriberThread.set(Thread.currentThread().getId());
}).subscribeOn(Schedulers.io()).filter(results -> {
assertNotEquals(startingThread.get(), subscriberThread.get());
return results.isLoaded();
}).map(results -> new Pair<>(results.size(), new Pair<>(results, results.first()))).observeOn(Schedulers.computation()).subscribe(pair -> {
assertNotEquals(startingThread.get(), Thread.currentThread().getId());
assertNotEquals(subscriberThread.get(), Thread.currentThread().getId());
assertEquals(TEST_SIZE, pair.first.intValue());
assertEquals(TEST_SIZE, pair.second.first.size());
assertEquals(pair.second.second.getColumnLong(), pair.second.first.first().getColumnLong());
disposeSuccessfulTest(realm);
});
}
use of io.realm.internal.util.Pair in project realm-java by realm.
the class OsMap method getKeyRealmAnyPair.
public <K> Pair<K, NativeRealmAny> getKeyRealmAnyPair(int position) {
// entry from OsMap is an array: entry[0] is key and entry[1] is a RealmAny value
Object[] entry = nativeGetEntryForRealmAny(nativePtr, position);
String key = (String) entry[0];
NativeRealmAny nativeRealmAny = new NativeRealmAny((long) entry[1]);
// noinspection unchecked
return new Pair<>((K) key, nativeRealmAny);
}
use of io.realm.internal.util.Pair in project realm-java by realm.
the class RealmTests method populateTestRealmAndCompactOnLaunch.
private Pair<Long, Long> populateTestRealmAndCompactOnLaunch(CompactOnLaunchCallback compactOnLaunch, int sizeInMB) {
final String REALM_NAME = "test.realm";
RealmConfiguration realmConfig = configFactory.createConfiguration(REALM_NAME);
Realm realm = Realm.getInstance(realmConfig);
populateTestRealmForCompact(realm, sizeInMB);
realm.beginTransaction();
realm.deleteAll();
realm.commitTransaction();
realm.close();
long before = new File(realmConfig.getPath()).length();
if (compactOnLaunch != null) {
realmConfig = configFactory.createConfigurationBuilder().name(REALM_NAME).compactOnLaunch(compactOnLaunch).build();
} else {
realmConfig = configFactory.createConfigurationBuilder().name(REALM_NAME).compactOnLaunch().build();
}
realm = Realm.getInstance(realmConfig);
realm.close();
long after = new File(realmConfig.getPath()).length();
return new Pair(before, after);
}
Aggregations