Skip to content

Commit

Permalink
variables for names and loop over entrySet()
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbusche committed Oct 2, 2024
1 parent 4d201d8 commit cf8ff24
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
20 changes: 10 additions & 10 deletions src/main/java/trap/report/ReportHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@

@Service
public class ReportHelper {
private static final String SINGLES = "singles";
private static final String DOUBLES = "doubles";
private static final String HANDICAP = "handicap";
private static final String SKEET = "skeet";
private static final String CLAYS = "clays";
private static final String FIVESTAND = "fivestand";
private static final String DOUBLESKEET = "doublesskeet";
public static final String SINGLES = "singles";
public static final String DOUBLES = "doubles";
public static final String HANDICAP = "handicap";
public static final String SKEET = "skeet";
public static final String CLAYS = "clays";
public static final String FIVESTAND = "fivestand";
public static final String DOUBLESKEET = "doublesskeet";
private static final String ROOKIE = "Rookie";
private static final String VARSITY = "Varsity";
private static final String INTERMEDIATE_ENTRY = "Intermediate Entry";
Expand All @@ -56,7 +56,7 @@ public class ReportHelper {
Logger logger = LoggerFactory.getLogger(ReportHelper.class);

public void generateExcelFile() throws Exception {
downloadHelper.downloadFiles(trapTypes);
// downloadHelper.downloadFiles(trapTypes);

var workbook = getWorkbook();

Expand Down Expand Up @@ -346,8 +346,8 @@ private HashMap<String, ArrayList<IndividualTotal>> calculateTeamScores(List<Ind
}

// Process each team to handle ties for 5th place
for (var team : teamScoresThatCount.keySet()) {
var currentTeam = teamScoresThatCount.get(team);
for (var team : teamScoresThatCount.entrySet()) {
var currentTeam = team.getValue();

// Sort the team scores in descending order based on the 'total' field
currentTeam.sort((a, b) -> Integer.compare(b.getTotal(), a.getTotal()));
Expand Down
42 changes: 25 additions & 17 deletions src/main/java/trap/report/TrapHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
import java.util.Map;
import java.util.Set;

import static trap.report.ReportHelper.CLAYS;
import static trap.report.ReportHelper.DOUBLES;
import static trap.report.ReportHelper.DOUBLESKEET;
import static trap.report.ReportHelper.FIVESTAND;
import static trap.report.ReportHelper.HANDICAP;
import static trap.report.ReportHelper.SINGLES;
import static trap.report.ReportHelper.SKEET;

public class TrapHelper {
private static final Map<String, Integer> eventCounts = determineEventsToCount();
public static final Map<String, Integer> roundCounts = determineRoundsToCount();
protected static final Map<String, Integer> roundCounts = determineRoundsToCount();

public Map<String, List<RoundTotal>> calculatePlayerRoundTotals(List<RoundScore> roundScores) {
Map<String, List<RoundTotal>> playerRoundTotals = new HashMap<>();
Expand Down Expand Up @@ -134,19 +142,19 @@ public Map<String, IndividualTotal> calculatePlayerFinalTotal(Map<String, List<I
}

public boolean singleRound(String roundType) {
Set<String> validRounds = Set.of("clays", "doubles", "doublesskeet", "fivestand");
Set<String> validRounds = Set.of(CLAYS, DOUBLES, DOUBLESKEET, FIVESTAND);
return validRounds.contains(roundType);
}

private static Map<String, Integer> determineEventsToCount() {
var eventCounts = new HashMap<String, Integer>();
eventCounts.put("singles", 4);
eventCounts.put("doubles", 4);
eventCounts.put("handicap", 4);
eventCounts.put("skeet", 4);
eventCounts.put("clays", 3);
eventCounts.put("fivestand", 4);
eventCounts.put("doublesskeet", 4);
eventCounts.put(SINGLES, 4);
eventCounts.put(DOUBLES, 4);
eventCounts.put(HANDICAP, 4);
eventCounts.put(SKEET, 4);
eventCounts.put(CLAYS, 3);
eventCounts.put(FIVESTAND, 4);
eventCounts.put(DOUBLESKEET, 4);
return eventCounts;
}

Expand All @@ -160,14 +168,14 @@ public static String trimString(String s) {

private static Map<String, Integer> determineRoundsToCount() {
var roundCounts = new HashMap<String, Integer>();
roundCounts.put("singles", 5);
roundCounts.put("doubles", 5);
roundCounts.put("handicap", 5);

roundCounts.put("skeet", 3);
roundCounts.put("clays", 3);
roundCounts.put("fivestand", 3);
roundCounts.put("doublesskeet", 3);
roundCounts.put(SINGLES, 5);
roundCounts.put(DOUBLES, 5);
roundCounts.put(HANDICAP, 5);

roundCounts.put(SKEET, 3);
roundCounts.put(CLAYS, 3);
roundCounts.put(FIVESTAND, 3);
roundCounts.put(DOUBLESKEET, 3);
return roundCounts;
}

Expand Down

0 comments on commit cf8ff24

Please sign in to comment.