So I have this POJO class:
public class Player {
@CsvBindByName
private String simTime;
@CsvBindByName
private String playerId;
@CsvBindByName
private String dimX;
@CsvBindByName
private String offX;
@CsvBindByName
private String dimY;
@CsvBindByName
private String roadS;
@CsvBindByName
private String roadT;
public String getSimTime() {
return simTime;
}
public void setSimTime(String simTime) {
this.simTime = simTime;
}
public String getPlayerId() {
return playerId;
}
public void setPlayerId(String playerId) {
this.playerId = playerId;
}
public String getDimX() {
return dimX;
}
public void setDimX(String dimX) {
this.dimX = dimX;
}
public String getOffX() {
return offX;
}
public void setOffX(String offX) {
this.offX = offX;
}
public String getDimY() {
return dimY;
}
public void setDimY(String dimY) {
this.dimY = dimY;
}
public String getRoadS() {
return roadS;
}
public void setRoadS(String roadS) {
this.roadS = roadS;
}
public String getRoadT() {
return roadT;
}
public void setRoadT(String roadT) {
this.roadT = roadT;
}
@Override
public String toString() {
return "Player{" + "simTime=" + simTime + ", playerId=" + playerId + ", dimX=" + dimX + ", offX=" + offX + ", dimY=" + dimY + ", roadS=" + roadS + ", roadT=" + roadT + '}';
}
}
And I have a large excel file with a LOT MORE columns. One of the columns in my excel file is called objectId
.
Using this code:
private void loadCSVFiles() throws Exception {
List<Player> beans = new CsvToBeanBuilder(new FileReader("C:\\Users\\noname\\Desktop\\ABP_S31\\ABP20180809_S31_FG_Notbremsung_100.csv"))
.withType(Player.class)
.withIgnoreLeadingWhiteSpace(true)
.build()
.parse();
beans.forEach(System.out::println);
}
I managed to get specific columns which I need.
The problem I am having is that right now I only need rows where the playerId
equals objectId
. Obviously I could add objectId
as a class property and after I load the file I could go through the entire list and filter the rows AGAIN. But I don't want to this as
- performance issues
- objectId has actually nothing to do with my Player class
Also I could load the entire excel file and filter the columns, but I also don't want this because for me personally it is more readable if I do this the current way. Is there a way to solve this problem or do I have to use the options above?
I tried using csvToBeanFilter
but the getColumnIndex
method is deprecated: docu