-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRound.java
More file actions
74 lines (62 loc) · 1.66 KB
/
Round.java
File metadata and controls
74 lines (62 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package cat.udl.eps.softarch.fll.domain;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;
@Entity
@Table(name = "rounds")
@Getter
@Setter
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true)
public class Round extends UriEntity<Long> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@EqualsAndHashCode.Include
private Long id;
@Column(unique = true)
private int number;
@OneToMany(mappedBy = "round", cascade = CascadeType.ALL, orphanRemoval = true)
@JsonManagedReference("round-matches")
@Setter(lombok.AccessLevel.NONE)
private List<Match> matches = new ArrayList<>();
public void setMatches(List<Match> matches) {
this.matches.clear();
if (matches != null) {
matches.forEach(this::addMatch);
}
}
public void addMatch(Match match) {
if (match == null) {
return;
}
if (matches.contains(match)) {
return;
}
Round previousRound = match.getRound();
if (previousRound != null && previousRound != this) {
previousRound.removeMatch(match);
}
matches.add(match);
match.setRound(this);
}
public void removeMatch(Match match) {
if (match == null) {
return;
}
if (matches.remove(match)) {
match.setRound(null);
}
}
}