1 package org.opendaylight.controller.config.yangjmxgenerator.plugin.java;
4 import java.util.regex.Matcher;
5 import java.util.regex.Pattern;
7 import static com.google.common.base.Preconditions.checkNotNull;
9 public class FullyQualifiedName {
11 private final String packageName;
12 private final String typeName;
14 public FullyQualifiedName(String packageName, String typeName) {
15 this.packageName = checkNotNull(packageName);
16 this.typeName = checkNotNull(typeName);
19 public FullyQualifiedName(Class<?> clazz) {
20 this(clazz.getPackage().getName(), clazz.getSimpleName());
23 public static FullyQualifiedName fromString(String fqn) {
24 Matcher m = Pattern.compile("(.*)\\.([^\\.]+)$").matcher(fqn);
26 return new FullyQualifiedName(m.group(1), m.group(2));
28 return new FullyQualifiedName("", fqn);
32 public String getPackageName() {
36 public String getTypeName() {
40 public File toFile(File srcDirectory) {
41 String directory = packageName.replace(".", File.separator);
42 return new File(srcDirectory, directory + File.separator + typeName + ".java");
47 public String toString() {
48 if (packageName.isEmpty()){
51 return packageName + "." + typeName;
55 public boolean equals(Object o) {
59 if (o == null || getClass() != o.getClass()) {
63 FullyQualifiedName that = (FullyQualifiedName) o;
65 if (!packageName.equals(that.packageName)) {
68 if (!typeName.equals(that.typeName)) {
76 public int hashCode() {
77 int result = packageName.hashCode();
78 result = 31 * result + typeName.hashCode();