本文整理汇总了Java中io.reactivex.functions.Predicate类的典型用法代码示例。如果您正苦于以下问题:Java Predicate类的具体用法?Java Predicate怎么用?Java Predicate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Predicate类属于io.reactivex.functions包,在下文中一共展示了Predicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isRequired_IMULocationWifiAndBluetooth_areRequired
import io.reactivex.functions.Predicate; //导入依赖的package包/类
@Test
public void isRequired_IMULocationWifiAndBluetooth_areRequired() throws Exception {
HashSet<SensorType> sensorTypes = new HashSet<>();
sensorTypes.addAll(Arrays.asList(SensorType.imuValues()));
sensorTypes.add(SensorType.LOCATION);
sensorTypes.addAll(Arrays.asList(SensorType.wifiValues()));
sensorTypes.addAll(Arrays.asList(SensorType.bluetoothValues()));
Long count = Observable.fromIterable(sensorTypes)
.map(new Function<SensorType, Boolean>() {
@Override
public Boolean apply(SensorType sensorType) throws Exception {
return basicSensorRequirementChecker.isRequired(sensorType);
}
}).filter(new Predicate<Boolean>() {
@Override
public boolean test(Boolean required) throws Exception {
return required;
}
}).count()
.blockingGet();
assertThat(count.intValue(), equalTo(sensorTypes.size()));
}
示例2: single_ReturnsSharedSingle
import io.reactivex.functions.Predicate; //导入依赖的package包/类
@Test
public void single_ReturnsSharedSingle() {
// Given
final DiffRequest spyRequest = spy(mDiffRequest);
// When
final Single<RxDiffResult> single = DiffRequestManager.single(spyRequest);
// Then
for (int i = 0; i < 5; ++i) {
final TestObserver<RxDiffResult> testObserver = new TestObserver<>();
single.subscribe(testObserver);
testObserver.awaitTerminalEvent(500, TimeUnit.MILLISECONDS);
testObserver.assertValue(new Predicate<RxDiffResult>() {
@Override
public boolean test(@NonNull RxDiffResult rxDiffResult) throws Exception {
return rxDiffResult.getTag().equals(TEST_TAG);
}
});
}
then(spyRequest).should(times(1)).isDetectingMoves();
}
示例3: testGetFile
import io.reactivex.functions.Predicate; //导入依赖的package包/类
@SuppressWarnings("Duplicates") @Test public void testGetFile() {
mockSuccessfulResultForTask(mockFileDownloadTask, mockFileDownloadTaskSnapshot);
when(mockStorageReference.getFile(mockFile)).thenReturn(mockFileDownloadTask);
when(mockFileDownloadTaskSnapshot.getBytesTransferred()).thenReturn(1000L);
when(mockFileDownloadTaskSnapshot.getTotalByteCount()).thenReturn(1000L);
TestObserver<FileDownloadTask.TaskSnapshot> obs = TestObserver.create();
RxFirebaseStorage.getFile(mockStorageReference, mockFile).subscribe(obs);
verifyAddOnCompleteListenerForTask(mockFileDownloadTask);
callOnComplete(mockFileDownloadTask);
obs.dispose();
callOnComplete(mockFileDownloadTask);
obs.assertNoErrors();
obs.assertComplete();
obs.assertValue(new Predicate<FileDownloadTask.TaskSnapshot>() {
@Override public boolean test(FileDownloadTask.TaskSnapshot taskSnapshot) throws Exception {
return taskSnapshot.getBytesTransferred() == taskSnapshot.getTotalByteCount()
&& taskSnapshot.getTotalByteCount() == 1000;
}
});
}
示例4: testGetMetadata
import io.reactivex.functions.Predicate; //导入依赖的package包/类
@Test public void testGetMetadata() {
mockSuccessfulResultForTask(mockStorageMetadataTask, mockStorageMetadata);
when(mockStorageReference.getMetadata()).thenReturn(mockStorageMetadataTask);
when(mockStorageMetadata.getName()).thenReturn("Test");
TestObserver<StorageMetadata> obs = TestObserver.create();
RxFirebaseStorage.getMetadata(mockStorageReference).subscribe(obs);
verifyAddOnCompleteListenerForTask(mockStorageMetadataTask);
callOnComplete(mockStorageMetadataTask);
obs.dispose();
callOnComplete(mockStorageMetadataTask);
obs.assertNoErrors();
obs.assertComplete();
obs.assertValue(new Predicate<StorageMetadata>() {
@Override public boolean test(StorageMetadata storageMetadata) throws Exception {
return "Test".equals(storageMetadata.getName());
}
});
}
示例5: onGet
import io.reactivex.functions.Predicate; //导入依赖的package包/类
public <CLASS> Observable<Getter<CLASS>> onGet(final Class<CLASS> theClass) {
return onEvent(AskedEvent.class)//I wait for an event (askevent) of CLASS
.filter(new Predicate<AskedEvent>() {
@Override
public boolean test(@NonNull AskedEvent askedEvent) throws Exception {
return askedEvent.askedObject.equals(theClass);
}
})
.map(new Function<AskedEvent, Getter<CLASS>>() {
@Override
public Getter<CLASS> apply(@NonNull AskedEvent o) throws Exception {
return new Getter<CLASS>() {
//then I send to the listener a Getter (interface)
//when the getter is notified, the value is sent to the first subscrier
//who called the method `get`
@Override
public void get(CLASS value) {
post(value); //the value is published on the bus
}
};
}
});
}
示例6: execute
import io.reactivex.functions.Predicate; //导入依赖的package包/类
@Override
public <T> Observable<CacheResult<T>> execute(ApiCache apiCache, String cacheKey, Observable<T> source, Type type) {
Observable<CacheResult<T>> remote = loadRemote(apiCache, cacheKey, source);
remote.onErrorReturn(new Function<Throwable, CacheResult<T>>() {
@Override
public CacheResult<T> apply(Throwable throwable) throws Exception {
return null;
}
});
Observable<CacheResult<T>> cache = loadCache(apiCache, cacheKey, type);
return Observable.concatDelayError(Arrays.asList(remote,cache)).filter(new Predicate<CacheResult<T>>() {
@Override
public boolean test(CacheResult<T> tCacheResult) throws Exception {
return tCacheResult != null && tCacheResult.getCacheData() != null;
}
}).firstElement().toObservable();
}
示例7: testUpdateMetadata
import io.reactivex.functions.Predicate; //导入依赖的package包/类
@Test public void testUpdateMetadata() {
when(mockStorageMetadata.getName()).thenReturn("metadata");
mockSuccessfulResultForTask(mockStorageMetadataTask, mockStorageMetadata);
TestObserver<StorageMetadata> obs = TestObserver.create();
when(mockStorageReference.updateMetadata(mockStorageMetadata)).thenReturn(
mockStorageMetadataTask);
RxFirebaseStorage.updateMetadata(mockStorageReference, mockStorageMetadata).subscribe(obs);
verifyAddOnCompleteListenerForTask(mockStorageMetadataTask);
callOnComplete(mockStorageMetadataTask);
obs.dispose();
callOnComplete(mockStorageMetadataTask);
obs.assertNoErrors();
obs.assertComplete();
obs.assertValue(new Predicate<StorageMetadata>() {
@Override public boolean test(StorageMetadata metadata) throws Exception {
return "metadata".equals(metadata.getName());
}
});
}
示例8: filterWithIfThenMapNullableContainer
import io.reactivex.functions.Predicate; //导入依赖的package包/类
private Observable<Integer> filterWithIfThenMapNullableContainer(
Observable<NullableContainer<String>> observable) {
return observable
.filter(
new Predicate<NullableContainer<String>>() {
@Override
public boolean test(NullableContainer<String> container) throws Exception {
if (container.get() != null) {
return true;
} else {
return false;
}
}
})
.map(
new Function<NullableContainer<String>, Integer>() {
@Override
public Integer apply(NullableContainer<String> c) throws Exception {
return c.get().length();
}
});
}
示例9: execute
import io.reactivex.functions.Predicate; //导入依赖的package包/类
@Override
public <T> Observable<CacheResult<T>> execute(ApiCache apiCache, String cacheKey, Observable<T> source, Type type) {
Observable<CacheResult<T>> cache = loadCache(apiCache, cacheKey, type);
cache.onErrorReturn(new Function<Throwable, CacheResult<T>>() {
@Override
public CacheResult<T> apply(Throwable throwable) throws Exception {
return null;
}
});
Observable<CacheResult<T>> remote = loadRemote(apiCache, cacheKey, source);
return Observable.concat(remote, cache).filter(new Predicate<CacheResult<T>>() {
@Override
public boolean test(CacheResult<T> tCacheResult) throws Exception {
return tCacheResult != null && tCacheResult.getCacheData() != null;
}
}).firstElement().toObservable();
}
示例10: filterThenDistinctUntilChanged
import io.reactivex.functions.Predicate; //导入依赖的package包/类
private Observable<NullableContainer<String>> filterThenDistinctUntilChanged(
Observable<NullableContainer<String>> observable) {
return observable
.filter(
new Predicate<NullableContainer<String>>() {
@Override
public boolean test(NullableContainer<String> container) throws Exception {
return container.get() != null;
}
})
.distinctUntilChanged(
new BiPredicate<NullableContainer<String>, NullableContainer<String>>() {
@Override
public boolean test(NullableContainer<String> nc1, NullableContainer<String> nc2) {
return nc1.get().length() == nc2.get().length()
&& nc1.get().contains(nc2.get())
&& nc2.get().contains(nc1.get());
}
});
}
示例11: testMaybe
import io.reactivex.functions.Predicate; //导入依赖的package包/类
private Maybe<Integer> testMaybe(Maybe<NullableContainer<String>> maybe) {
return maybe
.filter(
new Predicate<NullableContainer<String>>() {
@Override
public boolean test(NullableContainer<String> container) throws Exception {
return container.get() != null;
}
})
.map(
new Function<NullableContainer<String>, Integer>() {
@Override
public Integer apply(NullableContainer<String> c) throws Exception {
return c.get().length();
}
});
}
示例12: testSingle
import io.reactivex.functions.Predicate; //导入依赖的package包/类
private Maybe<Integer> testSingle(Single<NullableContainer<String>> single) {
return single
.filter(
new Predicate<NullableContainer<String>>() {
@Override
public boolean test(NullableContainer<String> container) throws Exception {
return container.get() != null;
}
})
.map(
new Function<NullableContainer<String>, Integer>() {
@Override
public Integer apply(NullableContainer<String> c) throws Exception {
return c.get().length();
}
});
}
示例13: filterWithIfThenMapNullableContainerNullableOnSomeBranch
import io.reactivex.functions.Predicate; //导入依赖的package包/类
private Observable<Integer> filterWithIfThenMapNullableContainerNullableOnSomeBranch(
Observable<NullableContainer<String>> observable) {
return observable
.filter(
new Predicate<NullableContainer<String>>() {
@Override
public boolean test(NullableContainer<String> container) throws Exception {
if (container.get() != null) {
return true;
} else {
return perhaps();
}
}
})
.map(
new Function<NullableContainer<String>, Integer>() {
@Override
public Integer apply(NullableContainer<String> c) throws Exception {
// BUG: Diagnostic contains: dereferenced expression
return c.get().length();
}
});
}
示例14: filterWithIfThenMapNullableContainerNullableOnSomeBranchAnyOrder
import io.reactivex.functions.Predicate; //导入依赖的package包/类
private Observable<Integer> filterWithIfThenMapNullableContainerNullableOnSomeBranchAnyOrder(
Observable<NullableContainer<String>> observable) {
return observable
.filter(
new Predicate<NullableContainer<String>>() {
@Override
public boolean test(NullableContainer<String> container) throws Exception {
if (container.get() == null) {
return perhaps();
} else {
return true;
}
}
})
.map(
new Function<NullableContainer<String>, Integer>() {
@Override
public Integer apply(NullableContainer<String> c1) throws Exception {
// BUG: Diagnostic contains: dereferenced expression
return c1.get().length();
}
});
}
示例15: setRecyclerViewScrollListener
import io.reactivex.functions.Predicate; //导入依赖的package包/类
private void setRecyclerViewScrollListener() {
LoadMoreDelegate delegate = new LoadMoreDelegate(new LoadMoreDelegate.LoadMoreSubject() {
@Override
public boolean isLoading() {
return mIsLoading;
}
@Override
public void onLoadMore() {
Observable<IssueDataBean> observable = mDailyApi.loadMoreDailyItem(mNextPageUrl);
mIsLoading = true;
observable
.filter(new Predicate<IssueDataBean>() {
@Override
public boolean test(@NonNull IssueDataBean issueDataBean) throws Exception {
return issueDataBean != null;
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(mObserver);
}
});
delegate.attach(mRecyclerView);
}