Lambda 在新列表中创建行摘要<&燃气轮机;
我想将列表中的信息汇总为平均值,并将按分钟分组的信息写入列表 我有这样一个资产类别,我想用longtrademinutes将每件事都按分钟进行分组;把每件事都分组。然后平均价格列。写入其他字段时保持不变。它们在每一行上总是相同的 我认为在Java8中使用lambda表达式可以实现这一点Lambda 在新列表中创建行摘要<&燃气轮机;,lambda,java-8,Lambda,Java 8,我想将列表中的信息汇总为平均值,并将按分钟分组的信息写入列表 我有这样一个资产类别,我想用longtrademinutes将每件事都按分钟进行分组;把每件事都分组。然后平均价格列。写入其他字段时保持不变。它们在每一行上总是相同的 我认为在Java8中使用lambda表达式可以实现这一点 public class Asset implements Serializable, Comparable<Asset> { private static final long seria
public class Asset implements Serializable, Comparable<Asset> {
private static final long serialVersionUID = 1L;
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id; // still set automatically
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
long sequenceNo;
String Exchange;
String Board;
long time;
String paper;
long tradeTime;
long quantity;
double price;
String source;
String buyer;
String seller;
float changeSinceLast;
String initator;
long tradeTimeSinceMidnight;
long tradeMinutesSinceMidnight;
long daysSinceEpoch;
public long getSequenceNo() {
return sequenceNo;
}
public void setSequenceNo(long sequenceNo) {
this.sequenceNo = sequenceNo;
}
public String getExchange() {
return Exchange;
}
public void setExchange(String exchange) {
Exchange = exchange;
}
public String getBoard() {
return Board;
}
public void setBoard(String board) {
Board = board;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
public String getPaper() {
return paper;
}
public void setPaper(String paper) {
this.paper = paper;
}
public long getTradeTime() {
return tradeTime;
}
public void setTradeTime(long tradeTime) {
this.tradeTime = tradeTime;
}
public long getQuantity() {
return quantity;
}
public void setQuantity(long quantity) {
this.quantity = quantity;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getBuyer() {
return buyer;
}
public void setBuyer(String buyer) {
this.buyer = buyer;
}
public String getSeller() {
return seller;
}
public void setSeller(String seller) {
this.seller = seller;
}
public float getChangeSinceLast() {
return changeSinceLast;
}
public void setChangeSinceLast(float changeSinceLast) {
this.changeSinceLast = changeSinceLast;
}
public String getInitator() {
return initator;
}
public void setInitator(String initator) {
this.initator = initator;
}
public long getDaysSinceEpoch() {
return daysSinceEpoch;
}
public void setDaysSinceEpoch(long daysSinceEpoch) {
this.daysSinceEpoch = daysSinceEpoch;
}
public long getTradeTimeSinceMidnight() {
return tradeTimeSinceMidnight;
}
public void setTradeTimeSinceMidnight(long tradeTimeSinceMidnight) {
this.tradeTimeSinceMidnight = tradeTimeSinceMidnight;
}
public long getTradeMinutesSinceMidnight() {
return tradeMinutesSinceMidnight;
}
public void setTradeMinutesSinceMidnight(long tradeMinutesSinceMidnight) {
this.tradeMinutesSinceMidnight = tradeMinutesSinceMidnight;
}
@Override
public boolean equals(Object obj) {
return sequenceNo == ((Asset)obj).sequenceNo;
}
@Override
public int compareTo(Asset otherAsset) {
if (this.getSequenceNo() < otherAsset.getSequenceNo()) {
return -1;
}
else if (this.getSequenceNo() == otherAsset.getSequenceNo()) {
return 0;
}
return 1;
}
}
公共类资产实现了可序列化、可比较的{
私有静态最终长serialVersionUID=1L;
@Id@GeneratedValue(策略=GenerationType.IDENTITY)
private Long id;//仍然自动设置
公共长getId(){
返回id;
}
公共无效集合id(长id){
this.id=id;
}
长序列号;
字符串交换;
线板;
长时间;
线纸;
交易时间长;
数量多;
双倍价格;
字符串源;
弦乐买家;
线人;
漂浮物变化;
字符串启动器;
从午夜开始的漫长时间;
从午夜开始的漫长交易;
长日照期;
公共长getSequenceNo(){
返回序列号;
}
公共无效序列号(长序列号){
this.sequenceNo=sequenceNo;
}
公共字符串getExchange(){
换汇;
}
公共无效集合交换(字符串交换){
交换=交换;
}
公共字符串getBoard(){
返回板;
}
公共空隙立根板(线板){
董事会=董事会;
}
公共长getTime(){
返回时间;
}
公共无效设置时间(长时间){
这个时间=时间;
}
公共字符串getPaper(){
回执纸;
}
公共空白衬纸(线纸){
这张纸=纸;
}
公共长时间(){
返回时间;
}
公共无效设置交易时间(长交易时间){
this.tradeTime=交易时间;
}
公共长getQuantity(){
退货数量;
}
公共无效设置数量(长数量){
这个。数量=数量;
}
公开双价{
退货价格;
}
公共定价(双倍价格){
这个价格=价格;
}
公共字符串getSource(){
返回源;
}
公共void集合源(字符串源){
this.source=源;
}
公共字符串getBuyer(){
退货买家;
}
公共买方(字符串买方){
这个。买方=买方;
}
公共字符串getSeller(){
退货卖家;
}
公共无效设置卖方(字符串卖方){
this.seller=卖方;
}
公共浮点getChangeSinceLast(){
最后的回报变化;
}
公共无效设置更改最后一次(浮动更改最后一次){
this.changeSinceLast=changeSinceLast;
}
公共字符串getInitator(){
返回启动器;
}
公共void setInitator(字符串initator){
this.initator=initator;
}
公共长getDaysSinceEpoch(){
返回日期;返回时间;
}
公共无效setDaysSinceEpoch(长daysSinceEpoch){
this.daysSinceEpoch=daysSinceEpoch;
}
公共长getTradeTimeSinceMidnight(){
午夜返回;
}
public void setTradeTimeSinceMidnight(长tradeTimeSinceMidnight){
this.tradeTimeSinceMidnight=tradeTimeSinceMidnight;
}
公共long getTradeMinutesSinceMidnight(){
午夜后返回交易记录;
}
公共无效设置tradeMinutesSinceMidnight(长tradeMinutesSinceMidnight){
this.tradeMinutesSinceMidnight=tradeMinutesSinceMidnight;
}
@凌驾
公共布尔等于(对象obj){
返回序列号==((资产)对象)。序列号;
}
@凌驾
公共整数比较(资产其他资产){
if(this.getSequenceNo()
将包含结果的AssetCommand类
public class AssetSummary implements Serializable, Comparable<AssetSummary> {
private static final long serialVersionUID = 1L;
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id; // still set automatically
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
String Exchange;
long time;
String paper;
long quantity;
double avgPrice;
long tradeMinutesSinceMidnight;
long daysSinceEpoch;
public String getExchange() {
return Exchange;
}
public void setExchange(String exchange) {
Exchange = exchange;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
public String getPaper() {
return paper;
}
public void setPaper(String paper) {
this.paper = paper;
}
public long getQuantity() {
return quantity;
}
public void setQuantity(long quantity) {
this.quantity = quantity;
}
public double getAvgPrice() {
return avgPrice;
}
public void setAvgPrice(double avgPrice) {
this.avgPrice = avgPrice;
}
public long getTradeMinutesSinceMidnight() {
return tradeMinutesSinceMidnight;
}
public void setTradeMinutesSinceMidnight(long tradeMinutesSinceMidnight) {
this.tradeMinutesSinceMidnight = tradeMinutesSinceMidnight;
}
public long getDaysSinceEpoch() {
return daysSinceEpoch;
}
public void setDaysSinceEpoch(long daysSinceEpoch) {
this.daysSinceEpoch = daysSinceEpoch;
}
@Override
public int compareTo(AssetSummary otherAsset) {
if (this.tradeMinutesSinceMidnight < otherAsset.tradeMinutesSinceMidnight) {
return -1;
}
else if (this.tradeMinutesSinceMidnight == otherAsset.tradeMinutesSinceMidnight) {
return 0;
}
return 1;
}
}
公共类AssetCommand实现了可序列化、可比较的{
私有静态最终长serialVersionUID=1L;
@Id@GeneratedValue(策略=GenerationType.IDENTITY)
private Long id;//仍然自动设置
公共长getId(){
返回id;
}
公共无效集合id(长id){
this.id=id;
}
字符串交换;
长时间;
线纸;
数量多;
双平均价格;
从午夜开始的漫长交易;
长日照期;
公共字符串getExchange(){
换汇;
}
公共无效集合交换(字符串交换){
交换=交换;
}
公共长getTime(){
返回时间;
}
公共无效设置时间(长时间){
这个时间=时间;
}
公共字符串getPaper(){
回执纸;
}
公共空白衬纸(线纸){
这张纸=纸;
}
公共长getQuantity(){
退货数量;
}
公共无效设置数量(长数量){
这个。数量=数量;
}
公共双getAvgPrice(){
返回平均价格;
}
公共无效设置平均价格(双平均价格){
this.avgPrice=avgPrice;
}
公共long getTradeMinutesSinceMidnight(){
午夜后返回交易记录;
}
公共无效设置tradeMinutesSinceMidnight(长tradeMinutesSinceMidnight){
this.tradeMinutesSinceMidnight=tradeMinutesSinceMidnight;
}
公共长getDaysSinceEpoch(){
返回日期;返回时间;
}
公共无效setDaysSinceEpoch(长daysSinceEpoch){
this.daysSinceEpoch=daysSinceEpoch;
}
@凌驾
公共内部比较(资产汇总其他资产){
如果(this.tradeMinutesSinceMidnight