Merge "Bug 735 - Part 1: Update ietf-restconf and ietf-yangtypes to newer versions"
[yangtools.git] / code-generator / binding-generator-util / src / main / java / org / opendaylight / yangtools / 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.yangtools.binding.generator.util.generated.type.builder;
9
10
11 import java.util.Collections;
12 import java.util.List;
13
14 import org.opendaylight.yangtools.sal.binding.model.api.AccessModifier;
15 import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType;
16 import org.opendaylight.yangtools.sal.binding.model.api.Type;
17 import org.opendaylight.yangtools.sal.binding.model.api.TypeMember;
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 boolean isStatic;
28     private final AccessModifier accessModifier;
29
30     public 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         super();
34         this.definingType = definingType;
35         this.name = name;
36         this.annotations = annotations.isEmpty() ? Collections.<AnnotationType>emptyList() : Collections.unmodifiableList(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         final int prime = 31;
87         int result = 1;
88         result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
89         result = prime * result
90                 + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
91         return result;
92     }
93
94     @Override
95     public boolean equals(final Object obj) {
96         if (this == obj) {
97             return true;
98         }
99         if (obj == null) {
100             return false;
101         }
102         if (getClass() != obj.getClass()) {
103             return false;
104         }
105         AbstractTypeMember other = (AbstractTypeMember) obj;
106         if (getName() == null) {
107             if (other.getName() != null) {
108                 return false;
109             }
110         } else if (!getName().equals(other.getName())) {
111             return false;
112         }
113         if (getReturnType() == null) {
114             if (other.getReturnType() != null) {
115                 return false;
116             }
117         } else if (!getReturnType().equals(other.getReturnType())) {
118             return false;
119         }
120         return true;
121     }
122
123     @Override
124     public String toString() {
125         StringBuilder builder = new StringBuilder();
126         builder.append("MethodSignatureImpl [name=");
127         builder.append(getName());
128         builder.append(", comment=");
129         builder.append(getComment());
130         if (getDefiningType() != null) {
131             builder.append(", definingType=");
132             builder.append(getDefiningType().getPackageName());
133             builder.append(".");
134             builder.append(getDefiningType().getName());
135         } else {
136             builder.append(", definingType= null");
137         }
138         builder.append(", returnType=");
139         builder.append(getReturnType());
140         builder.append(", annotations=");
141         builder.append(getAnnotations());
142         builder.append("]");
143         return builder.toString();
144     }
145 }