1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.basepom.mojo.duplicatefinder.classpath;
15
16 import java.util.Collection;
17 import java.util.regex.Pattern;
18
19 import com.google.common.base.Predicate;
20 import com.google.common.collect.ImmutableList;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 import static java.lang.String.format;
25
26 import static com.google.common.base.Preconditions.checkNotNull;
27
28 class MatchPatternPredicate implements Predicate<String> {
29
30 private static final Logger LOG = LoggerFactory.getLogger(MatchPatternPredicate.class);
31
32 private final ImmutableList<Pattern> patterns;
33
34 MatchPatternPredicate(final Collection<String> patternStrings) {
35 checkNotNull(patternStrings, "patternStrings is null");
36
37 final ImmutableList.Builder<Pattern> builder = ImmutableList.builder();
38 for (final String patternString : patternStrings) {
39 builder.add(Pattern.compile(patternString, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE));
40 }
41
42 this.patterns = builder.build();
43 }
44
45 public ImmutableList<Pattern> getPatterns() {
46 return patterns;
47 }
48
49 @Override
50 public boolean apply(final String input) {
51 if (input != null) {
52 for (final Pattern pattern : patterns) {
53 if (pattern.matcher(input).matches()) {
54 LOG.debug(format("Ignoring '%s' (matches %s)", input, pattern.pattern()));
55 return true;
56 }
57 }
58 }
59 return false;
60 }
61 }