Integrate JavaTypeName as Identifier
[mdsal.git] / binding / mdsal-binding-generator-util / src / main / java / org / opendaylight / mdsal / binding / model / 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.model.util;
9
10 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
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 public class AbstractBaseType implements Type {
17     /**
18      * Name of this <code>Type</code>.
19      */
20     private final JavaTypeName identifier;
21
22     @Override
23     public final JavaTypeName getIdentifier() {
24         return this.identifier;
25     }
26
27     /**
28      * Constructs the instance of this class with a JavaTypeName.
29      *
30      * @param identifier for this <code>Type</code>
31      */
32     protected AbstractBaseType(final JavaTypeName identifier) {
33         if (identifier == null) {
34             throw new IllegalArgumentException("Identifier for Generated Type cannot be null!");
35         }
36         this.identifier = identifier;
37     }
38
39     @Override
40     public int hashCode() {
41         return identifier.hashCode();
42     }
43
44     @Override
45     public boolean equals(final Object obj) {
46         if (this == obj) {
47             return true;
48         }
49         if (obj == null) {
50             return false;
51         }
52         if (!(obj instanceof Type)) {
53             return false;
54         }
55         final Type other = (Type) obj;
56         return identifier.equals(other.getIdentifier());
57     }
58
59     @Override
60     public String toString() {
61         return "Type (" + getFullyQualifiedName() + ")";
62     }
63 }