Remove yang-test
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / java / FullyQualifiedName.java
1 /*
2  * Copyright (c) 2013, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.config.yangjmxgenerator.plugin.java;
10
11 import static com.google.common.base.Preconditions.checkNotNull;
12
13 import java.io.File;
14 import java.util.regex.Matcher;
15 import java.util.regex.Pattern;
16
17 public class FullyQualifiedName {
18
19     private final String packageName;
20     private final String typeName;
21
22     public FullyQualifiedName(String packageName, String typeName) {
23         this.packageName = checkNotNull(packageName);
24         this.typeName = checkNotNull(typeName);
25     }
26
27     public FullyQualifiedName(Class<?> clazz) {
28         this(clazz.getPackage().getName(), clazz.getSimpleName());
29     }
30
31     public static FullyQualifiedName fromString(String fqn) {
32         Matcher m = Pattern.compile("(.*)\\.([^\\.]+)$").matcher(fqn);
33         if (m.matches()) {
34             return new FullyQualifiedName(m.group(1), m.group(2));
35         } else {
36             return new FullyQualifiedName("", fqn);
37         }
38     }
39
40     public String getPackageName() {
41         return packageName;
42     }
43
44     public String getTypeName() {
45         return typeName;
46     }
47
48     public File toFile(File srcDirectory) {
49         String directory = packageName.replace(".", File.separator);
50         return new File(srcDirectory, directory + File.separator + typeName + ".java");
51     }
52
53
54     @Override
55     public String toString() {
56         if (packageName.isEmpty()){
57             return typeName;
58         }
59         return packageName + "." + typeName;
60     }
61
62     @Override
63     public boolean equals(Object o) {
64         if (this == o) {
65             return true;
66         }
67         if (o == null || getClass() != o.getClass()) {
68             return false;
69         }
70
71         FullyQualifiedName that = (FullyQualifiedName) o;
72
73         if (!packageName.equals(that.packageName)) {
74             return false;
75         }
76         if (!typeName.equals(that.typeName)) {
77             return false;
78         }
79
80         return true;
81     }
82
83     @Override
84     public int hashCode() {
85         int result = packageName.hashCode();
86         result = 31 * result + typeName.hashCode();
87         return result;
88     }
89 }