/* package whatever; // don't place package name! */
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main
(String[] args
) {
List
<DbTrans
> transList
= Arrays.
asList( new DbTrans("Troy", "1123", " Savings", 50),
new DbTrans("Larry", "4233", " Savings", 200),
new DbTrans("Troy", "1123", " Current", 120),
new DbTrans("Larry", "4233", " Current", 220)
);
List<DbTransResponse> collect = transList.stream()
.collect(Collectors.groupingBy(DbTrans::getAcct))
.values().stream()
.map(r -> new DbTransResponse(
r.get(0).getName(),
r.get(0).getAcct(),
r.get(0).getTotal(),
r.get(1).getTotal()
)).collect(Collectors.toList());
collect.
forEach(System.
out::println
);
}
}
class DbTransResponse {
private double totalSavings;
private double totalCurrent;
public DbTransResponse
(String name,
String acct,
double totalSavings,
double totalCurrent
) { this.name = name;
this.acct = acct;
this.totalSavings = totalSavings;
this.totalCurrent = totalCurrent;
}
return name;
}
public void setName
(String name
) { this.name = name;
}
return acct;
}
public void setAcct
(String acct
) { this.acct = acct;
}
public double getTotalSavings() {
return totalSavings;
}
public void setTotalSavings(double totalSavings) {
this.totalSavings = totalSavings;
}
public double getTotalCurrent() {
return totalCurrent;
}
public void setTotalCurrent(double totalCurrent) {
this.totalCurrent = totalCurrent;
}
@Override
return "DbTransResponse{" +
"name='" + name + '\'' +
", acct='" + acct + '\'' +
", totalSavings=" + totalSavings +
", totalCurrent=" + totalCurrent +
'}';
}
}
class DbTrans {
private double total;
this.name = name;
this.acct = acct;
this.type = type;
this.total = total;
}
return name;
}
public void setName
(String name
) { this.name = name;
}
return acct;
}
public void setAcct
(String acct
) { this.acct = acct;
}
return type;
}
public void setType
(String type
) { this.type = type;
}
public double getTotal() {
return total;
}
public void setTotal(double total) {
this.total = total;
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC5BcnJheXM7CmltcG9ydCBqYXZhLnV0aWwuTGlzdDsKaW1wb3J0IGphdmEudXRpbC5zdHJlYW0uQ29sbGVjdG9yczsKCi8qIE5hbWUgb2YgdGhlIGNsYXNzIGhhcyB0byBiZSAiTWFpbiIgb25seSBpZiB0aGUgY2xhc3MgaXMgcHVibGljLiAqLwpjbGFzcyBJZGVvbmUKewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewoKICAgICAgICBMaXN0PERiVHJhbnM+IHRyYW5zTGlzdCA9IEFycmF5cy5hc0xpc3QoCiAgICAgICAgICAgICAgICBuZXcgRGJUcmFucygiVHJveSIsICIxMTIzIiwgIiBTYXZpbmdzIiwgNTApLAogICAgICAgICAgICAgICAgbmV3IERiVHJhbnMoIkxhcnJ5IiwgIjQyMzMiLCAiIFNhdmluZ3MiLCAyMDApLAogICAgICAgICAgICAgICAgbmV3IERiVHJhbnMoIlRyb3kiLCAiMTEyMyIsICIgQ3VycmVudCIsIDEyMCksCiAgICAgICAgICAgICAgICBuZXcgRGJUcmFucygiTGFycnkiLCAiNDIzMyIsICIgQ3VycmVudCIsIDIyMCkKICAgICAgICApOwoKICAgICAgICBMaXN0PERiVHJhbnNSZXNwb25zZT4gY29sbGVjdCA9IHRyYW5zTGlzdC5zdHJlYW0oKQogICAgICAgICAgICAgICAgLmNvbGxlY3QoQ29sbGVjdG9ycy5ncm91cGluZ0J5KERiVHJhbnM6OmdldEFjY3QpKQogICAgICAgICAgICAgICAgLnZhbHVlcygpLnN0cmVhbSgpCiAgICAgICAgICAgICAgICAubWFwKHIgLT4gbmV3IERiVHJhbnNSZXNwb25zZSgKICAgICAgICAgICAgICAgICAgICAgICAgci5nZXQoMCkuZ2V0TmFtZSgpLAogICAgICAgICAgICAgICAgICAgICAgICByLmdldCgwKS5nZXRBY2N0KCksCiAgICAgICAgICAgICAgICAgICAgICAgIHIuZ2V0KDApLmdldFRvdGFsKCksCiAgICAgICAgICAgICAgICAgICAgICAgIHIuZ2V0KDEp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