27d4cffae7aab5c78400150967dcedf8520ec1d5
[mdsal.git] / code-generator / binding-generator-util / src / main / java / org / opendaylight / yangtools / binding / generator / util / AbstractBaseType.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 package org.opendaylight.yangtools.binding.generator.util;\r
9 \r
10 import org.opendaylight.yangtools.sal.binding.model.api.Type;\r
11 \r
12 /**\r
13  * It is used only as ancestor for other <code>Type</code>s\r
14  * \r
15  */\r
16 public class AbstractBaseType implements Type {\r
17 \r
18     /**\r
19      * Name of the package to which this <code>Type</code> belongs.\r
20      */\r
21     private final String packageName;\r
22 \r
23     /**\r
24      * Name of this <code>Type</code>.\r
25      */\r
26     private final String name;\r
27 \r
28     @Override\r
29     public String getPackageName() {\r
30         return packageName;\r
31     }\r
32 \r
33     @Override\r
34     public String getName() {\r
35         return name;\r
36     }\r
37 \r
38     @Override\r
39     public String getFullyQualifiedName() {\r
40         if (packageName.isEmpty()) {\r
41             return name;\r
42         } else {\r
43             return packageName + "." + name;\r
44         }\r
45     }\r
46 \r
47     /**\r
48      * Constructs the instance of this class with the concrete package name type\r
49      * name.\r
50      * \r
51      * @param pkName\r
52      *            string with the package name to which this <code>Type</code>\r
53      *            belongs\r
54      * @param name\r
55      *            string with the name for this <code>Type</code>\r
56      */\r
57     protected AbstractBaseType(String pkName, String name) {\r
58         if (pkName == null) {\r
59             throw new IllegalArgumentException("Package Name for Generated Type cannot be null!");\r
60         }\r
61         if (name == null) {\r
62             throw new IllegalArgumentException("Name of Generated Type cannot be null!");\r
63         }\r
64         this.packageName = pkName;\r
65         this.name = name;\r
66     }\r
67 \r
68     @Override\r
69     public int hashCode() {\r
70         final int prime = 31;\r
71         int result = 1;\r
72         result = prime * result + ((name == null) ? 0 : name.hashCode());\r
73         result = prime * result + ((packageName == null) ? 0 : packageName.hashCode());\r
74         return result;\r
75     }\r
76 \r
77     @Override\r
78     public boolean equals(Object obj) {\r
79         if (this == obj)\r
80             return true;\r
81         if (obj == null)\r
82             return false;\r
83         if (getClass() != obj.getClass())\r
84             return false;\r
85         Type other = (Type) obj;\r
86         if (name == null) {\r
87             if (other.getName() != null)\r
88                 return false;\r
89         } else if (!name.equals(other.getName()))\r
90             return false;\r
91         if (packageName == null) {\r
92             if (other.getPackageName() != null)\r
93                 return false;\r
94         } else if (!packageName.equals(other.getPackageName()))\r
95             return false;\r
96         return true;\r
97     }\r
98 \r
99     @Override\r
100     public String toString() {\r
101         if (packageName.isEmpty()) {\r
102             return "Type (" + name + ")";\r
103         }\r
104         return "Type (" + packageName + "." + name + ")";\r
105     }\r
106 }\r