2 * Copyright (c) 2013, 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.config.yangjmxgenerator.plugin.java;
11 import static com.google.common.base.Preconditions.checkNotNull;
14 import java.util.regex.Matcher;
15 import java.util.regex.Pattern;
17 public class FullyQualifiedName {
19 private final String packageName;
20 private final String typeName;
22 public FullyQualifiedName(String packageName, String typeName) {
23 this.packageName = checkNotNull(packageName);
24 this.typeName = checkNotNull(typeName);
27 public FullyQualifiedName(Class<?> clazz) {
28 this(clazz.getPackage().getName(), clazz.getSimpleName());
31 public static FullyQualifiedName fromString(String fqn) {
32 Matcher m = Pattern.compile("(.*)\\.([^\\.]+)$").matcher(fqn);
34 return new FullyQualifiedName(m.group(1), m.group(2));
36 return new FullyQualifiedName("", fqn);
40 public String getPackageName() {
44 public String getTypeName() {
48 public File toFile(File srcDirectory) {
49 String directory = packageName.replace(".", File.separator);
50 return new File(srcDirectory, directory + File.separator + typeName + ".java");
55 public String toString() {
56 if (packageName.isEmpty()){
59 return packageName + "." + typeName;
63 public boolean equals(Object o) {
67 if (o == null || getClass() != o.getClass()) {
71 FullyQualifiedName that = (FullyQualifiedName) o;
73 if (!packageName.equals(that.packageName)) {
76 if (!typeName.equals(that.typeName)) {
84 public int hashCode() {
85 int result = packageName.hashCode();
86 result = 31 * result + typeName.hashCode();