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

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

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

Observable.distinct介绍

[英]Returns an Observable that emits all items emitted by the source Observable that are distinct.

Scheduler: distinct does not operate by default on a particular Scheduler.
[中]返回一个Observable,该Observable发出源Observable发出的所有不同项。
调度程序:默认情况下,distinct不会在特定调度程序上运行。

代码示例

代码示例来源:origin: jaydenxiao2016/AndroidFire

@Override
  public Observable<List<VideoData>> getVideosListData(final String type, int startPage) {
    return Api.getDefault(HostType.NETEASE_NEWS_VIDEO).getVideoList(Api.getCacheControl(),type,startPage)
        .flatMap(new Func1<Map<String, List<VideoData>>, Observable<VideoData>>() {
          @Override
          public Observable<VideoData> call(Map<String, List<VideoData>> map) {
            return Observable.from(map.get(type));
          }
        })
        //转化时间
        .map(new Func1<VideoData, VideoData>() {
          @Override
          public VideoData call(VideoData videoData) {
            String ptime = TimeUtil.formatDate(videoData.getPtime());
            videoData.setPtime(ptime);
            return videoData;
          }
        })
        .distinct()//去重
        .toSortedList(new Func2<VideoData, VideoData, Integer>() {
          @Override
          public Integer call(VideoData videoData, VideoData videoData2) {
            return videoData2.getPtime().compareTo(videoData.getPtime());
          }
        })
        //声明线程调度
        .compose(RxSchedulers.<List<VideoData>>io_main());
  }
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

.distinct()//去重
.toSortedList(new Func2<NewsSummary, NewsSummary, Integer>() {
  @Override

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

.distinct( queueMessage -> {

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

.distinct( new EdgeDistinctKey() )

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

.distinct( new EdgeDistinctKey() )

代码示例来源:origin: BaronZ88/MinimalistWeather

.distinct(weather -> weather.getWeatherLive().getTime())
.takeUntil(weather -> !refreshNow && System.currentTimeMillis() - weather.getWeatherLive().getTime() <= 15 * 60 * 1000);

代码示例来源:origin: kaku2015/ColorfulNews

.distinct()
.toSortedList(new Func2<NewsSummary, NewsSummary, Integer>() {
  @Override

代码示例来源:origin: ribot/ribot-app-android

/**
 * Retrieve list of venues. Behaviour:
 * 1. Return cached venues (empty list if none is cached)
 * 2. Return API venues (if different to cached ones)
 * 3. Save new venues from API in cache
 * 5. If an error happens and cache is not empty, returns venues from cache.
 */
public Observable<List<Venue>> getVenues() {
  String auth = RibotService.Util.buildAuthorization(mPreferencesHelper.getAccessToken());
  return mRibotService.getVenues(auth)
      .doOnNext(new Action1<List<Venue>>() {
        @Override
        public void call(List<Venue> venues) {
          mPreferencesHelper.putVenues(venues);
        }
      })
      .onErrorResumeNext(new Func1<Throwable, Observable<? extends List<Venue>>>() {
        @Override
        public Observable<? extends List<Venue>> call(Throwable throwable) {
          return getVenuesRecoveryObservable(throwable);
        }
      })
      .startWith(mPreferencesHelper.getVenuesAsObservable())
      .distinct();
}

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

@Override
 public void run() {
  Observable.just(1, 1, 2, 2, 3, 4, 4, 1, 1, 5)
       .distinct()
       .subscribe(new Action1<Integer>() {
        @Override
        public void call(Integer integer) {
         log(integer);
        }
       });
 }
});

代码示例来源:origin: henrymorgen/android-advanced-light

private void distinct() {
  Observable.just(1, 2, 2, 3, 4, 1).distinct().subscribe(new Action1<Integer>() {
    @Override
    public void call(Integer integer) {
      Log.d(TAG, "distinct:" + integer);
    }
  });
}

代码示例来源:origin: hawkular/hawkular-metrics

private List<String> loadTenantIds() {
  Iterable<String> tenantIds = dataAccess.findAllTenantIds()
      .map(row -> row.getString(0))
      .distinct()
      .toBlocking()
      .toIterable();
  return ImmutableList.copyOf(tenantIds);
}

代码示例来源:origin: org.hawkular.metrics/hawkular-metrics-core-service

private List<String> loadTenantIds() {
  Iterable<String> tenantIds = dataAccess.findAllTenantIds()
      .map(row -> row.getString(0))
      .distinct()
      .toBlocking()
      .toIterable();
  return ImmutableList.copyOf(tenantIds);
}

代码示例来源:origin: hawkular/hawkular-metrics

@Override
public Observable<Tenant> getTenants() {
  return dataAccess.findAllTenantIds()
      .map(row -> row.getString(0))
      .distinct()
      .flatMap(id ->
              dataAccess.findTenant(id)
                  .map(Functions::getTenant)
                  .switchIfEmpty(Observable.just(new Tenant(id)))
      );
}

代码示例来源:origin: org.hawkular.metrics/hawkular-metrics-core-service

@Override
public Observable<MetricId<?>> findAllMetricIdentifiers() {
  return dataAccess.findAllMetricIdentifiersInData()
      .compose(new MetricIdentifierFromFullDataRowTransformer(defaultTTL))
      .distinct();
}

代码示例来源:origin: hawkular/hawkular-metrics

@Override
public Observable<MetricId<?>> findAllMetricIdentifiers() {
  return dataAccess.findAllMetricIdentifiersInData()
      .compose(new MetricIdentifierFromFullDataRowTransformer(defaultTTL))
      .distinct();
}

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

@Test
public void sample_499() throws Exception {
  Observable<Status> tweets = Observable.empty();
  Observable<Long> distinctUserIds = tweets
      .map(status -> status.getUser().getId())
      .distinct();
}

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

@Test
public void sample_490() throws Exception {
  final Observable<Integer> randomInts = randomInts();
  Observable<Integer> uniqueRandomInts = randomInts
      .distinct()
      .take(10);
}

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

Observable<Item> observeNewItems() {
  return Observable
      .interval(1, TimeUnit.SECONDS)
      .flatMapIterable(x -> query())
      .distinct();
}

代码示例来源:origin: meltwater/rxrabbit

private Observable.Transformer<Message,List<Integer>> getIdsTransformer(int nrMessages){
  return input -> input.
      compose(new TakeAndAckTransformer(nrMessages, TIMEOUT/10*9))
      .doOnNext(message -> log.debugWithParams("Got message", "id",message.basicProperties.getMessageId()))
      .map(RxRabbitTests::msgToInteger)
      .distinct()
      .toList();
}

代码示例来源:origin: meltwater/rxrabbit

private Observable.Transformer<Message, List<Integer>> getIdsTransformer(int nrMessages) {
  return input -> input.
      compose(new TakeAndAckTransformer(nrMessages, TIMEOUT / 10 * 9))
      .doOnNext(message -> log.debugWithParams("Got message", "id", message.basicProperties.getMessageId()))
      .map(RxRabbitTests::msgToInteger)
      .distinct()
      .toList();
}

相关文章

Observable类方法