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