From 1cffeba8b7ceef001594e0ed044b1ca386876a39 Mon Sep 17 00:00:00 2001 From: Matt Busche Date: Sat, 21 Dec 2024 22:15:30 -0600 Subject: [PATCH] modernize models --- src/main/java/trap/model/IndividualTotal.java | 14 +++++++------- src/main/java/trap/model/RoundScore.java | 10 +++++++--- src/main/java/trap/model/RoundTotal.java | 4 ++-- src/main/java/trap/report/ReportHelper.java | 4 ++-- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/java/trap/model/IndividualTotal.java b/src/main/java/trap/model/IndividualTotal.java index be7fe034..3b41e22e 100644 --- a/src/main/java/trap/model/IndividualTotal.java +++ b/src/main/java/trap/model/IndividualTotal.java @@ -17,14 +17,14 @@ public class IndividualTotal { String type; public String getTeamForScores() { - return this.type + " " + this.team + " " + this.getTeamClassificationForTotal(); + return "%s %s %s".formatted(this.type, this.team, this.getTeamClassification()); } public String getTeamClassification() { - return this.classification.replace("Senior/Varsity", "Varsity").replace("Senior/Jr. Varsity", "Junior Varsity").replace("Intermediate/Advanced", "Intermediate Advanced").replace("Intermediate/Entry Level", "Intermediate Entry"); + return switch (classification) { + case "Senior/Varsity", "Senior/Jr. Varsity", "Junior Varsity" -> "Varsity"; + case "Intermediate/Advanced", "Intermediate/Entry Level" -> "Intermediate Entry"; + default -> classification; + }; } - - public String getTeamClassificationForTotal() { - return this.getTeamClassification().replace("Senior/Jr. Varsity", "Varsity").replace("Senior/Varsity", "Varsity").replace("Junior Varsity", "Varsity").replace("Intermediate Advanced", "Intermediate Entry"); - } -} +} \ No newline at end of file diff --git a/src/main/java/trap/model/RoundScore.java b/src/main/java/trap/model/RoundScore.java index e344765d..dd798a90 100644 --- a/src/main/java/trap/model/RoundScore.java +++ b/src/main/java/trap/model/RoundScore.java @@ -27,10 +27,14 @@ public class RoundScore { String type; public String getUniqueName() { - return this.getAthlete() + " " + this.getTeam() + " " + this.getClassification() + " " + this.getType(); + return String.format("%s %s %s %s", athlete, team, getSimplifiedTeamClassification(), type); } - public String getTeamClassification() { - return this.classification.replace("Senior/Varsity", "Varsity").replace("Senior/Jr. Varsity", "Junior Varsity").replace("Intermediate/Advanced", "Intermediate Advanced").replace("Intermediate/Entry Level", "Intermediate Entry"); + public String getSimplifiedTeamClassification() { + return switch (classification) { + case "Senior/Varsity", "Senior/Jr. Varsity", "Junior Varsity" -> "Varsity"; + case "Intermediate/Advanced", "Intermediate/Entry Level" -> "Intermediate Entry"; + default -> classification; + }; } } diff --git a/src/main/java/trap/model/RoundTotal.java b/src/main/java/trap/model/RoundTotal.java index 891acd05..12a5f46e 100644 --- a/src/main/java/trap/model/RoundTotal.java +++ b/src/main/java/trap/model/RoundTotal.java @@ -16,6 +16,6 @@ public class RoundTotal { String type; public String getUniqueName() { - return this.getAthlete() + " " + this.getTeam() + " " + this.getClassification() + " " + this.getType(); + return String.format("%s %s %s %s", athlete, team, classification, type); } -} +} \ No newline at end of file diff --git a/src/main/java/trap/report/ReportHelper.java b/src/main/java/trap/report/ReportHelper.java index 8f62c68c..40218fab 100644 --- a/src/main/java/trap/report/ReportHelper.java +++ b/src/main/java/trap/report/ReportHelper.java @@ -223,7 +223,7 @@ private void populateTeamData(Sheet sheet, String teamType, CellStyle mainTextSt int startColumn = 1; long start = System.currentTimeMillis(); - List>> teamData = teamScoresByTotal.entrySet().stream().filter(f -> f.getValue().getFirst().getTeamClassificationForTotal().equals(teamType) && f.getValue().getFirst().getType().equals(SINGLES)).toList(); + List>> teamData = teamScoresByTotal.entrySet().stream().filter(f -> f.getValue().getFirst().getTeamClassification().equals(teamType) && f.getValue().getFirst().getType().equals(SINGLES)).toList(); List teamScores = getTeamScores(teamData); logger.info("Ran query for singles by {} in {} ms", teamType, System.currentTimeMillis() - start); for (var teamScore : teamScores) { @@ -238,7 +238,7 @@ private void populateTeamData(Sheet sheet, String teamType, CellStyle mainTextSt for (var type : types) { updateRow = rows; start = System.currentTimeMillis(); - teamData = teamScoresByTotal.entrySet().stream().filter(f -> f.getValue().getFirst().getTeamClassificationForTotal().equals(teamType) && f.getValue().getFirst().getType().equals(type)).toList(); + teamData = teamScoresByTotal.entrySet().stream().filter(f -> f.getValue().getFirst().getTeamClassification().equals(teamType) && f.getValue().getFirst().getType().equals(type)).toList(); teamScores = getTeamScores(teamData); logger.info("Ran query for {} by {} in {} ms", type, teamType, System.currentTimeMillis() - start); for (var teamScore : teamScores) {