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