rx.Observable.count()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(216)

本文整理了Java中rx.Observable.count()方法的一些代码示例,展示了Observable.count()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.count()方法的具体详情如下:
包路径:rx.Observable
类名称:Observable
方法名:count

Observable.count介绍

[英]Returns an Observable that emits the count of the total number of items emitted by the source Observable.

Backpressure Support: This operator does not support backpressure because by intent it will receive all values and reduce them to a single onNext. Scheduler: count does not operate by default on a particular Scheduler.
[中]返回一个Observable,该Observable发出源Observable发出的项目总数的计数。
背压支持:此运算符不支持背压,因为它会接收所有值,并将它们减少到单个onNext。计划程序:默认情况下,计数不会在特定计划程序上运行。

代码示例

代码示例来源:origin: apache/usergrid

  1. .doOnNext( RX_LOG ).take( 1 ).count()
  2. .doOnNext( count -> {

代码示例来源:origin: apache/usergrid

  1. @Test
  2. @Category(ExperimentalTest.class )
  3. public void testConnectableObserver() throws InterruptedException {
  4. final int count = 10;
  5. final CountDownLatch latch = new CountDownLatch( count );
  6. final ConnectableObservable<Integer> connectedObservable = Observable.range( 0, count ).publish();
  7. //connect to our latch, which should run on it's own subscription
  8. //start our latch running
  9. connectedObservable.doOnNext( integer -> latch.countDown() ).subscribeOn( Schedulers.io() ).subscribe();
  10. final Observable<Integer> countObservable = connectedObservable.subscribeOn( Schedulers.io() ).count();
  11. //start the sequence
  12. connectedObservable.connect();
  13. final boolean completed = latch.await( 5, TimeUnit.SECONDS );
  14. assertTrue( "publish1 behaves as expected", completed );
  15. final int returnedCount = countObservable.toBlocking().last();
  16. assertEquals( "Counts the same", count, returnedCount );
  17. }

代码示例来源:origin: apache/usergrid

  1. } ).count().defaultIfEmpty( 0 ).toBlocking().last();

代码示例来源:origin: apache/usergrid

  1. @Test
  2. public void testGetEdgesToTarget() {
  3. final GraphManager gm = emf.createEdgeManager( scope );
  4. Id sourceId1 = new SimpleId( "source1" );
  5. Id sourceId2 = new SimpleId( "source2" );
  6. Id targetId1 = new SimpleId( "target" );
  7. Edge testTargetEdge = createEdge( sourceId1, "test", targetId1, System.currentTimeMillis() );
  8. gm.writeEdge( testTargetEdge ).toBlocking().singleOrDefault( null );
  9. Edge testTarget2Edge = createEdge( sourceId2, "edgeType1", targetId1, System.currentTimeMillis() );
  10. gm.writeEdge( testTarget2Edge ).toBlocking().singleOrDefault( null );
  11. Edge test2TargetEdge = createEdge( sourceId1, "edgeType1", targetId1, System.currentTimeMillis() );
  12. gm.writeEdge( test2TargetEdge ).toBlocking().singleOrDefault( null );
  13. Edge test3TargetEdge = createEdge( sourceId1, "edgeType2", targetId1, System.currentTimeMillis() );
  14. gm.writeEdge( test3TargetEdge ).toBlocking().singleOrDefault( null );
  15. int count = gm.getEdgeTypesToTarget( new SimpleSearchEdgeType(targetId1, null, null) )
  16. .count().toBlocking().last();
  17. assertEquals( 3, count );
  18. count = gm.getEdgeTypesToTarget( new SimpleSearchEdgeType(targetId1, "edgeType", null) )
  19. .count().toBlocking().last();
  20. assertEquals( 2, count );
  21. }

代码示例来源:origin: apache/usergrid

  1. /**
  2. * Simple test case that tests a single edge and removing the node. The other target node should be removed as well
  3. * since it has no other targets
  4. */
  5. @Test
  6. public void testNoDeletionMarked() {
  7. GraphManager em = emf.createEdgeManager( scope );
  8. Edge edge = createEdge( "source", "test", "target" );
  9. //write the edge
  10. Edge last = em.writeEdge( edge ).toBlocking().last();
  11. assertEquals( edge, last );
  12. Id sourceNode = edge.getSourceNode();
  13. UUID eventTime = UUIDGenerator.newTimeUUID();
  14. int count = deleteListener.receive( scope, sourceNode, eventTime ).count().toBlocking().last();
  15. assertEquals( "Mark was not set, no delete should be executed", 0, count );
  16. }

代码示例来源:origin: apache/usergrid

  1. Observable<Id> ids =
  2. this.app.getApplicationService().deleteAllEntities(appScope, 5);
  3. int count = ids.count().toBlocking().last();
  4. Assert.assertEquals(count, 5);
  5. ids =
  6. this.app.getApplicationService().deleteAllEntities(appScope, 5);
  7. count = ids.count().toBlocking().last();
  8. Assert.assertEquals(count, 5);
  9. this.app.waitForQueueDrainAndRefreshIndex();

