Bug 6859: Cleanup package names for mdsal-binding-generator-util module
[mdsal.git] / binding / mdsal-binding-generator-util / src / main / java / org / opendaylight / mdsal / binding / generator / util / AbstractBaseType.java
1 /*
2  * Copyright (c) 2013 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 package org.opendaylight.mdsal.binding.generator.util;
9
10 import java.util.Objects;
11 import org.opendaylight.mdsal.binding.model.api.Type;
12
13 /**
14  * It is used only as ancestor for other <code>Type</code>s
15  *
16  */
17 public class AbstractBaseType implements Type {
18
19     /**
20      * Name of the package to which this <code>Type</code> belongs.
21      */
22     private final String packageName;
23
24     /**
25      * Name of this <code>Type</code>.
26      */
27     private final String name;
28
29     @Override
30     public String getPackageName() {
31         return packageName;
32     }
33
34     @Override
35     public String getName() {
36         return name;
37     }
38
39     @Override
40     public String getFullyQualifiedName() {
41         if (packageName.isEmpty()) {
42             return name;
43         } else {
44             return packageName + "." + name;
45         }
46     }
47
48     /**
49      * Constructs the instance of this class with the concrete package name type
50      * name.
51      *
52      * @param pkName
53      *            string with the package name to which this <code>Type</code>
54      *            belongs
55      * @param name
56      *            string with the name for this <code>Type</code>
57      */
58     protected AbstractBaseType(final String pkName, final String name) {
59         if (pkName == null) {
60             throw new IllegalArgumentException("Package Name for Generated Type cannot be null!");
61         }
62         if (name == null) {
63             throw new IllegalArgumentException("Name of Generated Type cannot be null!");
64         }
65         this.packageName = pkName;
66         this.name = name;
67     }
68
69     @Override
70     public int hashCode() {
71         final int prime = 31;
72         int result = 1;
73         result = prime * result + Objects.hashCode(name);
74         result = prime * result + Objects.hashCode(packageName);
75         return result;
76     }
77
78     @Override
79     public boolean equals(final Object obj) {
80         if (this == obj) {
81             return true;
82         }
83         if (obj == null) {
84             return false;
85         }
86         if (!(obj instanceof Type)) {
87             return false;
88         }
89         Type other = (Type) obj;
90         return Objects.equals(name, other.getName()) && Objects.equals(packageName, other.getPackageName());
91     }
92
93     @Override
94     public String toString() {
95         if (packageName.isEmpty()) {
96             return "Type (" + name + ")";
97         }
98         return "Type (" + packageName + "." + name + ")";
99     }
100 }