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