Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mergeFilmlist by attributes (sender,title,thema, ect) #160

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 58 additions & 8 deletions src/main/java/de/mediathekview/mlib/daten/Film.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ > getUrls().get(urlEntry.getKey()).getFileSize())
return this;
}

public Film merge(final Film objToMergeWith) {
merge((AbstractMediaResource<FilmUrl>) objToMergeWith);
objToMergeWith.getAudioDescriptions().forEach(audioDescriptions::putIfAbsent);
objToMergeWith.getSignLanguages().forEach(signLanguages::putIfAbsent);
subtitles.addAll(objToMergeWith.getSubtitles());
return this;
}

public void addAllSubtitleUrls(final Set<URL> urlsToAdd) {
subtitles.addAll(urlsToAdd);
}
Expand Down Expand Up @@ -154,4 +146,62 @@ public int hashCode() {
public boolean hasUT() {
return !subtitles.isEmpty();
}

public static void addAllToFilmlist(final Filmlist source,final Filmlist target) {
target.addAllFilms(source.getFilms().values());
target.addAllLivestreams(source.getLivestreams().values());
target.addAllPodcasts(source.getPodcasts().values());
}

public static Filmlist mergeTwoFilmlists(final Filmlist aThis, final Filmlist aFilmlist) {
final Filmlist toBeAdded = new Filmlist(UUID.randomUUID(), LocalDateTime.now());
final Filmlist diff = new Filmlist(UUID.randomUUID(), LocalDateTime.now());
// add all from old list not in the new list
aFilmlist.getFilms().entrySet().stream()
.filter(e -> !containsFilm(aThis, e.getValue()))
.forEachOrdered(e -> toBeAdded.getFilms().put(e.getKey(), e.getValue()));
// the diff list contains all new entries (fresh list) which are not already in the old list
aThis.getFilms().entrySet().stream()
.filter(e -> !containsFilm(aFilmlist,e.getValue()))
.forEachOrdered(e -> diff.getFilms().put(e.getKey(), e.getValue()));
// add the history to the current list
aThis.getFilms().putAll(toBeAdded.getFilms());
//
// the same for podcast
aFilmlist.getPodcasts().entrySet().stream()
.filter(e -> !containsPodcast(aThis,e.getValue()))
.forEachOrdered(e -> toBeAdded.getPodcasts().put(e.getKey(), e.getValue()));
aThis.getPodcasts().entrySet().stream()
.filter(e -> !containsPodcast(aFilmlist,e.getValue()))
.forEachOrdered(e -> diff.getPodcasts().put(e.getKey(), e.getValue()));
aThis.getPodcasts().putAll(toBeAdded.getPodcasts());
//
return diff;
}

public static boolean containsFilm(Filmlist athis, Film film) {
Optional<Film> check = athis.getFilms().entrySet().stream()
.filter(entry ->
film.getTitel().equalsIgnoreCase(entry.getValue().getTitel()) &&
film.getThema().equalsIgnoreCase(entry.getValue().getThema()) &&
film.getSender().equals(entry.getValue().getSender()) &&
film.getDuration().equals(entry.getValue().getDuration()))
.map(Map.Entry::getValue)
.findFirst();

return check.isPresent();
}

public static boolean containsPodcast(Filmlist athis, Podcast prodcast) {
Optional<Podcast> check = athis.getPodcasts().entrySet().stream()
.filter(entry ->
prodcast.getTitel().equalsIgnoreCase(entry.getValue().getTitel()) &&
prodcast.getThema().equalsIgnoreCase(entry.getValue().getThema()) &&
prodcast.getSender().equals(entry.getValue().getSender()) &&
prodcast.getDuration().equals(entry.getValue().getDuration()))
.map(Map.Entry::getValue)
.findFirst();

return check.isPresent();
}
}
Loading