Bug 1411-3: MDSAL Binding2 Generator Util
[mdsal.git] / binding2 / mdsal-binding2-generator-util / src / main / java / org / opendaylight / mdsal / binding2 / 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.mdsal.binding2.generator.util.generated.type.builder;
9
10 import com.google.common.annotations.Beta;
11 import java.util.List;
12 import java.util.Objects;
13 import org.opendaylight.mdsal.binding2.model.api.AccessModifier;
14 import org.opendaylight.mdsal.binding2.model.api.AnnotationType;
15 import org.opendaylight.mdsal.binding2.model.api.Type;
16 import org.opendaylight.mdsal.binding2.model.api.TypeMember;
17
18 @Beta
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 boolean isStatic;
28     private final AccessModifier accessModifier;
29
30     protected AbstractTypeMember(final Type definingType, final String name,  final List<AnnotationType> annotations,
31             final String comment, final AccessModifier accessModifier, final Type returnType,
32             final boolean isFinal, final boolean isStatic) {
33
34         this.definingType = definingType;
35         this.name = name;
36         this.annotations = annotations;
37         this.comment = comment;
38         this.accessModifier = accessModifier;
39         this.returnType = returnType;
40         this.isFinal = isFinal;
41         this.isStatic = isStatic;
42     }
43
44     @Override
45     public List<AnnotationType> getAnnotations() {
46         return annotations;
47     }
48
49     @Override
50     public String getName() {
51         return name;
52     }
53
54     @Override
55     public String getComment() {
56         return comment;
57     }
58
59     @Override
60     public Type getDefiningType() {
61         return definingType;
62     }
63
64     @Override
65     public AccessModifier getAccessModifier() {
66         return accessModifier;
67     }
68
69     @Override
70     public Type getReturnType() {
71         return returnType;
72     }
73
74     @Override
75     public boolean isFinal() {
76         return isFinal;
77     }
78
79     @Override
80     public boolean isStatic() {
81         return isStatic;
82     }
83
84     @Override
85     public int hashCode() {
86         return Objects.hash(name, returnType);
87     }
88
89     @Override
90     public boolean equals(final Object obj) {
91         if (this == obj) {
92             return true;
93         }
94         if (obj == null) {
95             return false;
96         }
97         if (getClass() != obj.getClass()) {
98             return false;
99         }
100
101         if (!(obj instanceof AbstractTypeMember)) {
102             return false;
103         }
104
105         AbstractTypeMember other = (AbstractTypeMember) obj;
106         return Objects.equals(getName(), other.getName()) && Objects.equals(getReturnType(), other.getReturnType());
107     }
108
109     @Override
110     public String toString() {
111         StringBuilder builder = new StringBuilder();
112         builder.append("MethodSignatureImpl [name=");
113         builder.append(getName());
114         builder.append(", comment=");
115         builder.append(getComment());
116         if (getDefiningType() != null) {
117             builder.append(", definingType=");
118             builder.append(getDefiningType().getPackageName());
119             builder.append(".");
120             builder.append(getDefiningType().getName());
121         } else {
122             builder.append(", definingType= null");
123         }
124         builder.append(", returnType=");
125         builder.append(getReturnType());
126         builder.append(", annotations=");
127         builder.append(getAnnotations());
128         builder.append("]");
129         return builder.toString();
130     }
131 }