Changeset 7fafead in Git for src/main/java/com/wediscussmovies/project/model/Movie.java
- Timestamp:
- 01/16/22 20:22:55 (3 years ago)
- Branches:
- main
- Children:
- 3ded84d
- Parents:
- 2d57cad (diff), 7bc8942 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/wediscussmovies/project/model/Movie.java
r2d57cad r7fafead 1 1 package com.wediscussmovies.project.model; 2 3 import lombok.Data; 2 4 3 5 import javax.persistence.*; 4 6 import java.sql.Date; 5 7 import java.util.Collection; 8 import java.util.Comparator; 9 import java.util.List; 6 10 import java.util.Objects; 11 7 12 8 13 @Entity 9 14 @Table(name = "movies", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies") 15 @Data 10 16 public class Movie { 17 11 18 @GeneratedValue(strategy = GenerationType.IDENTITY) 12 19 @Id 13 20 @Column(name = "movie_id") 14 private int movieId; 15 @Basic 16 @Column(name = "title") 21 private Long id; 22 17 23 private String title; 18 @Basic 19 @Column(name = "description") 24 20 25 private String description; 21 @Basic 26 22 27 @Column(name = "image_url") 23 28 private String imageUrl; 24 @Basic 29 30 25 31 @Column(name = "airing_date") 26 private Date a iringDate;27 @Basic 32 private Date aringDate; 33 28 34 @Column(name = "imdb_rating") 29 private Double im dbRating;30 @Basic 31 @ Column(name = "director_id")32 private Integer directorId;33 @OneToMany(mappedBy = "moviesByMovieId") 34 private Collection<Discussion> discussionsByMovieId;35 @OneToMany(mappedBy = "moviesByMovieId")36 private Collection<MovieActorsEntity> movieActorsByMovieId; 37 @ OneToMany(mappedBy = "moviesByMovieId")38 private Collection<MovieGenresEntity> movieGenresByMovieId;39 @OneToMany(mappedBy = "moviesByMovieId") 40 private Collection<MovieLikesEntity> movieLikesByMovieId; 41 @OneToMany(mappedBy = "moviesByMovieId") 42 private Collection<MovieRatesEntity> movieRatesByMovieId; 35 private Double imbdRating; 36 37 @ManyToMany 38 private List<Genre> genres; 39 40 @ManyToMany 41 private List<Person> likes; 42 43 @ManyToMany 44 private List<Person> actors; 45 46 47 48 43 49 @ManyToOne 44 @JoinColumn(name = "director_id" , referencedColumnName = "person_id",insertable = false, updatable = false)45 private Person personsByDirectorId;50 @JoinColumn(name = "director_id") 51 private Person director; 46 52 47 public int getMovieId() { 48 return movieId; 53 54 55 56 57 58 public boolean isFromGenre(Genre genre){ 59 60 return genres 61 .stream() 62 .anyMatch(g -> Objects.equals(g.getId(), genre.getId())); 63 64 } 65 public boolean hasActor(Person p){ 66 return 67 actors 68 .stream() 69 .anyMatch(a -> Objects.equals(a.getPersonId(), p.getPersonId())); 70 71 49 72 } 50 73 51 public void setMovieId(int movieId){52 this.movieId = movieId;74 public boolean isDirectedBy(Person p){ 75 return Objects.equals(director.getPersonId(), p.getPersonId()); 53 76 } 54 77 55 public String getTitle() { 56 return title; 57 } 78 public static Comparator<Movie> comparatorTitle = Comparator.comparing(Movie::getTitle); 58 79 59 public void setTitle(String title) {60 this.title = title;61 }62 80 63 public String getDescription() { 64 return description; 65 } 81 public Movie( String title, String description, String imageUrl, Date aringDate, Double imbdRating,Person director, List<Person> actors, List<Genre> genres) { 66 82 67 public void setDescription(String description) {68 this.description = description;69 }70 71 public String getImageUrl() {72 return imageUrl;73 }74 75 public void setImageUrl(String imageUrl) {76 this.imageUrl = imageUrl;77 }78 79 public Date getAiringDate() {80 return airingDate;81 }82 83 public void setAiringDate(Date airingDate) {84 this.airingDate = airingDate;85 }86 87 public Double getImdbRating() {88 return imdbRating;89 }90 91 public void setImdbRating(Double imdbRating) {92 this.imdbRating = imdbRating;93 }94 95 public Integer getDirectorId() {96 return directorId;97 }98 99 public void setDirectorId(Integer directorId) {100 this.directorId = directorId;101 }102 103 @Override104 public boolean equals(Object o) {105 if (this == o) return true;106 if (o == null || getClass() != o.getClass()) return false;107 108 Movie that = (Movie) o;109 110 if (movieId != that.movieId) return false;111 if (!Objects.equals(title, that.title)) return false;112 if (!Objects.equals(description, that.description)) return false;113 if (!Objects.equals(imageUrl, that.imageUrl)) return false;114 if (!Objects.equals(airingDate, that.airingDate)) return false;115 if (!Objects.equals(imdbRating, that.imdbRating)) return false;116 if (!Objects.equals(directorId, that.directorId)) return false;117 118 return true;119 }120 121 public Movie(String title, String description, String imageUrl, Date airingDate, Double imdbRating, Integer directorId) {122 83 this.title = title; 123 84 this.description = description; 124 85 this.imageUrl = imageUrl; 125 this.airingDate = airingDate; 126 this.imdbRating = imdbRating; 127 this.directorId = directorId; 86 this.aringDate = aringDate; 87 this.imbdRating = imbdRating; 88 this.genres = genres; 89 this.likes = likes; 90 this.actors = actors; 91 this.director = director; 128 92 } 129 93 … … 131 95 } 132 96 133 @Override134 public int hashCode() {135 int result = movieId;136 result = 31 * result + (title != null ? title.hashCode() : 0);137 result = 31 * result + (description != null ? description.hashCode() : 0);138 result = 31 * result + (imageUrl != null ? imageUrl.hashCode() : 0);139 result = 31 * result + (airingDate != null ? airingDate.hashCode() : 0);140 result = 31 * result + (imdbRating != null ? imdbRating.hashCode() : 0);141 result = 31 * result + (directorId != null ? directorId.hashCode() : 0);142 return result;143 }144 97 145 public Collection<Discussion> getDiscussionsByMovieId() {146 return discussionsByMovieId;147 }148 149 public void setDiscussionsByMovieId(Collection<Discussion> discussionsByMovieId) {150 this.discussionsByMovieId = discussionsByMovieId;151 }152 153 public Collection<MovieActorsEntity> getMovieActorsByMovieId() {154 return movieActorsByMovieId;155 }156 157 public void setMovieActorsByMovieId(Collection<MovieActorsEntity> movieActorsByMovieId) {158 this.movieActorsByMovieId = movieActorsByMovieId;159 }160 161 public Collection<MovieGenresEntity> getMovieGenresByMovieId() {162 return movieGenresByMovieId;163 }164 165 public void setMovieGenresByMovieId(Collection<MovieGenresEntity> movieGenresByMovieId) {166 this.movieGenresByMovieId = movieGenresByMovieId;167 }168 169 public Collection<MovieLikesEntity> getMovieLikesByMovieId() {170 return movieLikesByMovieId;171 }172 173 public void setMovieLikesByMovieId(Collection<MovieLikesEntity> movieLikesByMovieId) {174 this.movieLikesByMovieId = movieLikesByMovieId;175 }176 177 public Collection<MovieRatesEntity> getMovieRatesByMovieId() {178 return movieRatesByMovieId;179 }180 181 public void setMovieRatesByMovieId(Collection<MovieRatesEntity> movieRatesByMovieId) {182 this.movieRatesByMovieId = movieRatesByMovieId;183 }184 185 public Person getPersonsByDirectorId() {186 return personsByDirectorId;187 }188 189 public void setPersonsByDirectorId(Person personsByDirectorId) {190 this.personsByDirectorId = personsByDirectorId;191 }192 98 }
Note:
See TracChangeset
for help on using the changeset viewer.