本文整理汇总了Java中rx.observables.GroupedObservable类的典型用法代码示例。如果您正苦于以下问题:Java GroupedObservable类的具体用法?Java GroupedObservable怎么用?Java GroupedObservable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GroupedObservable类属于rx.observables包,在下文中一共展示了GroupedObservable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: groupByInMemory_MoreDetail
import rx.observables.GroupedObservable; //导入依赖的package包/类
/**
* This does the same thing as {@link #groupByInMemory_MoreDetail()} but with pedagogical details
* @throws Exception
*/
@Test
public void groupByInMemory_MoreDetail() throws Exception {
int requestPageSize = 3;
FeedOptions options = new FeedOptions();
options.setPageSize(requestPageSize);
Observable<Document> documentsObservable = asyncClient
.queryDocuments(createdCollection.getSelfLink(),
new SqlQuerySpec("SELECT * FROM root r WHERE [email protected]_id",
new SqlParameterCollection(new SqlParameter("@site_id", "ABC"))),
options)
.flatMap(page -> Observable.from(page.getResults()));
final LocalDateTime now = LocalDateTime.now();
Observable<GroupedObservable<Integer, Document>> groupedByPayerIdObservable = documentsObservable
.filter(doc -> Math.abs(now.getSecond() - doc.getInt("created_time")) <= 90)
.groupBy(doc -> doc.getInt("payer_id"));
Observable<List<Document>> docsGroupedAsList = groupedByPayerIdObservable.flatMap(grouped -> {
Observable<List<Document>> list = grouped.toList();
return list;
});
List<List<Document>> resultsGroupedAsLists = docsGroupedAsList.toList().toBlocking().single();
for(List<Document> resultsForEachPayer : resultsGroupedAsLists) {
System.out.println("documents with payer_id : " + resultsForEachPayer.get(0).getInt("payer_id") + " are " + resultsForEachPayer);
}
}
示例2: splitByAddressAndForEach
import rx.observables.GroupedObservable; //导入依赖的package包/类
private Observable.Transformer<RxBleInternalScanResult, RxBleInternalScanResult> splitByAddressAndForEach(
final Observable.Transformer<RxBleInternalScanResult, RxBleInternalScanResult> compose
) {
return new Observable.Transformer<RxBleInternalScanResult, RxBleInternalScanResult>() {
@Override
public Observable<RxBleInternalScanResult> call(Observable<RxBleInternalScanResult> observable) {
return observable
.groupBy(new Func1<RxBleInternalScanResult, String>() {
@Override
public String call(RxBleInternalScanResult rxBleInternalScanResult) {
return rxBleInternalScanResult.getBluetoothDevice().getAddress();
}
})
.flatMap(new Func1<GroupedObservable<String, RxBleInternalScanResult>, Observable<RxBleInternalScanResult>>() {
@Override
public Observable<RxBleInternalScanResult> call(
GroupedObservable<String, RxBleInternalScanResult> groupedObservable) {
return groupedObservable.compose(compose);
}
});
}
};
}
示例3: main
import rx.observables.GroupedObservable; //导入依赖的package包/类
public static void main(String[] args) {
System.setProperty("rx.ring-buffer.size", "16");
List<AppInfo> list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 3; j++) {
AppInfo ai = new AppInfo();
ai.name = i + " - " + j;
ai.date = LocalDate.of(2016, 3, i + 1);
list.add(ai);
}
}
Observable<GroupedObservable<String, AppInfo>> o = Observable.from(list)
.groupBy(v -> v.date.format(DateTimeFormatter.ofPattern("MM/yyyy")));
Observable.concat(o)
.subscribe(System.out::println);
}
示例4: GroupBySubscriber
import rx.observables.GroupedObservable; //导入依赖的package包/类
public GroupBySubscriber(
Function<? super T, ? extends K> keySelector,
Function<? super T, ? extends R> elementSelector,
Subscriber<? super GroupedObservable<K, R>> child) {
super();
this.keySelector = keySelector;
this.elementSelector = elementSelector;
this.child = child;
child.add(Subscriptions.create(new Action0() {
@Override
public void call() {
if (WIP_FOR_UNSUBSCRIBE_UPDATER.decrementAndGet(self) == 0) {
self.unsubscribe();
}
}
}));
}
示例5: testTakeUnsubscribesOnGroupBy
import rx.observables.GroupedObservable; //导入依赖的package包/类
@Test
public void testTakeUnsubscribesOnGroupBy() {
Observable.merge(
EventStream.getEventStream("HTTP-ClusterA", 50),
EventStream.getEventStream("HTTP-ClusterB", 20))
// group by type (2 clusters)
.groupBy(new Function<Event, String>() {
@Override
public String call(Event event) {
return event.type;
}
}).take(1)
.toBlocking().forEach(new Action1<GroupedObservable<String, Event>>() {
@Override
public void call(GroupedObservable<String, Event> g) {
System.out.println(g);
}
});
System.out.println("**** finished");
}
示例6: toMap
import rx.observables.GroupedObservable; //导入依赖的package包/类
private static <K, V> Map<K, Collection<V>> toMap(Observable<GroupedObservable<K, V>> observable) {
final ConcurrentHashMap<K, Collection<V>> result = new ConcurrentHashMap<K, Collection<V>>();
observable.toBlocking().forEach(new Action1<GroupedObservable<K, V>>() {
@Override
public void call(final GroupedObservable<K, V> o) {
result.put(o.getKey(), new ConcurrentLinkedQueue<V>());
o.subscribe(new Action1<V>() {
@Override
public void call(V v) {
result.get(o.getKey()).add(v);
}
});
}
});
return result;
}
示例7: testGroupByOnAsynchronousSourceAcceptsMultipleSubscriptions
import rx.observables.GroupedObservable; //导入依赖的package包/类
@Test
public void testGroupByOnAsynchronousSourceAcceptsMultipleSubscriptions() throws InterruptedException {
// choose an asynchronous source
Observable<Long> source = Observable.interval(10, TimeUnit.MILLISECONDS).take(1);
// apply groupBy to the source
Observable<GroupedObservable<Boolean, Long>> stream = source.groupBy(IS_EVEN);
// create two observers
@SuppressWarnings("unchecked")
Observer<GroupedObservable<Boolean, Long>> o1 = mock(Observer.class);
@SuppressWarnings("unchecked")
Observer<GroupedObservable<Boolean, Long>> o2 = mock(Observer.class);
// subscribe with the observers
stream.subscribe(o1);
stream.subscribe(o2);
// check that subscriptions were successful
verify(o1, never()).onError(Matchers.<Throwable> any());
verify(o2, never()).onError(Matchers.<Throwable> any());
}
示例8: testTakeUnsubscribesOnGroupBy
import rx.observables.GroupedObservable; //导入依赖的package包/类
@Test
public void testTakeUnsubscribesOnGroupBy() {
Observable.merge(
EventStream.getEventStream("HTTP-ClusterA", 50),
EventStream.getEventStream("HTTP-ClusterB", 20))
// group by type (2 clusters)
.groupBy(new Func1<Event, String>() {
@Override
public String call(Event event) {
return event.type;
}
}).take(1)
.toBlockingObservable().forEach(new Action1<GroupedObservable<String, Event>>() {
@Override
public void call(GroupedObservable<String, Event> g) {
System.out.println(g);
}
});
System.out.println("**** finished");
}
示例9: GroupBySubscriber
import rx.observables.GroupedObservable; //导入依赖的package包/类
public GroupBySubscriber(Func1<? super T, ? extends K> keySelector, Func1<? super T, ? extends R> elementSelector, Subscriber<? super GroupedObservable<K, R>> child) {
this.keySelector = keySelector;
this.elementSelector = elementSelector;
this.child = child;
child.add(Subscriptions.create(new Action0() {
public void call() {
if (GroupBySubscriber.WIP_FOR_UNSUBSCRIBE_UPDATER.decrementAndGet(GroupBySubscriber.this.self) == 0) {
GroupBySubscriber.this.self.unsubscribe();
}
}
}));
}
示例10: main
import rx.observables.GroupedObservable; //导入依赖的package包/类
public static void main(String[] args) {
System.out.println("Simple scan usage");
Observable.from(NumbersGenerator.getList(1000))
.groupBy((i) -> 0 == (int)i % 2 ? "EVEN" : "ODD")
.subscribe((group) -> {
System.out.println("Key " + ((GroupedObservable)group).getKey());
((GroupedObservable)group).subscribe((x) -> System.out.println(((GroupedObservable)group).getKey() + ": " + x));
});
}
示例11: toBatchPoints
import rx.observables.GroupedObservable; //导入依赖的package包/类
/**
* Converts a list of Points to BatchPoints
*/
private BatchPoints toBatchPoints (GroupedObservable<String, JsonEvent> byDatabase, List<Point> points) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Storing batch of {} in db {}", points.size(), byDatabase.getKey());
}
return BatchPoints.database(ensureDatabaseNameIsValid (byDatabase.getKey ()))
.points(points.toArray(new Point[0])).build();
}
示例12: ensureDatabaseExists
import rx.observables.GroupedObservable; //导入依赖的package包/类
/**
* Invokes createOrGet database command to make sure that the database exists
*
* * TODO - Add a cache of databases that evicts names after a certain interval but removes an extra HTTP call for each invocation.
*/
private Observable<GroupedObservable<String, JsonEvent>> ensureDatabaseExists (InfluxDB influxDB, GroupedObservable<String, JsonEvent> byDatabase) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Ensuring db exists: {}", byDatabase.getKey());
}
return ioJob(() -> {
influxDB.createDatabase(ensureDatabaseNameIsValid (byDatabase.getKey ()));
return byDatabase;
});
}
示例13: testZipObservableOfObservables
import rx.observables.GroupedObservable; //导入依赖的package包/类
@Test
public void testZipObservableOfObservables() {
EventStream.getEventStream("HTTP-ClusterB", 20)
.groupBy(new Function<Event, String>() {
@Override
public String call(Event e) {
return e.instanceId;
}
// now we have streams of cluster+instanceId
}).flatMap(new Function<GroupedObservable<String, Event>, Observable<Map<String, String>>>() {
@Override
public Observable<Map<String, String>> call(final GroupedObservable<String, Event> ge) {
return ge.scan(new HashMap<String, String>(), new BiFunction<Map<String, String>, Event, Map<String, String>>() {
@Override
public Map<String, String> call(Map<String, String> accum, Event perInstanceEvent) {
accum.put("instance", ge.getKey());
return accum;
}
});
}
})
.take(10)
.toBlocking().forEach(new Action1<Map<String, String>>() {
@Override
public void call(Map<String, String> v) {
System.out.println(v);
}
});
System.out.println("**** finished");
}
示例14: testGroupBy
import rx.observables.GroupedObservable; //导入依赖的package包/类
@Test
public void testGroupBy() {
Observable<String> source = Observable.just("one", "two", "three", "four", "five", "six");
Observable<GroupedObservable<Integer, String>> grouped = source.lift(new OperatorGroupBy<String, Integer, String>(length));
Map<Integer, Collection<String>> map = toMap(grouped);
assertEquals(3, map.size());
assertArrayEquals(Arrays.asList("one", "two", "six").toArray(), map.get(3).toArray());
assertArrayEquals(Arrays.asList("four", "five").toArray(), map.get(4).toArray());
assertArrayEquals(Arrays.asList("three").toArray(), map.get(5).toArray());
}
示例15: testGroupByWithElementSelector
import rx.observables.GroupedObservable; //导入依赖的package包/类
@Test
public void testGroupByWithElementSelector() {
Observable<String> source = Observable.just("one", "two", "three", "four", "five", "six");
Observable<GroupedObservable<Integer, Integer>> grouped = source.lift(new OperatorGroupBy<String, Integer, Integer>(length, length));
Map<Integer, Collection<Integer>> map = toMap(grouped);
assertEquals(3, map.size());
assertArrayEquals(Arrays.asList(3, 3, 3).toArray(), map.get(3).toArray());
assertArrayEquals(Arrays.asList(4, 4).toArray(), map.get(4).toArray());
assertArrayEquals(Arrays.asList(5).toArray(), map.get(5).toArray());
}