5a211b9d415333ed69b914b3c11aad70f63179b6
[mdsal.git] / binding / mdsal-binding-generator-util / src / main / java / org / opendaylight / mdsal / binding / model / util / generated / type / builder / MethodSignatureImpl.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 static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.VisibleForTesting;
13 import java.util.List;
14 import java.util.Objects;
15 import org.opendaylight.mdsal.binding.model.api.AccessModifier;
16 import org.opendaylight.mdsal.binding.model.api.AnnotationType;
17 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
18 import org.opendaylight.mdsal.binding.model.api.Type;
19
20 class MethodSignatureImpl extends AbstractTypeMember implements MethodSignature {
21     private final List<Parameter> params;
22     private final ValueMechanics mechanics;
23     private final boolean isAbstract;
24     private final boolean isDefault;
25
26     @VisibleForTesting
27     MethodSignatureImpl(final Type definingType, final String name, final List<AnnotationType> annotations,
28         final String comment, final AccessModifier accessModifier, final Type returnType,
29         final List<Parameter> params, final boolean isFinal, final boolean isAbstract, final boolean isStatic) {
30         this(definingType, name, annotations, comment, accessModifier, returnType, params, isFinal, isAbstract,
31             isStatic, false, ValueMechanics.NORMAL);
32     }
33
34     MethodSignatureImpl(final Type definingType, final String name, final List<AnnotationType> annotations,
35             final String comment, final AccessModifier accessModifier, final Type returnType,
36             final List<Parameter> params, final boolean isFinal, final boolean isAbstract, final boolean isStatic,
37             final boolean isDefault, final ValueMechanics mechanics) {
38         super(definingType, name, annotations, comment, accessModifier, returnType, isFinal, isStatic);
39         this.params = params;
40         this.isAbstract = isAbstract;
41         this.isDefault = isDefault;
42         this.mechanics = requireNonNull(mechanics);
43     }
44
45     @Override
46     public boolean isAbstract() {
47         return this.isAbstract;
48     }
49
50     @Override
51     public boolean isDefault() {
52         return isDefault;
53     }
54
55     @Override
56     public List<Parameter> getParameters() {
57         return this.params;
58     }
59
60     @Override
61     public ValueMechanics getMechanics() {
62         return mechanics;
63     }
64
65     @Override
66     public int hashCode() {
67         final int prime = 31;
68         int result = 1;
69         result = prime * result + Objects.hashCode(getName());
70         result = prime * result + Objects.hashCode(this.params);
71         result = prime * result + Objects.hashCode(getReturnType());
72         return result;
73     }
74
75     @Override
76     public boolean equals(final Object obj) {
77         if (this == obj) {
78             return true;
79         }
80         if (obj == null || getClass() != obj.getClass()) {
81             return false;
82         }
83         final MethodSignatureImpl other = (MethodSignatureImpl) obj;
84         return Objects.equals(getName(), other.getName())
85                 && Objects.equals(this.params, other.params)
86                 && Objects.equals(getReturnType(), other.getReturnType());
87     }
88
89     @Override
90     public String toString() {
91         final StringBuilder builder = new StringBuilder().append("MethodSignatureImpl [name=").append(getName())
92                 .append(", comment=").append(getComment())
93                 .append(", definingType=");
94
95         final Type defType = getDefiningType();
96         if (defType != null) {
97             builder.append(defType.getPackageName()).append('.').append(defType.getName());
98         } else {
99             builder.append(" null");
100         }
101
102         return builder.append(", returnType=").append(getReturnType())
103                 .append(", params=").append(this.params)
104                 .append(", annotations=").append(getAnnotations())
105                 .append(']').toString();
106     }
107 }