Refactor Ep\EpisodeMetrics

This commit is contained in:
Reinhard Pointner 2016-08-17 15:23:09 +08:00
parent 13e6360c4d
commit 800d61543b
1 changed files with 29 additions and 28 deletions

View File

@ -55,37 +55,38 @@ public enum EpisodeMetrics implements SimilarityMetric {
return emptySet(); return emptySet();
} }
Collection<SxE> result = transformCache.get(object); return transformCache.computeIfAbsent(object, key -> {
if (result != null) {
return result;
}
if (object instanceof Episode) { if (object instanceof Episode) {
Episode episode = (Episode) object; Episode episode = (Episode) object;
return parse(episode);
}
return super.parse(object);
});
}
private Set<SxE> parse(Episode e) {
// get SxE from episode, both SxE for season/episode numbering and SxE for absolute episode numbering // get SxE from episode, both SxE for season/episode numbering and SxE for absolute episode numbering
Set<SxE> sxe = new HashSet<SxE>(2); Set<SxE> sxe = new HashSet<SxE>(2);
// default SxE numbering // default SxE numbering
if (episode.getEpisode() != null) { if (e.getEpisode() != null) {
sxe.add(new SxE(episode.getSeason(), episode.getEpisode())); sxe.add(new SxE(e.getSeason(), e.getEpisode()));
}
// absolute numbering // absolute numbering
if (episode.getAbsolute() != null) { if (e.getAbsolute() != null) {
sxe.add(new SxE(null, episode.getAbsolute())); sxe.add(new SxE(null, e.getAbsolute()));
} }
// 0xSpecial numbering
if (episode.getSpecial() != null) {
sxe.add(new SxE(0, episode.getSpecial()));
}
result = sxe;
} else { } else {
result = super.parse(object); // 0xSpecial numbering
if (e.getSpecial() != null) {
sxe.add(new SxE(0, e.getSpecial()));
}
} }
transformCache.put(object, result); return sxe;
return result;
} }
}), }),
// Match episode airdate // Match episode airdate