### Question:
Indexer { public String cleanUpTitle(String title) { if (Strings.isNullOrEmpty(title)) { return title; } title = title.trim(); List<String> removeTrailing = configProvider.getBaseConfig().getSearching().getRemoveTrailing().stream().map(x -> x.toLowerCase().trim()).collect(Collectors.toList()); if (removeTrailing.isEmpty()) { return title; } if (cleanupPattern == null) { String allPattern = "^(?<keep>.*)(" + removeTrailing.stream().map(x -> x.replace("*", "WILDCARDXXX").replaceAll("[-\\[\\]{}()*+?.,\\\\\\\\^$|#]", "\\\\$0").replace("WILDCARDXXX", ".*") + "$").collect(Collectors.joining("|")) + ")"; cleanupPattern = Pattern.compile(allPattern, Pattern.CASE_INSENSITIVE); } Matcher matcher = cleanupPattern.matcher(title); while (matcher.matches()) { title = matcher.replaceAll("$1").trim(); matcher = cleanupPattern.matcher(title); } return title; }  void initialize(IndexerConfig config, IndexerEntity indexer); @EventListener void handleNewConfig(ConfigChangedEvent configChangedEvent); IndexerSearchResult search(SearchRequest searchRequest, int offset, Integer limit); abstract NfoResult getNfo(String guid); String getName(); IndexerConfig getConfig(); IndexerEntity getIndexerEntity(); String cleanUpTitle(String title); Optional<Instant> tryParseDate(String dateString); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void shouldRemoveTrailing2() { List<String> collect = IntStream.range(1, 100).mapToObj(x -> "trailing" + x + "*********").collect(Collectors.toList()); List<String> all = new ArrayList<>(); all.addAll(collect); all.add("trailing*"); baseConfig.getSearching().setRemoveTrailing(all); testee.cleanUpTitle("abc trailing1 trailing2"); testee.cleanUpTitle("abc trailing1 trailing2"); testee.cleanUpTitle("abc trailing1 trailing2"); Stopwatch stopwatch = Stopwatch.createStarted(); for (int i = 0; i < 100; i++) { testee.cleanUpTitle("abc trailing1 trailing2"); } System.out.println(stopwatch.elapsed(TimeUnit.MILLISECONDS)); }