【发布时间】:2018-05-26 12:35:24
【问题描述】:
我正在尝试使用 jOOλ 库 (https://github.com/jOOQ/jOOL) 总结 Bigdecimal 字段
这是我的代码,但它仅适用于总结双打。 这里我对字段 x 求和,并按字段 w、z 分组:
class A {
final int w;
final Double x;
final int y;
final int z;
A(int w, Double x, int y, int z) {
this.w = w;
this.x = x;
this.y = y;
this.z = z;
}
}
Map<
Tuple2<Integer, Integer>,
DoubleSummaryStatistics
> map =
Seq.of(
new A(1, 1.01D, 1, 1),
new A(1, 2.09D, 3, 1),
new A(1, 8D, 6, 1),
new A(2, 119D, 7, 2),
new A(1, 3.01D, 4, 1),
new A(1, 4D, 4, 1),
new A(1, 5D, 5, 1))
.groupBy(
t -> tuple(t.z, t.w),
Tuple.collectors(
Collectors.summarizingDouble(t -> t.x)
)
);
map.entrySet().forEach(t-> {
log.info("w={}, z={}, sumX={}", t.getKey().v1, t.getKey().v2,
t.getValue().getSum());
});
有没有办法使用 BigDecimal 而不是 Double,使用那个库? 我只需要使用 BigDecimal,因为我想用它来总结财务操作。
任何帮助将不胜感激。
【问题讨论】:
-
您的代码不应该编译。
map的类型应该是Map<Tuple2<Integer, Integer>, Tuple1<DoubleSummaryStatistics>>
标签: java stream tuples jool-library