Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,37 @@ private boolean isTeamsTie() {
int referencePoints = teams.get(0).getTotalPoints();
return teams.stream().allMatch(team -> team.getTotalPoints() == referencePoints);
}

/**
* @param battleHostName name of host to search
* @return Team instance containing name of host or null if no team found */
public Team getTeam(String battleHostName) {
List<Team> list = getTeams(battleHostName);
return list.isEmpty() ? null : list.get(0);
}

/**
* @param battleHostName name of host to search
* @return Team instances not containing name of host */
public List<Team> getOpponentTeams(String battleHostName) {
List<Team> list = getTeams(battleHostName);
return list.isEmpty() ? null : list;
}

/**
* @param battleHostName name of host to search
* @return {@link List<Team>} with host team first, then opponent teams
* <p> If host is in neither or teams is empty, returns empty
* <p> Otherwise always teams.length in length;
*/
public List<Team> getTeams(String battleHostName) {
if (teams.isEmpty() || teams.stream().noneMatch(team -> team.contains(battleHostName)))
return Collections.EMPTY_LIST;
Team hostTeam = teams.stream().filter(team -> team.contains(battleHostName)).findFirst().orElseThrow();
List<Team> opponentTeams = teams.stream().filter(team -> !team.contains(battleHostName)).toList();
List<Team> teams = new ArrayList<>();
teams.add(hostTeam);
teams.addAll(opponentTeams);
return teams;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@ public Team(WebcastLinkMicBattle.BattleUserInfo anchorInfo, WebcastLinkMicBattle
this(anchorInfo);
this.winStreak = (int) battleCombo.getComboCount();
}

public boolean contains(String name) {
return hosts.stream().anyMatch(user -> user.getName().equals(name));
}
}