.
:
List<Team> sorted = table.values().stream()
.sorted(Comparator.comparing(Team::getPoints)
.thenComparing(Team::goalDifference)
.reversed()
.thenComparing(Team::getName))
.collect(Collectors.toList());
String table = IntStream.range(0, sorted.size())
.mapToObj(i -> String.format("%2d%s %-15s%5d%5d%5d%5d%5d",
i, ".",
sorted.get(i).getName(),
sorted.get(i).getPlayed(),
sorted.get(i).getWins(),
sorted.get(i).getDraws(),
sorted.get(i).getLosses(),
sorted.get(i).getPoints()))
.collect(Collectors.joining("\n"));
, Team
, :
public String formatWithPosition(int position) {
return String.format("%2d%s %-15s%5d%5d%5d%5d%5d",
position, ".",
name, played, wins, draws, losses, points);
}
:
String table = IntStream.range(0, sorted.size())
.mapToObj(Team::formatWithPosition)
.collect(Collectors.joining("\n"));