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