代码示例来源:origin: apache/usergrid

  1. @Test
  2. public void testSingleConnection() {
  3. final ApplicationScope applicationScope = new ApplicationScopeImpl( new SimpleId( "application" ) );
  4. final GraphManager gm = graphManagerFactory.createEdgeManager( applicationScope );
  5. //now write a single connection
  6. final Id source = new SimpleId( "source" );
  7. //add to a collection
  8. final String collectionName = "testCollection";
  9. final Edge collectionEdge = CpNamingUtils.createCollectionEdge( applicationScope.getApplication(), collectionName, source );
  10. final Edge writtenCollection = gm.writeEdge( collectionEdge ).toBlocking().last();
  11. assertNotNull("Collection edge written", writtenCollection);
  12. final Id target = new SimpleId( "target" );
  13. final String connectionType = "testConnection";
  14. final Edge connectionEdge = CpNamingUtils.createConnectionEdge( source, connectionType, target );
  15. final Edge writtenConnection = gm.writeEdge( connectionEdge ).toBlocking().last();
  16. //now run the cleanup
  17. final int count =
  18. connectionService.deDupeConnections( Observable.just( applicationScope ) ).count().toBlocking().last();
  19. assertEquals( "No edges deleted", 0, count );
  20. //now ensure we can read the edge.
  21. final SearchByEdge simpleSearchByEdge =
  22. new SimpleSearchByEdge( source, connectionEdge.getType(), target, Long.MAX_VALUE,
  23. SearchByEdgeType.Order.DESCENDING, Optional.absent() );
  24. final List<MarkedEdge> edges = gm.loadEdgeVersions( simpleSearchByEdge ).toList().toBlocking().last();
  25. assertEquals( 1, edges.size() );
  26. assertEquals( writtenConnection, edges.get( 0 ) );
  27. }

代码示例来源:origin: apache/usergrid

  1. int appCount = Observable.from( applicationInfoResults.getEntities() ).filter(
  2. entity -> !entity.getName().startsWith( "org." ) ).doOnNext(
  3. entity -> logger.info("counting entity {}", entity) ).count().toBlocking().last();
  4. assertEquals( appIds.size() ,appCount );

代码示例来源:origin: apache/usergrid

  1. int count = deleteListener.receive( scope, toDelete, UUIDGenerator.newTimeUUID() ).count().toBlocking().last();

代码示例来源:origin: apache/usergrid

  1. int count = deleteListener.receive( scope, targetNode, UUIDGenerator.newTimeUUID() ).count().toBlocking().last();

代码示例来源:origin: apache/usergrid

  1. int count = deleteListener.receive( scope, sourceNode, deleteEventTimestamp ).count().toBlocking().last();

代码示例来源:origin: apache/usergrid

  1. .flatMap(mesage ->indexProducer.put(mesage)).count().toBlocking().last();

代码示例来源:origin: davidmoten/rxjava-jdbc

  1. public Observable<Integer> count() {
  2. return get(Util.toOne()).count();
  3. }

代码示例来源:origin: davidmoten/rxjava-jdbc

  1. public Observable<Integer> count() {
  2. return get(Util.toOne()).count();
  3. }

代码示例来源:origin: apache/usergrid

  1. .flatMap(mesage -> indexProducer.put(mesage)).count().toBlocking().last();

代码示例来源:origin: apache/usergrid

  1. .flatMap(mesage -> indexProducer.put(mesage)).count().toBlocking().last();

代码示例来源:origin: au.gov.amsa.risky/formats

  1. public static void main(String[] args) throws InterruptedException {
  2. String output = System.getProperty("output", "target/output");
  3. // output = "/media/an/binary-fixes-2012/temp";
  4. long sampleSeconds = Long.parseLong(System.getProperty("sampleSeconds", "0"));
  5. BinaryFixes
  6. .sortBinaryFixFilesByTime(new File(output), sampleSeconds, Schedulers.immediate())
  7. .count().toBlocking().single();
  8. }

代码示例来源:origin: au.gov.amsa.risky/formats

  1. public static void main(String[] args) {
  2. final File input = new File(System.getProperty("input"));
  3. final File output = new File(System.getProperty("output"));
  4. Pattern pattern = Pattern.compile(System.getProperty("pattern"));
  5. Action2<List<HasFix>, File> fixesWriter = (fixes, file) -> {
  6. BinaryFixesWriter.writeFixes(fixes, file, false, true, BinaryFixesFormat.WITHOUT_MMSI);
  7. };
  8. Func1<String, String> renamer = name -> name + ".zip";
  9. Formats.transform(input, output, pattern, Transformers.<HasFix> identity(), fixesWriter,
  10. renamer).count().toBlocking().single();
  11. }

代码示例来源:origin: au.gov.amsa.risky/formats

  1. public static void sort(File output) {
  2. // now sort the data in each output file by time and rewrite
  3. List<File> files = Files.find(output, Pattern.compile(".*\\.fix"));
  4. Observable.from(files)
  5. //
  6. .buffer(Math.max(1, files.size() / Runtime.getRuntime().availableProcessors()))
  7. //
  8. .flatMap(list -> Observable.from(list)
  9. //
  10. .doOnNext(file -> sortFixFile(file)).subscribeOn(Schedulers.computation()))
  11. .count().toBlocking().single();
  12. }

代码示例来源:origin: nurkiewicz/rxjava-book-examples

  1. @Test
  2. public void sample_216() throws Exception {
  3. Observable<KeyEvent> keyEvents = empty();
  4. Observable<Observable<KeyEvent>> windows = keyEvents.window(1, SECONDS);
  5. Observable<Integer> eventPerSecond = windows
  6. .flatMap(eventsInSecond -> eventsInSecond.count());
  7. }

相关文章

Observable类方法