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 static java.util.Objects.requireNonNull;
13 import com.google.common.annotations.Beta;
14 import java.util.Objects;
15 import org.opendaylight.mdsal.binding.javav2.generator.context.ModuleContext;
16 import org.opendaylight.mdsal.binding.javav2.model.api.Type;
19 * This class represents ancestor for other <code>Type</code>s.
22 public abstract class AbstractBaseType implements Type {
25 * Name of the package to which this <code>Type</code> belongs.
27 protected final String packageName;
30 * Name of this <code>Type</code>.
32 protected final String name;
35 * Constructs the instance of this class with the concrete package name type
39 * string with the package name to which this <code>Type</code>
42 * string with the name for this <code>Type</code>
44 protected AbstractBaseType(final String pkName, final String name, final ModuleContext context) {
45 requireNonNull(pkName, "Package Name for Generated Type cannot be null!");
46 requireNonNull(name, "Name of Generated Type cannot be null!");
47 this.packageName = JavaIdentifierNormalizer.normalizeFullPackageName(pkName);
48 requireNonNull(context,
49 "In case of not having identifiers normalized, ModuleContext instance must be provided.");
50 this.name = JavaIdentifierNormalizer.normalizeClassIdentifier(pkName, name, context);
54 * Constructs the instance of this class with the concrete package name type
58 * string with the package name to which this <code>Type</code>
61 * string with the name for this <code>Type</code>
63 * true if pkName and name are normalized
65 protected AbstractBaseType(final String pkName, final String name, final boolean isNormalized,
66 final ModuleContext context) {
67 requireNonNull(pkName, "Package Name for Generated Type cannot be null!");
68 requireNonNull(name, "Name of Generated Type cannot be null!");
70 this.packageName = pkName;
73 this.packageName = JavaIdentifierNormalizer.normalizeFullPackageName(pkName);
74 requireNonNull(context,
75 "In case of not having identifiers normalized, ModuleContext instance must be provided.");
76 this.name = JavaIdentifierNormalizer.normalizeClassIdentifier(pkName, name, context);
80 protected AbstractBaseType(final String pkName, final String name, final boolean isPkNameNormalized,
81 final boolean isTypeNormalized, final ModuleContext context) {
82 requireNonNull(pkName, "Package Name for Generated Type cannot be null!");
83 requireNonNull(name, "Name of Generated Type cannot be null!");
84 if (isPkNameNormalized) {
85 this.packageName = pkName;
87 this.packageName = JavaIdentifierNormalizer.normalizeFullPackageName(pkName);
90 if (isTypeNormalized) {
93 requireNonNull(context,
94 "In case of not having identifiers normalized ModuleContext instance must be provided.");
95 this.name = JavaIdentifierNormalizer.normalizeClassIdentifier(pkName, name, context);
100 public int hashCode() {
101 return Objects.hash(this.name, this.packageName);
105 public boolean equals(final Object obj) {
112 if (!(obj instanceof Type)) {
115 final Type other = (Type) obj;
116 return Objects.equals(this.name, other.getName()) && Objects.equals(this.packageName, other.getPackageName());
121 public String toString() {
122 if (this.packageName.isEmpty()) {
123 return "Type (" + this.name + ")";
125 return "Type (" + this.packageName + "." + this.name + ")";
129 public String getPackageName() {
130 return this.packageName;
134 public String getName() {
139 public String getFullyQualifiedName() {
140 if (this.packageName.isEmpty()) {
143 return this.packageName + "." + this.name;