2 * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.mdsal.binding.javav2.generator.util;
11 import com.google.common.annotations.Beta;
12 import com.google.common.base.Preconditions;
13 import java.util.Objects;
14 import org.opendaylight.mdsal.binding.javav2.model.api.Type;
17 * This class represents ancestor for other <code>Type</code>s
20 public abstract class AbstractBaseType implements Type {
23 * Name of the package to which this <code>Type</code> belongs.
25 protected final String packageName;
28 * Name of this <code>Type</code>.
30 protected final String name;
33 * Constructs the instance of this class with the concrete package name type
37 * string with the package name to which this <code>Type</code>
40 * string with the name for this <code>Type</code>
42 protected AbstractBaseType(final String pkName, final String name) {
43 Preconditions.checkNotNull(pkName, "Package Name for Generated Type cannot be null!");
44 Preconditions.checkNotNull(name, "Name of Generated Type cannot be null!");
45 this.packageName = JavaIdentifierNormalizer.normalizeFullPackageName(pkName);
46 this.name = JavaIdentifierNormalizer.normalizeClassIdentifier(pkName, name);
50 * Constructs the instance of this class with the concrete package name type
54 * string with the package name to which this <code>Type</code>
57 * string with the name for this <code>Type</code>
59 * true if pkName and name are normalized
61 protected AbstractBaseType(final String pkName, final String name, final boolean isNormalized) {
62 Preconditions.checkNotNull(pkName, "Package Name for Generated Type cannot be null!");
63 Preconditions.checkNotNull(name, "Name of Generated Type cannot be null!");
65 this.packageName = pkName;
68 this.packageName = JavaIdentifierNormalizer.normalizeFullPackageName(pkName);
69 this.name = JavaIdentifierNormalizer.normalizeClassIdentifier(pkName, name);
74 public int hashCode() {
75 return Objects.hash(this.name, this.packageName);
79 public boolean equals(final Object obj) {
86 if (!(obj instanceof Type)) {
89 final Type other = (Type) obj;
90 return Objects.equals(this.name, other.getName()) && Objects.equals(this.packageName, other.getPackageName());
95 public String toString() {
96 if (this.packageName.isEmpty()) {
97 return "Type (" + this.name + ")";
99 return "Type (" + this.packageName + "." + this.name + ")";
103 public String getPackageName() {
104 return this.packageName;
108 public String getName() {
113 public String getFullyQualifiedName() {
114 if (this.packageName.isEmpty()) {
117 return this.packageName + "." + this.name;