Eliminate org.opendaylight.mdsal.binding.generator.spi
[mdsal.git] / binding / mdsal-binding-generator-api / src / main / java / org / opendaylight / mdsal / binding / model / api / 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.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import org.eclipse.jdt.annotation.NonNull;
14
15 /**
16  * It is used only as ancestor for other <code>Type</code>s. Note this forms the equality domain over most types, please
17  * consider joining the party.
18  */
19 @Beta
20 public class AbstractBaseType implements Type {
21     /**
22      * Name of this <code>Type</code>.
23      */
24     private final @NonNull JavaTypeName identifier;
25
26     /**
27      * Constructs the instance of this class with a JavaTypeName.
28      *
29      * @param identifier for this <code>Type</code>
30      */
31     protected AbstractBaseType(final JavaTypeName identifier) {
32         this.identifier = requireNonNull(identifier);
33     }
34
35     @Override
36     public final JavaTypeName getIdentifier() {
37         return this.identifier;
38     }
39
40     @Override
41     public final int hashCode() {
42         return identifier.hashCode();
43     }
44
45     @Override
46     public final boolean equals(final Object obj) {
47         if (this == obj) {
48             return true;
49         }
50         if (!(obj instanceof Type)) {
51             return false;
52         }
53         return identifier.equals(((Type) obj).getIdentifier());
54     }
55
56     @Override
57     public String toString() {
58         return "Type (" + getFullyQualifiedName() + ")";
59     }
60 }