When I manage to recall the contructor from the Teams class (which store the List<Players>
in it) is obvs null
. Where do I populate that List? Do I need to populate it inside the Players class? Or inside the Team class?
I am working with Spring recently.
I'll leave the examples of the 3 class. Squadre means Teams, Giocatori means Players. (using lombok)
public class Squadra {
private String nomeSquadra;
private List<Giocatori> rosaAttuale;
private int goalFatti;
private int goalSubiti;
private int differenzaReti;
private int posizioneInCampionato;
private double valoreRosa;
public void addGiocatori(Giocatori g) {
rosaAttuale.add(g);
}
public void removeGiocatori(Giocatori g) {
rosaAttuale.remove(g);
}
}
public class Giocatori {
String nomeGiocatore;
String cognomeGiocatore;
int eta;
int numeroMaglia;
public Giocatori() {
}
}
@Component
public class SquadreRepo {
@Getter
private List<Squadra> dataBaseSquadre = new ArrayList<Squadra>();
public SquadreRepo() {
dataBaseSquadre.add(new Squadra(null, null, 0, 0, 0, 0, 0))
}
public void addSquadra(Squadra s) {
dataBaseSquadre.add(s);
}
public void removeSquadra(Squadra s) {
dataBaseSquadre.remove(s);
}
}