Extended binding-model-api to support of Enclosed Generated Types and TOs.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-generator-util / src / main / java / org / opendaylight / controller / binding / generator / util / generated / type / builder / AbstractTypeMember.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.controller.binding.generator.util.generated.type.builder;
9
10
11 import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
12 import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
13 import org.opendaylight.controller.sal.binding.model.api.Type;
14 import org.opendaylight.controller.sal.binding.model.api.TypeMember;
15
16 import java.util.Collections;
17 import java.util.List;
18
19 abstract class AbstractTypeMember implements TypeMember {
20
21     private final String name;
22     private final String comment;
23     private final Type definingType;
24     private final Type returnType;
25     private final List<AnnotationType> annotations;
26     private final boolean isFinal;
27     private final AccessModifier accessModifier;
28
29     public AbstractTypeMember(final Type definingType, final String name,  final List<AnnotationType> annotations,
30                               final String comment, final AccessModifier accessModifier, final Type returnType,
31                               boolean isFinal) {
32         super();
33         this.definingType = definingType;
34         this.name = name;
35         this.annotations = Collections.unmodifiableList(annotations);
36         this.comment = comment;
37         this.accessModifier = accessModifier;
38         this.returnType = returnType;
39         this.isFinal = isFinal;
40     }
41
42     @Override
43     public List<AnnotationType> getAnnotations() {
44         return annotations;
45     }
46
47     @Override
48     public String getName() {
49         return name;
50     }
51
52     @Override
53     public String getComment() {
54         return comment;
55     }
56
57     @Override
58     public Type getDefiningType() {
59         return definingType;
60     }
61
62     @Override
63     public AccessModifier getAccessModifier() {
64         return accessModifier;
65     }
66
67     @Override
68     public Type getReturnType() {
69         return returnType;
70     }
71
72     @Override
73     public boolean isFinal() {
74         return isFinal;
75     }
76
77     @Override
78     public int hashCode() {
79         final int prime = 31;
80         int result = 1;
81         result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
82         result = prime * result
83                 + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
84         return result;
85     }
86
87     @Override
88     public boolean equals(Object obj) {
89         if (this == obj) {
90             return true;
91         }
92         if (obj == null) {
93             return false;
94         }
95         if (getClass() != obj.getClass()) {
96             return false;
97         }
98         MethodSignatureImpl other = (MethodSignatureImpl) obj;
99         if (getName() == null) {
100             if (other.getName() != null) {
101                 return false;
102             }
103         } else if (!getName().equals(other.getName())) {
104             return false;
105         }
106         if (getReturnType() == null) {
107             if (other.getReturnType() != null) {
108                 return false;
109             }
110         } else if (!getReturnType().equals(other.getReturnType())) {
111             return false;
112         }
113         return true;
114     }
115
116     @Override
117     public String toString() {
118         StringBuilder builder = new StringBuilder();
119         builder.append("MethodSignatureImpl [name=");
120         builder.append(getName());
121         builder.append(", comment=");
122         builder.append(getComment());
123         if (getDefiningType() != null) {
124             builder.append(", definingType=");
125             builder.append(getDefiningType().getPackageName());
126             builder.append(".");
127             builder.append(getDefiningType().getName());
128         } else {
129             builder.append(", definingType= null");
130         }
131         builder.append(", returnType=");
132         builder.append(getReturnType());
133         builder.append(", annotations=");
134         builder.append(getAnnotations());
135         builder.append("]");
136         return builder.toString();
137     }
138 }