Refactor OriginalOrder

This commit is contained in:
Reinhard Pointner 2016-05-14 01:28:58 +08:00
parent 2eaac2eab8
commit b1d48fe590
4 changed files with 7 additions and 3 deletions

View File

@ -54,7 +54,7 @@ class AutoDetectMatcher implements AutoCompleteMatcher {
log.log(Level.WARNING, "Failed group: " + it.getKey(), e);
return Stream.empty();
}
}).sorted(comparing(Match::getValue, new OriginalOrder<File>(files))).collect(toList());
}).sorted(comparing(Match::getValue, OriginalOrder.of(files))).collect(toList());
} finally {
workerThreadPool.shutdownNow();
}

View File

@ -137,7 +137,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
matches.addAll(derivateMatches);
// restore original order
matches.sort(comparing(Match::getValue, new OriginalOrder<File>(files)));
matches.sort(comparing(Match::getValue, OriginalOrder.of(files)));
return matches;
}

View File

@ -217,7 +217,7 @@ class MovieMatcher implements AutoCompleteMatcher {
});
// restore original order
matches.sort(comparing(Match::getValue, new OriginalOrder<File>(files)));
matches.sort(comparing(Match::getValue, OriginalOrder.of(files)));
return matches;
}

View File

@ -7,6 +7,10 @@ import java.util.Map;
class OriginalOrder<T> implements Comparator<T> {
public static <T> Comparator<T> of(Collection<T> values) {
return new OriginalOrder(values);
}
private Map<T, Integer> index;
public OriginalOrder(Collection<T> values) {