下面列出了io.reactivex.Observable#filter ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
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);
}
}));
}
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);
}
}));
}
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);
}
}));
}
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));
}