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.List;
17
18 import com.google.common.base.Joiner;
19 import com.google.common.collect.ImmutableList;
20
21 import static com.google.common.base.Preconditions.checkArgument;
22 import static com.google.common.base.Preconditions.checkNotNull;
23
24
25
26
27
28 class PackageNameHolder {
29
30 private final ImmutableList<String> packages;
31 private final String packageName;
32 private final String path;
33
34 PackageNameHolder(final List<String> packages) {
35 this.packages = ImmutableList.copyOf(checkNotNull(packages, "packages is null"));
36 this.packageName = Joiner.on('.').join(packages);
37 this.path = Joiner.on('/').join(packages);
38 }
39
40 PackageNameHolder() {
41 this.packages = ImmutableList.of();
42 this.packageName = "";
43 this.path = "";
44 }
45
46 PackageNameHolder getChildPackage(final String packageName) {
47 checkNotNull(packageName, "packageName is null");
48 checkArgument(packageName.length() > 0, "package name must have at least one character");
49
50 return new PackageNameHolder(ImmutableList.<String>builder().addAll(packages).add(packageName).build());
51 }
52
53 String getQualifiedName(final String className) {
54 checkNotNull(className, "className is null");
55 return packages.isEmpty() ? className : packageName + "." + className;
56 }
57
58 String getQualifiedPath(final String className) {
59 checkNotNull(className, "className is null");
60 return packages.isEmpty() ? className : path + "/" + className;
61 }
62
63 @Override
64 public String toString() {
65 return getClass().getSimpleName() + "(" + packageName + ")";
66 }
67 }