public void visitRentals(RentalVisitor visitor) {
   for (RentalDTO r : rentalService.getAllRentals()) {
     UserDTO user = userService.getUserById(r.getUserId());
     MovieDTO movie = movieService.getMovieById(r.getMovieId());
     visitor.visit(
         r.getId(),
         r.getRentalDays(),
         r.getRentalDate(),
         user.getLastName(),
         user.getFirstName(),
         movie.getTitle(),
         r.getRemainingDays(),
         r.getRentalFee());
   }
 }
 public void visitRentalsOfUser(Long userId, RentalVisitor visitor) {
   UserDTO user = userService.getUserById(userId);
   for (Long id : user.getRentalIds()) {
     RentalDTO r = rentalService.getRentalById(id);
     MovieDTO movie = movieService.getMovieById(r.getMovieId());
     visitor.visit(
         r.getId(),
         r.getRentalDays(),
         r.getRentalDate(),
         user.getLastName(),
         user.getFirstName(),
         movie.getTitle(),
         r.getRemainingDays(),
         r.getRentalFee());
   }
 }
 private MovieDTO getMovie(Long id) {
   if (movie == null || !movie.getId().equals(id)) {
     movie = movieService.getMovieById(id);
   }
   return movie;
 }
 public void visitMovies(MovieVisitor visitor) {
   for (MovieDTO m : movieService.getAllMovies()) {
     visitor.visit(
         m.getId(), m.getTitle(), m.getReleaseDate(), m.isRented(), m.getPriceCategory());
   }
 }
 public void updateMovie(Long movieId, String movieTitle, Date date, String category) {
   MovieDTO movie = getMovie(movieId);
   movie = new MovieDTO(movieId, movieTitle, movie.isRented(), date, category);
   movieService.saveOrUpdateMovie(movie);
   invalidateCache();
 }