Skip to content

Commit

Permalink
use sequenced collection methods (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbusche authored Jan 13, 2024
1 parent 544a528 commit a1abf3f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/main/java/trap/report/ReportHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private Workbook getWorkbook() throws IOException {
private List<RoundScore> generateRoundScores(String type) throws IOException, CsvException {
CSVReader reader = new CSVReader(new FileReader(type + ".csv"));
List<String[]> roundScores = reader.readAll();
roundScores.remove(0);
roundScores.removeFirst();
List<RoundScore> roundScoresList = new ArrayList<>();
roundScores.forEach((s) -> roundScoresList.add(new RoundScore(Integer.parseInt(s[1]), s[2].trim(), Integer.parseInt(s[3]), s[4].trim(), s[5].trim(), s[6].trim(), s[7].trim().replace("Club", "Team"), s[8].trim(), s[10].trim(), s[11].trim(), "".equals(s[12]) ? 0 : Integer.parseInt(s[12]), "".equals(s[13]) ? 0 : Integer.parseInt(s[13]), "".equals(s[14]) ? 0 : Integer.parseInt(s[14]), "".equals(s[15]) ? 0 : Integer.parseInt(s[15]), "".equals(s[16]) ? 0 : Integer.parseInt(s[16]), "".equals(s[17]) ? 0 : Integer.parseInt(s[17]), "".equals(s[18]) ? 0 : Integer.parseInt(s[18]), "".equals(s[19]) ? 0 : Integer.parseInt(s[19]), type)));
return roundScoresList;
Expand Down Expand Up @@ -146,12 +146,12 @@ private void populateCleanData(Sheet sheet, List<RoundScore> allRoundScores) {
private List<TeamScore> getTeamScores(List<Map.Entry<String, ArrayList<IndividualTotal>>> teamData) {
HashMap<String, TeamScore> teamScoresThatCount = new HashMap<>();
for (Map.Entry<String, ArrayList<IndividualTotal>> total : teamData) {
var details = new TeamScore(total.getValue().get(0).getTeam(), 0);
teamScoresThatCount.put(total.getValue().get(0).getTeam(), details);
var details = new TeamScore(total.getValue().getFirst().getTeam(), 0);
teamScoresThatCount.put(total.getValue().getFirst().getTeam(), details);
}

for (Map.Entry<String, ArrayList<IndividualTotal>> total : teamData) {
TeamScore teamTotal = teamScoresThatCount.get(total.getValue().get(0).getTeam());
TeamScore teamTotal = teamScoresThatCount.get(total.getValue().getFirst().getTeam());
for (IndividualTotal indTotal : total.getValue()) {
int currentTotal = teamTotal.getTotal();
teamTotal.setTotal(currentTotal + indTotal.getTotal());
Expand All @@ -173,7 +173,7 @@ private void populateTeamData(Sheet sheet, String teamType, CellStyle mainTextSt
int startColumn = 1;
long start = System.currentTimeMillis();

List<Map.Entry<String, ArrayList<IndividualTotal>>> teamData = teamScoresByTotal.entrySet().stream().filter(f -> f.getValue().get(0).getTeamClassificationForTotal().equals(teamType) && f.getValue().get(0).getType().equals(SINGLES)).toList();
List<Map.Entry<String, ArrayList<IndividualTotal>>> teamData = teamScoresByTotal.entrySet().stream().filter(f -> f.getValue().getFirst().getTeamClassificationForTotal().equals(teamType) && f.getValue().getFirst().getType().equals(SINGLES)).toList();
List<TeamScore> teamScores = getTeamScores(teamData);
System.out.println("Ran query for singles by " + teamType + " " + (System.currentTimeMillis() - start) + "ms");
for (TeamScore teamScore : teamScores) {
Expand All @@ -188,7 +188,7 @@ private void populateTeamData(Sheet sheet, String teamType, CellStyle mainTextSt
for (String type : types) {
updateRow = rows;
start = System.currentTimeMillis();
teamData = teamScoresByTotal.entrySet().stream().filter(f -> f.getValue().get(0).getTeamClassificationForTotal().equals(teamType) && f.getValue().get(0).getType().equals(type)).toList();
teamData = teamScoresByTotal.entrySet().stream().filter(f -> f.getValue().getFirst().getTeamClassificationForTotal().equals(teamType) && f.getValue().getFirst().getType().equals(type)).toList();
teamScores = getTeamScores(teamData);
System.out.println("Ran query for " + type + " by " + teamType + " " + (System.currentTimeMillis() - start) + "ms");
for (TeamScore teamScore : teamScores) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/trap/report/TrapHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Map<String, ArrayList<IndividualTotal>> calculatePlayerIndividualTotal(Li
}
for (ArrayList<RoundTotal> playerRoundTotal : playerRoundTotals.values()) {
// clays, skeet, and fivestand are top 3 scores only, minimum 2 locations
var subtractScores = subtractScores(playerRoundTotal.get(0).getType());
var subtractScores = subtractScores(playerRoundTotal.getFirst().getType());
ArrayList<IndividualTotal> indTotal = new ArrayList<>();
playerRoundTotal.sort(Comparator.comparingInt(RoundTotal::getTotal).reversed());
for (RoundTotal t : playerRoundTotal) {
Expand All @@ -73,7 +73,7 @@ public Map<String, ArrayList<IndividualTotal>> calculatePlayerIndividualTotal(Li

}
}
playerIndividualTotal.put(playerRoundTotal.get(0).getUniqueName(), indTotal);
playerIndividualTotal.put(playerRoundTotal.getFirst().getUniqueName(), indTotal);
}

return playerIndividualTotal;
Expand All @@ -89,7 +89,7 @@ public Map<String, IndividualTotal> calculatePlayerFinalTotal(Map<String, ArrayL
for (IndividualTotal t : value) {
total += t.getTotal();
}
playerFinalTotal.put(key, new IndividualTotal(0, value.get(0).getTeam(), value.get(0).getAthlete(), value.get(0).getClassification(), value.get(0).getGender(), total, value.get(0).getType()));
playerFinalTotal.put(key, new IndividualTotal(0, value.getFirst().getTeam(), value.getFirst().getAthlete(), value.getFirst().getClassification(), value.getFirst().getGender(), total, value.getFirst().getType()));
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/test/java/trap/report/TrapHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ void testPlayerRoundTotals() {
roundScores.addAll(roundScoresPlayer2);
var playerRoundTotals = trapHelper.calculatePlayerRoundTotals(roundScores);

var player1 = playerRoundTotals.get(roundScoresPlayer1.get(0).getUniqueName());
var player1 = playerRoundTotals.get(roundScoresPlayer1.getFirst().getUniqueName());
assertEquals(16, player1.size());
var player2 = playerRoundTotals.get(roundScoresPlayer2.get(0).getUniqueName());
var player2 = playerRoundTotals.get(roundScoresPlayer2.getFirst().getUniqueName());
assertEquals(6, player2.size());
}

Expand All @@ -118,14 +118,14 @@ void testPlayerIndividualTotals() {

var playerIndividualTotal = trapHelper.calculatePlayerIndividualTotal(roundScores, playerRoundTotals);

var player1 = playerIndividualTotal.get(roundScoresPlayer1.get(0).getUniqueName());
var player1 = playerIndividualTotal.get(roundScoresPlayer1.getFirst().getUniqueName());
assertEquals(4, player1.size());
assertEquals(49, player1.get(0).getTotal());
assertEquals(48, player1.get(1).getTotal());
assertEquals(48, player1.get(2).getTotal());
assertEquals(48, player1.get(3).getTotal());

var player2 = playerIndividualTotal.get(roundScoresPlayer2.get(0).getUniqueName());
var player2 = playerIndividualTotal.get(roundScoresPlayer2.getFirst().getUniqueName());
assertEquals(4, player2.size());
assertEquals(49, player2.get(0).getTotal());
assertEquals(49, player2.get(1).getTotal());
Expand All @@ -144,7 +144,7 @@ void testPlayerFinalTotal() {
var playerIndividualTotal = trapHelper.calculatePlayerIndividualTotal(roundScores, playerRoundTotals);
var playerFinalTotal = trapHelper.calculatePlayerFinalTotal(playerIndividualTotal);

var player1 = roundScoresPlayer1.get(0);
var player1 = roundScoresPlayer1.getFirst();
assertEquals(0, playerFinalTotal.get(player1.getUniqueName()).getLocationId());
assertEquals("UNI Trap Team", playerFinalTotal.get(player1.getUniqueName()).getTeam());
assertEquals("Scott W Busche", playerFinalTotal.get(player1.getUniqueName()).getAthlete());
Expand All @@ -153,11 +153,11 @@ void testPlayerFinalTotal() {
assertEquals(193, playerFinalTotal.get(player1.getUniqueName()).getTotal());
assertEquals("singles", playerFinalTotal.get(player1.getUniqueName()).getType());

var player2 = roundScoresPlayer2.get(0);
var player2 = roundScoresPlayer2.getFirst();

assertEquals(4, playerFinalTotal.size());

var firstResult = roundScoresPlayer2.get(0).getUniqueName();
var firstResult = roundScoresPlayer2.getFirst().getUniqueName();
assertEquals(0, playerFinalTotal.get(firstResult).getLocationId());
assertEquals("UNI Trap Team", playerFinalTotal.get(firstResult).getTeam());
assertEquals("Matt Busche", playerFinalTotal.get(firstResult).getAthlete());
Expand Down Expand Up @@ -192,7 +192,7 @@ void testPlayerFinalTotal2() {
var playerIndividualTotal = trapHelper.calculatePlayerIndividualTotal(roundScores, playerRoundTotals);
var playerFinalTotal = trapHelper.calculatePlayerFinalTotal(playerIndividualTotal);

var player1 = roundScores.get(0);
var player1 = roundScores.getFirst();
assertEquals(0, playerFinalTotal.get(player1.getUniqueName()).getLocationId());
assertEquals("Minnesota Vikings", playerFinalTotal.get(player1.getUniqueName()).getTeam());
assertEquals("Justin Jefferson", playerFinalTotal.get(player1.getUniqueName()).getAthlete());
Expand All @@ -209,7 +209,7 @@ void testClaysScoring() {
var playerIndividualTotal = trapHelper.calculatePlayerIndividualTotal(roundScores, playerRoundTotals);
var playerFinalTotal = trapHelper.calculatePlayerFinalTotal(playerIndividualTotal);

var player1 = roundScores.get(0);
var player1 = roundScores.getFirst();
assertEquals(0, playerFinalTotal.get(player1.getUniqueName()).getLocationId());
assertEquals("Ankeny Centennial Jaguars Shooting Sports", playerFinalTotal.get(player1.getUniqueName()).getTeam());
assertEquals("Sam LaPorta", playerFinalTotal.get(player1.getUniqueName()).getAthlete());
Expand All @@ -226,7 +226,7 @@ void testPlayerFinalTotal5() {
var playerIndividualTotal = trapHelper.calculatePlayerIndividualTotal(roundScores, playerRoundTotals);
var playerFinalTotal = trapHelper.calculatePlayerFinalTotal(playerIndividualTotal);

var player1 = roundScores.get(0);
var player1 = roundScores.getFirst();
assertEquals(0, playerFinalTotal.get(player1.getUniqueName()).getLocationId());
assertEquals("Wilton Trap Team", playerFinalTotal.get(player1.getUniqueName()).getTeam());
assertEquals("TJ Hockenson", playerFinalTotal.get(player1.getUniqueName()).getAthlete());
Expand Down

0 comments on commit a1abf3f

Please sign in to comment.