From d84b11a850d9b2afe12385aa4f8138e1d915123c Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 10 Feb 2016 18:32:34 +0000 Subject: [PATCH] Optimize DateMatcher --- .../net/filebot/similarity/DateMatcher.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/source/net/filebot/similarity/DateMatcher.java b/source/net/filebot/similarity/DateMatcher.java index 6844d8fa..dde3b42a 100644 --- a/source/net/filebot/similarity/DateMatcher.java +++ b/source/net/filebot/similarity/DateMatcher.java @@ -28,37 +28,37 @@ public class DateMatcher { private final DatePattern[] patterns; - public DateMatcher(Locale locale, DateFilter sanity) { + public DateMatcher(DateFilter sanity, Locale... locale) { // generate default date format patterns - List format = new ArrayList(7); + String[] format = new String[7]; // match yyyy-mm-dd patterns like 2010-10-24, 2009/6/1, etc - format.add("y M d"); + format[0] = "y M d"; // match dd-mm-yyyy patterns like 1.1.2010, 01/06/2010, etc - format.add("d M y"); + format[1] = "d M y"; // match yyyy.MMMMM.dd patterns like 2015.October.05 - format.add("y MMMM d"); + format[2] = "y MMMM d"; // match yyyy.MMM.dd patterns like 2015.Oct.6 - format.add("y MMM d"); + format[3] = "y MMM d"; // match dd.MMMMM.yyyy patterns like 25 July 2014 - format.add("d MMMM y"); + format[4] = "d MMMM y"; // match dd.MMM.yyyy patterns like 8 Sep 2015 - format.add("d MMM y"); + format[5] = "d MMM y"; // match yyyymmdd patterns like 20140408 - format.add("yyyyMMdd"); + format[6] = "yyyyMMdd"; - this.patterns = compile(format, locale, sanity); + this.patterns = compile(format, sanity, locale); } - protected DatePattern[] compile(List patterns, Locale locale, DateFilter sanity) { - return StreamEx.of(patterns).flatMap(dateFormat -> { - return StreamEx.of(Locale.ENGLISH, locale).distinct().map(formatLocale -> { + protected DatePattern[] compile(String[] pattern, DateFilter sanity, Locale... locale) { + return StreamEx.of(pattern).flatMap(dateFormat -> { + return StreamEx.of(locale).distinct(Locale::getLanguage).map(formatLocale -> { String regex = StreamEx.split(dateFormat, DateFormatPattern.DELIMITER).map(g -> getPatternGroup(g, formatLocale)).joining("\\D", "(?