@@ -191,33 +191,34 @@ public Collection<FilmDto> showRecommendations(long id) {
191
191
Set <Film > userLikedFilms = usersLikedFilms .get (id );
192
192
Map <Long , Integer > userFilmIdRating = usersLikes .get (id );
193
193
for (Long userId : usersLikes .keySet ()) {
194
- if (userId != id ) {
195
- Set <Film > sameFilms = new HashSet <>();
196
- Set <Film > anotherUserLikedFilms = usersLikedFilms .get (userId );
197
- for (Film film : anotherUserLikedFilms ) {
198
- Film sameFilm ;
199
- Optional <Film > optionalFilm = userLikedFilms .stream ().filter (f -> f .getId () == film .getId ()).findFirst ();
200
- if (optionalFilm .isEmpty ()) {
201
- continue ;
202
- } else {
203
- sameFilm = optionalFilm .get ();
204
- }
205
- long filmId = sameFilm .getId ();
206
- Map <Long , Integer > anotherUserFilmIdRating = usersLikes .get (userId );
207
- if ((userFilmIdRating .get (filmId ) >= positiveRating && anotherUserFilmIdRating .get (filmId ) >= positiveRating ) ||
208
- (userFilmIdRating .get (filmId ) < positiveRating && anotherUserFilmIdRating .get (filmId ) < positiveRating ))
209
- sameFilms .add (film );
210
- }
211
- if (sameFilms .size () > maxLikes && sameFilms .size () < anotherUserLikedFilms .size ()) {
212
- recommendations .clear ();
213
- maxLikes = sameFilms .size ();
214
- anotherUserLikedFilms .removeAll (sameFilms );
215
- recommendations .addAll (anotherUserLikedFilms );
216
- }
217
- if (userLikedFilms .size () == maxLikes ) {
218
- anotherUserLikedFilms .removeAll (sameFilms );
219
- recommendations .addAll (anotherUserLikedFilms );
194
+ if (userId == id ) {
195
+ continue ;
196
+ }
197
+ Set <Film > sameFilms = new HashSet <>();
198
+ Set <Film > anotherUserLikedFilms = usersLikedFilms .get (userId );
199
+ for (Film film : anotherUserLikedFilms ) {
200
+ Film sameFilm ;
201
+ Optional <Film > optionalFilm = userLikedFilms .stream ().filter (f -> f .getId () == film .getId ()).findFirst ();
202
+ if (optionalFilm .isEmpty ()) {
203
+ continue ;
204
+ } else {
205
+ sameFilm = optionalFilm .get ();
220
206
}
207
+ long filmId = sameFilm .getId ();
208
+ Map <Long , Integer > anotherUserFilmIdRating = usersLikes .get (userId );
209
+ if ((userFilmIdRating .get (filmId ) >= positiveRating && anotherUserFilmIdRating .get (filmId ) >= positiveRating ) ||
210
+ (userFilmIdRating .get (filmId ) < positiveRating && anotherUserFilmIdRating .get (filmId ) < positiveRating ))
211
+ sameFilms .add (film );
212
+ }
213
+ if (sameFilms .size () > maxLikes && sameFilms .size () < anotherUserLikedFilms .size ()) {
214
+ recommendations .clear ();
215
+ maxLikes = sameFilms .size ();
216
+ anotherUserLikedFilms .removeAll (sameFilms );
217
+ recommendations .addAll (anotherUserLikedFilms );
218
+ }
219
+ if (userLikedFilms .size () == maxLikes ) {
220
+ anotherUserLikedFilms .removeAll (sameFilms );
221
+ recommendations .addAll (anotherUserLikedFilms );
221
222
}
222
223
}
223
224
if (recommendations .isEmpty ()) {
@@ -228,7 +229,9 @@ public Collection<FilmDto> showRecommendations(long id) {
228
229
.map (Film ::getId )
229
230
.collect (Collectors .toSet ());
230
231
231
- return filmStorage .findFilmsByIds (recommendedFilmsId ).stream ().map (FilmMapper ::toDto ).collect (Collectors .toList ());
232
+ return filmStorage .findFilmsByIds (recommendedFilmsId ).stream ()
233
+ .map (FilmMapper ::toDto )
234
+ .collect (Collectors .toList ());
232
235
}
233
236
234
237
/**
0 commit comments