1 changed files with 42 additions and 0 deletions
@ -0,0 +1,42 @@ |
|||||
|
package project.analysis; |
||||
|
|
||||
|
import project.bean.Movie; |
||||
|
|
||||
|
import java.util.*; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
public class MovieAnalyzer { |
||||
|
public static Map<Double, Long> getRatingDistribution(List<Movie> movies) { |
||||
|
return movies.stream() |
||||
|
.collect(Collectors.groupingBy(Movie::getRating, Collectors.counting())); |
||||
|
} |
||||
|
|
||||
|
public static Map<Integer, Double> getYearRatingCorrelation(List<Movie> movies) { |
||||
|
return movies.stream() |
||||
|
.collect(Collectors.groupingBy(Movie::getYear, |
||||
|
Collectors.averagingDouble(Movie::getRating))); |
||||
|
} |
||||
|
|
||||
|
public static Map<String, Long> getDirectorMovieCount(List<Movie> movies) { |
||||
|
return movies.stream() |
||||
|
.collect(Collectors.groupingBy(Movie::getDirector, Collectors.counting())) |
||||
|
.entrySet().stream() |
||||
|
.filter(entry -> entry.getValue() > 1) |
||||
|
.sorted(Map.Entry.<String, Long>comparingByValue().reversed()) |
||||
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); |
||||
|
} |
||||
|
|
||||
|
public static double getAverageRating(List<Movie> movies) { |
||||
|
return movies.stream() |
||||
|
.mapToDouble(Movie::getRating) |
||||
|
.average() |
||||
|
.orElse(0.0); |
||||
|
} |
||||
|
|
||||
|
public static List<Movie> getTopRatedMovies(List<Movie> movies, int count) { |
||||
|
return movies.stream() |
||||
|
.sorted(Comparator.comparingDouble(Movie::getRating).reversed()) |
||||
|
.limit(count) |
||||
|
.collect(Collectors.toList()); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue