1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.basepom.mojo.duplicatefinder.classpath;
16
17 import java.io.File;
18 import java.util.function.Predicate;
19 import java.util.stream.Collectors;
20
21 import com.google.common.collect.ImmutableSet;
22 import com.google.common.collect.Multimap;
23
24 final class ClasspathCacheElement {
25
26 private final File element;
27 private final ImmutableSet<String> classes;
28 private final ImmutableSet<String> resources;
29
30 public static Builder builder(final File element) {
31 return new Builder(element);
32 }
33
34 private ClasspathCacheElement(final File element, final ImmutableSet<String> classes, final ImmutableSet<String> resources) {
35 this.element = element;
36 this.classes = classes;
37 this.resources = resources;
38 }
39
40 void putClasses(final Multimap<String, File> classMap, final Predicate<String> excludePredicate) {
41 for (final String className : classes.stream().filter(excludePredicate.negate()).collect(Collectors.toList())) {
42 classMap.put(className, element);
43 }
44 }
45
46 void putResources(final Multimap<String, File> resourceMap, final Predicate<String> excludePredicate) {
47 for (final String resource : resources.stream().filter(excludePredicate.negate()).collect(Collectors.toList())) {
48 resourceMap.put(resource, element);
49 }
50 }
51
52 static final class Builder {
53
54 private final File element;
55 private final ImmutableSet.Builder<String> classBuilder = ImmutableSet.builder();
56 private final ImmutableSet.Builder<String> resourcesBuilder = ImmutableSet.builder();
57
58 private Builder(final File element) {
59 this.element = element;
60 }
61
62 void addClass(final String className) {
63 classBuilder.add(className);
64 }
65
66 void addResource(final String resource) {
67 resourcesBuilder.add(resource);
68 }
69
70 ClasspathCacheElement build() {
71 return new ClasspathCacheElement(element, classBuilder.build(), resourcesBuilder.build());
72 }
73 }
74 }