1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.basepom.mojo.duplicatefinder.classpath;
16
17 import static com.google.common.base.Preconditions.checkNotNull;
18 import static java.lang.String.format;
19
20 import java.util.Collection;
21 import java.util.regex.Pattern;
22
23 import com.google.common.base.Predicate;
24 import com.google.common.collect.ImmutableList;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
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 }