正文
1985,ATL,NL,campri01,633333
1985,ATL,NL,ceronri01,625000
...
我们用类似于如下代码的Streams加载CSV的数据:
Pattern pattern = Pattern.compile(",");
try (BufferedReader in = new BufferedReader(new FileReader(filename));){
List
players = in
.lines()
.skip(1)
.map(line -> {
String[] arr = pattern.split(line);
return new Player(Integer.parseInt(arr[0]),
arr[1],
arr[2],
arr[3],
Integer.parseInt(arr[4]));
})
.collect(Collectors.toList());
}
我们使用下面的类来定义数据透视表的各个列容器的类。这些列是用于对数据进行分组的。如果你使用的是SQL的话,这些列将出现在“GROUP BY”的语句中。
public class YearTeam
{
public int year;
public String teamID;
public YearTeam(int year,String teamID) {
this.year = year;
this.teamID = teamID;
}
@Override
public boolean equals(Object other)
{
if ( other == null ) return false;
if ( this == other ) return true;
if ( other instanceof YearTeam ) {
YearTeam yt = (YearTeam)other;