本文整理汇总了Java中rx.observables.MathObservable类的典型用法代码示例。如果您正苦于以下问题:Java MathObservable类的具体用法?Java MathObservable怎么用?Java MathObservable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MathObservable类属于rx.observables包,在下文中一共展示了MathObservable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runCode
import rx.observables.MathObservable; //导入依赖的package包/类
public void runCode() {
//compile 'io.reactivex:rxjava-math:1.0.0'
// http://blog.csdn.net/nicolelili1/article/details/52180643
MathObservable.averageInteger(Observable.just(1, 2, 3, 4))
.subscribe(new Subscriber<Integer>() {
@Override
public void onCompleted() {
println("onCompleted.");
}
@Override
public void onError(Throwable e) {
println("onError: " + e.getMessage());
}
@Override
public void onNext(Integer integer) {
println("onNext: " + integer);
}
});
}
示例2: runCode
import rx.observables.MathObservable; //导入依赖的package包/类
public void runCode() {
MathObservable.sumInteger(Observable.just(11, 2, 3, 4, 5))
.subscribe(new Subscriber<Integer>() {
@Override
public void onNext(Integer v) {
println( "onNext:." + v);
}
@Override
public void onCompleted() {
println("onCompleted:");
}
@Override
public void onError(Throwable e) {
println("onError:");
}
});
}
示例3: runCode
import rx.observables.MathObservable; //导入依赖的package包/类
public void runCode() {
MathObservable.max(Observable.just(0, 1, 2, 4))
.subscribe(new Subscriber<Integer>() {
@Override
public void onCompleted() {
println("onCompleted");
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Integer integer) {
println("onNext:"+integer);
}
});
}
示例4: runCode
import rx.observables.MathObservable; //导入依赖的package包/类
public void runCode() {
MathObservable.min(Observable.just(0, 1, 2, 4))
.subscribe(new Subscriber<Integer>() {
@Override
public void onCompleted() {
println("onCompleted");
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Integer integer) {
println("onNext:"+integer);
}
});
}
示例5: doExecute
import rx.observables.MathObservable; //导入依赖的package包/类
public ExecutionResult doExecute(ExecutionContext executionContext, GraphQLObjectType parentType, Object source, Map<String, List<Field>> fields) {
List<Observable<Pair<String, Object>>> observablesResult = new ArrayList<>();
List<Observable<Double>> observablesComplexity = new ArrayList<>();
for (String fieldName : fields.keySet()) {
final List<Field> fieldList = fields.get(fieldName);
ExecutionResult executionResult = resolveField(executionContext, parentType, source, fieldList);
observablesResult.add(unwrapExecutionResult(fieldName, executionResult));
observablesComplexity.add(calculateFieldComplexity(executionContext, parentType, fieldList,
executionResult != null ? ((GraphQLRxExecutionResult) executionResult).getComplexityObservable() : Observable.just(0.0)));
}
Observable<Map<String, Object>> result =
Observable.merge(observablesResult)
.toMap(Pair::getLeft, Pair::getRight);
GraphQLRxExecutionResult graphQLRxExecutionResult = new GraphQLRxExecutionResult(result, Observable.just(executionContext.getErrors()), MathObservable.sumDouble(Observable.merge(observablesComplexity)));
return graphQLRxExecutionResult;
}
示例6: testJdbcObservableCountLettersInAllNames
import rx.observables.MathObservable; //导入依赖的package包/类
@Test
public void testJdbcObservableCountLettersInAllNames() {
int count = MathObservable
.sumInteger(db()
// select
.select("select name from person where name >?")
// set name
.parameter("ALEX")
// count letters
.get(COUNT_LETTERS_IN_NAME))
// first result
.first()
// block and get result
.toBlocking().single();
assertEquals(19, count);
}
示例7: testConvertObservableToInt
import rx.observables.MathObservable; //导入依赖的package包/类
@Test
public void testConvertObservableToInt() {
Integer sum = MathObservable.sumInteger(Observable.just(1, 2, 8, 9, 10, 11)).toBlocking().first();
System.out.println(sum);
List<String> list = Observable.just("it", "was", "the", "best", "of", "times").buffer(100).toBlocking().single();
System.out.println(list);
}
示例8: testMax
import rx.observables.MathObservable; //导入依赖的package包/类
@Test
public void testMax() {
Integer[] list = new Integer[]{10, 20, null, 30, 40, 50};
Observable<Integer> observable = Observable.from(list);
Observable<Integer> buffer = MathObservable.from(observable)
.max(Integer::compareTo);
buffer.subscribe(System.out::println,
Throwable::printStackTrace,
() -> System.out.println("Complete"));
}
示例9: testSum
import rx.observables.MathObservable; //导入依赖的package包/类
@Test
public void testSum() {
Integer[] list = new Integer[]{10, 20, null, 30, 40, 50};
Observable<Integer> observable = Observable.from(list)
.filter(s -> s != null);
Observable<Integer> buffer = MathObservable.from(observable)
.sumInteger(s -> s * 10);
buffer.subscribe(System.out::println,
Throwable::printStackTrace,
() -> System.out.println("Complete"));
}
示例10: testMath
import rx.observables.MathObservable; //导入依赖的package包/类
@Test
public void testMath() {
Integer[] list = new Integer[]{10, 60, null, 65, 70, 80};
Observable<Integer> observable = Observable.from(list)
.filter(s -> s != null);
Observable<Double> sum = MathObservable.from(observable)
.sumDouble(s -> s * 1d);
Observable<Double> max = MathObservable.from(observable)
.max(Integer::compareTo)
.map(s -> s * 1.);
Observable<Double> min = MathObservable.from(observable)
.min(Integer::compareTo)
.map(s -> s * 1.);
Observable<Double> medianStream = max.mergeWith(min);
Observable<Double> midrange = MathObservable.from(medianStream).averageDouble(s -> s);
midrange.subscribe((x) -> System.out.println("Mid range:" + x));
Observable<Integer> midrangeInt = MathObservable.from(medianStream).averageInteger(Double::intValue);
midrangeInt.subscribe((x) -> System.out.println("Mid range int:" + x));
sum.subscribe((x) -> System.out.println("Sum:" + x),
Throwable::printStackTrace,
() -> System.out.println("Complete"));
}
示例11: testMidRange
import rx.observables.MathObservable; //导入依赖的package包/类
@Test
public void testMidRange() {
Integer[] list = {10, 80, 90, 100};
Observable<Integer> ints = Observable.from(list);
Observable<Integer> min = MathObservable.from(ints).min(Integer::compareTo);
Observable<Integer> max = MathObservable.from(ints).max(Integer::compareTo);
// min.zipWith(max, (a, b) -> (b + a) / 2).subscribe(System.out::println);
Observable.zip(min, max, (a, b) -> (b + a) / 2).subscribe(System.out::println);
}
示例12: completeValueForList
import rx.observables.MathObservable; //导入依赖的package包/类
@Override
protected ExecutionResult completeValueForList(ExecutionContext executionContext, GraphQLList fieldType, List<Field> fields, List<Object> result) {
Observable<List<ListTuple>> cachedObservable =
Observable.from(
IntStream.range(0, result.size())
.mapToObj(idx -> new ListTuple(idx, result.get(idx), null))
.toArray(ListTuple[]::new)
)
.flatMap(tuple -> {
ExecutionResult executionResult = completeValue(executionContext, fieldType.getWrappedType(), fields, tuple.result);
if (executionResult instanceof GraphQLRxExecutionResult) {
return Observable.zip(Observable.just(tuple.index),
((GraphQLRxExecutionResult) executionResult).getDataObservable(),
((GraphQLRxExecutionResult) executionResult).getComplexityObservable(),
ListTuple::new);
}
return Observable.just(new ListTuple(tuple.index, executionResult.getData(), Observable.just(1.0)));
})
.toList()
.cache();
Observable<?> resultObservable = cachedObservable
.map(listTuples -> {
return listTuples.stream()
.sorted(Comparator.comparingInt(x -> x.index))
.map(x -> x.result)
.collect(Collectors.toList());
});
Observable<?> complexityObservable = cachedObservable
.map(listTuples -> {
return listTuples.stream()
.sorted(Comparator.comparingInt(x -> x.index))
.map(x -> x.complexity)
.collect(Collectors.toList());
})
.flatMap(combined -> Observable.from(combined));
return new GraphQLRxExecutionResult(resultObservable, null, MathObservable.sumDouble((Observable<Double>) complexityObservable));
}
示例13: getApplicationSize
import rx.observables.MathObservable; //导入依赖的package包/类
@Override
public long getApplicationSize(ApplicationScope applicationScope) {
final IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(applicationScope);
EntityIndex entityIndex = entityIndexFactory.createEntityIndex(indexLocationStrategy);
GraphManager graphManager = graphManagerFactory.createEdgeManager(applicationScope);
Long sum = ObservableTimer.time(
MathObservable.sumLong(
graphManager.getEdgeTypesFromSource(new SimpleSearchEdgeType(applicationScope.getApplication(), CpNamingUtils.EDGE_COLL_PREFIX, Optional.<String>absent()))
.map(type -> CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(), type))
.map(edge -> entityIndex.getTotalEntitySizeInBytes(edge))
), sumTimer).toBlocking().last();
return sum.longValue();
}
示例14: call
import rx.observables.MathObservable; //导入依赖的package包/类
@Override
public Observable<Integer> call(Observable<Integer> source) {
return MathObservable.sumInteger(source);
}
示例15: receive
import rx.observables.MathObservable; //导入依赖的package包/类
public Observable<Integer> receive( final ApplicationScope scope, final MarkedEdge edge,
final UUID eventTimestamp ) {
final long maxTimestamp = edge.getTimestamp();
return edgeDeleteRepair.repair( scope, edge, eventTimestamp )
.flatMap( markedEdge -> {
Observable<Integer> sourceDelete = edgeMetaRepair
.repairSources( scope, edge.getSourceNode(), edge.getType(), maxTimestamp );
Observable<Integer> targetDelete = edgeMetaRepair
.repairTargets( scope, edge.getTargetNode(), edge.getType(), maxTimestamp );
return MathObservable.sumInteger( Observable.merge( sourceDelete, targetDelete ) );
} );
}