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