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