diff --git a/src/main/java/cz/fi/muni/pa165/seminar4/group7/secretservice/entity/Country.java b/src/main/java/cz/fi/muni/pa165/seminar4/group7/secretservice/entity/Country.java index 08a3079b2af14343782f8265056191bbb68ae2bb..d8cbfaf16bf4eddcda542993b75dd39734387a48 100644 --- a/src/main/java/cz/fi/muni/pa165/seminar4/group7/secretservice/entity/Country.java +++ b/src/main/java/cz/fi/muni/pa165/seminar4/group7/secretservice/entity/Country.java @@ -1,90 +1,85 @@ package cz.fi.muni.pa165.seminar4.group7.secretservice.entity; import com.sun.istack.NotNull; +import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; +import lombok.experimental.Accessors; import javax.persistence.*; -import java.util.List; +import java.util.HashSet; import java.util.Objects; +import java.util.Set; /** * @author Milan Mozolak */ @Entity +@Getter +@Setter +@Accessors(chain = true) public class Country { @Id @Column(name = "id", nullable = false) @GeneratedValue(strategy = GenerationType.IDENTITY) - @Getter - @Setter private Long id; @NotNull @Column(nullable = false) - @Getter - @Setter private String code; @NotNull @Column(nullable = false) - @Getter - @Setter private String name; @NotNull @Column(nullable = false) - @Getter - @Setter private String demographics; @NotNull @Column(nullable = false) - @Getter - @Setter private String geography; @NotNull @Column(nullable = false) - @Getter - @Setter private String communications; @NotNull @Column(nullable = false) - @Getter - @Setter private String government; @NotNull @Column(nullable = false) - @Getter - @Setter private String economy; @NotNull @Column(nullable = false) - @Getter - @Setter private String military; - @Getter - @Setter + @Setter(AccessLevel.NONE) @OneToMany(mappedBy = "country") - private List missions; + private Set missions = new HashSet<>(); + + public void addMission(Mission mission) { + missions.add(mission); + mission.setCountry(this); + } + + public void removeMission(Mission mission) { + missions.remove(mission); + mission.setCountry(null); + } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - Country country = (Country) o; - - return id.equals(country.id) && code.equals(country.code); + return code.equals(country.code); } @Override public int hashCode() { - return Objects.hash(id, code); + return Objects.hash(code); } }