2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding2.generator.util.generated.type.builder;
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.ImmutableList;
12 import java.util.Collections;
13 import java.util.List;
14 import java.util.Objects;
15 import org.opendaylight.mdsal.binding2.model.api.AnnotationType;
16 import org.opendaylight.mdsal.binding2.model.api.MethodSignature;
17 import org.opendaylight.mdsal.binding2.model.api.Type;
18 import org.opendaylight.mdsal.binding2.model.api.type.builder.MethodSignatureBuilder;
19 import org.opendaylight.yangtools.util.LazyCollections;
22 final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder<MethodSignatureBuilder> implements MethodSignatureBuilder {
24 private List<MethodSignature.Parameter> parameters = ImmutableList.of();
25 private List<MethodSignature.Parameter> unmodifiableParams = ImmutableList.of();
26 private boolean isAbstract;
28 public MethodSignatureBuilderImpl(final String name) {
33 public MethodSignatureBuilder setAbstract(final boolean isAbstract) {
34 this.isAbstract = isAbstract;
39 public MethodSignatureBuilder addParameter(final Type type, final String name) {
40 parameters = LazyCollections.lazyAdd(parameters, new MethodParameterImpl(name, type));
41 unmodifiableParams = Collections.unmodifiableList(parameters);
46 protected MethodSignatureBuilder thisInstance() {
51 public MethodSignature toInstance(final Type definingType) {
52 final List<AnnotationType> annotations = toAnnotationTypes();
53 return new MethodSignatureImpl(definingType, getName(), annotations, getComment(), getAccessModifier(),
54 getReturnType(), unmodifiableParams, isFinal(), isAbstract, isStatic());
58 public int hashCode() {
59 return Objects.hash(getName(), parameters, getReturnType());
63 public boolean equals(final Object obj) {
70 if (getClass() != obj.getClass()) {
73 MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
74 if (!Objects.equals(getName(), other.getName())) {
77 if (!Objects.equals(parameters, other.parameters)) {
80 if (!Objects.equals(getReturnType(), other.getReturnType())) {
87 public String toString() {
88 StringBuilder builder = new StringBuilder();
89 builder.append("MethodSignatureBuilderImpl [name=");
90 builder.append(getName());
91 builder.append(", returnType=");
92 builder.append(getReturnType());
93 builder.append(", parameters=");
94 builder.append(parameters);
95 builder.append(", annotationBuilders=");
96 builder.append(getAnnotationBuilders());
97 builder.append(", comment=");
98 builder.append(getComment());
100 return builder.toString();