From 700239934f3757cd18f67e3e68393381fd6c499f Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 19 Feb 2017 00:41:36 +0800 Subject: [PATCH] Refactor EpisodeMetrics --- .../filebot/similarity/EpisodeMetrics.java | 70 +++++++------------ 1 file changed, 27 insertions(+), 43 deletions(-) diff --git a/source/net/filebot/similarity/EpisodeMetrics.java b/source/net/filebot/similarity/EpisodeMetrics.java index cd18816c..6d8c001f 100644 --- a/source/net/filebot/similarity/EpisodeMetrics.java +++ b/source/net/filebot/similarity/EpisodeMetrics.java @@ -92,25 +92,16 @@ public enum EpisodeMetrics implements SimilarityMetric { @Override public SimpleDate parse(Object object) { + if (object instanceof Episode) { + Episode episode = (Episode) object; + return episode.getAirdate(); + } + if (object instanceof Movie) { return null; } - if (object instanceof Episode) { - Episode episode = (Episode) object; - - // use airdate from episode - return episode.getAirdate(); - } - - SimpleDate result = transformCache.get(object); - if (result != null) { - return result; - } - - result = super.parse(object); - transformCache.put(object, result); - return result; + return transformCache.computeIfAbsent(object, super::parse); } }), @@ -717,38 +708,31 @@ public enum EpisodeMetrics implements SimilarityMetric { return ""; } - String result = transformCache.get(object); - if (result != null) { - return result; - } + return transformCache.computeIfAbsent(object, o -> { + String name = normalizeFileName(o); - String name; + // remove checksums, any [...] or (...) + name = removeEmbeddedChecksum(name); + + // remove obvious release info + name = stripFormatInfo(name); + + synchronized (transliterator) { + name = transliterator.transform(name); + } + + // remove or normalize special characters + return normalizePunctuation(name).toLowerCase(); + }); + } + + private static String normalizeFileName(Object object) { if (object instanceof File) { - name = getName((File) object); + return getName((File) object); } else if (object instanceof FileInfo) { - name = ((FileInfo) object).getName(); - } else { - name = object.toString(); + return ((FileInfo) object).getName(); } - - // remove checksums, any [...] or (...) - name = removeEmbeddedChecksum(name); - - // remove obvious release info - name = stripFormatInfo(name); - - synchronized (transliterator) { - name = transliterator.transform(name); - } - - // remove or normalize special characters - name = normalizePunctuation(name); - - // normalize to lower case - name = name.toLowerCase(); - - transformCache.put(object, name); - return name; + return object.toString(); } public static SimilarityMetric[] defaultSequence(boolean includeFileMetrics) {