Java Code Examples for io.reactivex.Observable#filter()

The following examples show how to use io.reactivex.Observable#filter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FirstCacheTimeoutStrategy.java    From RxCache with Apache License 2.0 6 votes vote down vote up
@Override
public <T> Observable<CacheResult<T>> execute(RxCache rxCache, String key, Observable<T> source, Type type) {
    Observable<CacheResult<T>> cache = RxCacheHelper.loadCache(rxCache, key, type, true);
    cache = cache.filter(new Predicate<CacheResult<T>>() {
        @Override
        public boolean test(CacheResult<T> tCacheResult) throws Exception {
            return System.currentTimeMillis() - tCacheResult.getTimestamp() <= milliSecond;
        }
    });
    Observable<CacheResult<T>> remote;
    if (isSync) {
        remote = RxCacheHelper.loadRemoteSync(rxCache, key, source, CacheTarget.MemoryAndDisk, false);
    } else {
        remote = RxCacheHelper.loadRemote(rxCache, key, source, CacheTarget.MemoryAndDisk, false);
    }
    return cache.switchIfEmpty(remote);
}
 
Example 2
Source File: LifeCycleHelper.java    From Tangram-Android with MIT License 5 votes vote down vote up
public static <T, E> LifecycleTransformer<T> bindUntilEvent(Observable<E> lifecycle, final E event) {
    return new LifecycleTransformer<>(lifecycle.filter(new Predicate<E>() {
        @Override
        public boolean test(E e) throws Exception {
            return e.equals(event);
        }
    }));
}
 
Example 3
Source File: LifeCycleHelper.java    From Tangram-Android with MIT License 5 votes vote down vote up
public static <T, E> LifecycleTransformer<T> bindUntilEvent(Observable<E> lifecycle, final E event) {
    return new LifecycleTransformer<>(lifecycle.filter(new io.reactivex.functions.Predicate<E>() {
        @Override
        public boolean test(E e) throws Exception {
            return e.equals(event);
        }
    }));
}
 
Example 4
Source File: LifeCycleHelper.java    From Tangram-Android with MIT License 5 votes vote down vote up
public static <T, E> LifecycleTransformer<T> bindUntilEvent(Observable<E> lifecycle, final E event) {
    return new LifecycleTransformer<>(lifecycle.filter(new io.reactivex.functions.Predicate<E>() {
        @Override
        public boolean test(E e) throws Exception {
            return e.equals(event);
        }
    }));
}
 
Example 5
Source File: AccountRxStore.java    From moVirt with Apache License 2.0 5 votes vote down vote up
public Observable<MovirtAccount> onRemovedAccountObservable(MovirtAccount account) {
    Observable<MovirtAccount> result = REMOVED_ACCOUNT;

    if (!environmentStore.hasEnvironment(account)) {
        result = result.startWith(account);
    }

    return result.filter(acc -> acc.equals(account));
}