Fix duplicate dependency warnings
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / java / FullyQualifiedName.java
1 package org.opendaylight.controller.config.yangjmxgenerator.plugin.java;
2
3 import java.io.File;
4 import java.util.regex.Matcher;
5 import java.util.regex.Pattern;
6
7 import static com.google.common.base.Preconditions.checkNotNull;
8
9 public class FullyQualifiedName {
10
11     private final String packageName;
12     private final String typeName;
13
14     public FullyQualifiedName(String packageName, String typeName) {
15         this.packageName = checkNotNull(packageName);
16         this.typeName = checkNotNull(typeName);
17     }
18
19     public FullyQualifiedName(Class<?> clazz) {
20         this(clazz.getPackage().getName(), clazz.getSimpleName());
21     }
22
23     public static FullyQualifiedName fromString(String fqn) {
24         Matcher m = Pattern.compile("(.*)\\.([^\\.]+)$").matcher(fqn);
25         if (m.matches()) {
26             return new FullyQualifiedName(m.group(1), m.group(2));
27         } else {
28             return new FullyQualifiedName("", fqn);
29         }
30     }
31
32     public String getPackageName() {
33         return packageName;
34     }
35
36     public String getTypeName() {
37         return typeName;
38     }
39
40     public File toFile(File srcDirectory) {
41         String directory = packageName.replace(".", File.separator);
42         return new File(srcDirectory, directory + File.separator + typeName + ".java");
43     }
44
45
46     @Override
47     public String toString() {
48         if (packageName.isEmpty()){
49             return typeName;
50         }
51         return packageName + "." + typeName;
52     }
53
54     @Override
55     public boolean equals(Object o) {
56         if (this == o) {
57             return true;
58         }
59         if (o == null || getClass() != o.getClass()) {
60             return false;
61         }
62
63         FullyQualifiedName that = (FullyQualifiedName) o;
64
65         if (!packageName.equals(that.packageName)) {
66             return false;
67         }
68         if (!typeName.equals(that.typeName)) {
69             return false;
70         }
71
72         return true;
73     }
74
75     @Override
76     public int hashCode() {
77         int result = packageName.hashCode();
78         result = 31 * result + typeName.hashCode();
79         return result;
80     }
81 }