當前位置: 首頁>>代碼示例>>Java>>正文


Java Predicate類代碼示例

本文整理匯總了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()));
}
 
開發者ID:ubikgs,項目名稱:AndroidSensors,代碼行數:25,代碼來源:BasicSensorRequirementCheckerTest.java

示例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();
}
 
開發者ID:storix,項目名稱:RxDiffUtil,代碼行數:26,代碼來源:DiffRequestManagerRoboTest.java

示例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;
    }
  });
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:27,代碼來源:RxFirebaseStorageTest.java

示例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());
    }
  });
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:25,代碼來源:RxFirebaseStorageTest.java

示例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
                        }
                    };
                }
            });
}
 
開發者ID:datalink747,項目名稱:Rx_java2_soussidev,代碼行數:24,代碼來源:RxBus_java.java

示例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();
}
 
開發者ID:xiaoyaoyou1212,項目名稱:XSnow,代碼行數:18,代碼來源:FirstRemoteStrategy.java

示例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());
    }
  });
}
 
開發者ID:b3er,項目名稱:RxFirebase2,代碼行數:26,代碼來源:RxFirebaseStorageTest.java

示例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();
            }
          });
}
 
開發者ID:uber,項目名稱:NullAway,代碼行數:23,代碼來源:NullAwayRxSupportNegativeCases.java

示例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();
}
 
開發者ID:qiaodashaoye,項目名稱:SuperHttp,代碼行數:18,代碼來源:FirstRemoteStrategy.java

示例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());
            }
          });
}
 
開發者ID:uber,項目名稱:NullAway,代碼行數:21,代碼來源:NullAwayRxSupportNegativeCases.java

示例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();
            }
          });
}
 
開發者ID:uber,項目名稱:NullAway,代碼行數:18,代碼來源:NullAwayRxSupportNegativeCases.java

示例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();
            }
          });
}
 
開發者ID:uber,項目名稱:NullAway,代碼行數:18,代碼來源:NullAwayRxSupportNegativeCases.java

示例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();
            }
          });
}
 
開發者ID:uber,項目名稱:NullAway,代碼行數:24,代碼來源:NullAwayRxSupportPositiveCases.java

示例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();
            }
          });
}
 
開發者ID:uber,項目名稱:NullAway,代碼行數:24,代碼來源:NullAwayRxSupportPositiveCases.java

示例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);
}
 
開發者ID:KnowledgeBegger,項目名稱:MyEyepetizer,代碼行數:26,代碼來源:DailyActivity.java


注:本文中的io.reactivex.functions.Predicate類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。