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.binding.model.util.generated.type.builder;
10 import java.util.Collections;
11 import java.util.List;
12 import java.util.Objects;
13 import org.opendaylight.mdsal.binding.model.api.AnnotationType;
14 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
15 import org.opendaylight.mdsal.binding.model.api.Type;
16 import org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder;
17 import org.opendaylight.yangtools.util.LazyCollections;
19 final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder<MethodSignatureBuilder> implements MethodSignatureBuilder {
21 private List<MethodSignature.Parameter> parameters = Collections.emptyList();
22 private List<MethodSignature.Parameter> unmodifiableParams = Collections.emptyList();
23 private boolean isAbstract;
25 public MethodSignatureBuilderImpl(final String name) {
30 public MethodSignatureBuilder setAbstract(final boolean isAbstract) {
31 this.isAbstract = isAbstract;
36 public MethodSignatureBuilder addParameter(final Type type, final String name) {
37 this.parameters = LazyCollections.lazyAdd(this.parameters, new MethodParameterImpl(name, type));
38 this.unmodifiableParams = Collections.unmodifiableList(this.parameters);
43 protected MethodSignatureBuilder thisInstance() {
48 public MethodSignature toInstance(final Type definingType) {
49 final List<AnnotationType> annotations = toAnnotationTypes();
50 return new MethodSignatureImpl(definingType, getName(), annotations, getComment(), getAccessModifier(),
51 getReturnType(), this.unmodifiableParams, isFinal(), this.isAbstract, isStatic());
55 public int hashCode() {
58 result = (prime * result) + Objects.hashCode(getName());
59 result = (prime * result) + Objects.hashCode(this.parameters);
60 result = (prime * result) + Objects.hashCode(getReturnType());
65 public boolean equals(final Object obj) {
72 if (getClass() != obj.getClass()) {
75 final MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
76 if (!Objects.equals(getName(), other.getName())) {
79 if (!Objects.equals(this.parameters, other.parameters)) {
82 if (!Objects.equals(getReturnType(), other.getReturnType())) {
89 public String toString() {
90 final StringBuilder builder = new StringBuilder();
91 builder.append("MethodSignatureBuilderImpl [name=");
92 builder.append(getName());
93 builder.append(", returnType=");
94 builder.append(getReturnType());
95 builder.append(", parameters=");
96 builder.append(this.parameters);
97 builder.append(", annotationBuilders=");
98 builder.append(getAnnotationBuilders());
99 builder.append(", comment=");
100 builder.append(getComment());
102 return builder.toString();