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.generator.context.ModuleContext;
15 import org.opendaylight.mdsal.binding.javav2.model.api.Type;
18 * This class represents ancestor for other <code>Type</code>s.
21 public abstract class AbstractBaseType implements Type {
24 * Name of the package to which this <code>Type</code> belongs.
26 protected final String packageName;
29 * Name of this <code>Type</code>.
31 protected final String name;
34 * Constructs the instance of this class with the concrete package name type
38 * string with the package name to which this <code>Type</code>
41 * string with the name for this <code>Type</code>
43 protected AbstractBaseType(final String pkName, final String name, final ModuleContext context) {
44 Preconditions.checkNotNull(pkName, "Package Name for Generated Type cannot be null!");
45 Preconditions.checkNotNull(name, "Name of Generated Type cannot be null!");
46 this.packageName = JavaIdentifierNormalizer.normalizeFullPackageName(pkName);
47 Preconditions.checkNotNull(context,
48 "In case of not having identifiers normalized, ModuleContext instance must be provided.");
49 this.name = JavaIdentifierNormalizer.normalizeClassIdentifier(pkName, name, context);
53 * Constructs the instance of this class with the concrete package name type
57 * string with the package name to which this <code>Type</code>
60 * string with the name for this <code>Type</code>
62 * true if pkName and name are normalized
64 protected AbstractBaseType(final String pkName, final String name, final boolean isNormalized,
65 final ModuleContext context) {
66 Preconditions.checkNotNull(pkName, "Package Name for Generated Type cannot be null!");
67 Preconditions.checkNotNull(name, "Name of Generated Type cannot be null!");
69 this.packageName = pkName;
72 this.packageName = JavaIdentifierNormalizer.normalizeFullPackageName(pkName);
73 Preconditions.checkNotNull(context,
74 "In case of not having identifiers normalized, ModuleContext instance must be provided.");
75 this.name = JavaIdentifierNormalizer.normalizeClassIdentifier(pkName, name, context);
79 protected AbstractBaseType(final String pkName, final String name, final boolean isPkNameNormalized,
80 final boolean isTypeNormalized, final ModuleContext context) {
81 Preconditions.checkNotNull(pkName, "Package Name for Generated Type cannot be null!");
82 Preconditions.checkNotNull(name, "Name of Generated Type cannot be null!");
83 if (isPkNameNormalized) {
84 this.packageName = pkName;
86 this.packageName = JavaIdentifierNormalizer.normalizeFullPackageName(pkName);
89 if (isTypeNormalized) {
92 Preconditions.checkNotNull(context,
93 "In case of not having identifiers normalized ModuleContext instance must be provided.");
94 this.name = JavaIdentifierNormalizer.normalizeClassIdentifier(pkName, name, context);
99 public int hashCode() {
100 return Objects.hash(this.name, this.packageName);
104 public boolean equals(final Object obj) {
111 if (!(obj instanceof Type)) {
114 final Type other = (Type) obj;
115 return Objects.equals(this.name, other.getName()) && Objects.equals(this.packageName, other.getPackageName());
120 public String toString() {
121 if (this.packageName.isEmpty()) {
122 return "Type (" + this.name + ")";
124 return "Type (" + this.packageName + "." + this.name + ")";
128 public String getPackageName() {
129 return this.packageName;
133 public String getName() {
138 public String getFullyQualifiedName() {
139 if (this.packageName.isEmpty()) {
142 return this.packageName + "." + this.name;