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.yangtools.binding.generator.util.generated.type.builder;
10 import java.util.Collections;
11 import java.util.List;
13 import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType;
14 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;
15 import org.opendaylight.yangtools.sal.binding.model.api.Type;
16 import org.opendaylight.yangtools.sal.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 parameters = LazyCollections.lazyAdd(parameters, new MethodParameterImpl(name, type));
38 unmodifiableParams = Collections.unmodifiableList(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(), unmodifiableParams, isFinal(), isAbstract, isStatic());
55 public int hashCode() {
58 result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
59 result = prime * result + ((parameters == null) ? 0 : parameters.hashCode());
60 result = prime * result + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
65 public boolean equals(final Object obj) {
72 if (getClass() != obj.getClass()) {
75 MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
76 if (getName() == null) {
77 if (other.getName() != null) {
80 } else if (!getName().equals(other.getName())) {
83 if (parameters == null) {
84 if (other.parameters != null) {
87 } else if (!parameters.equals(other.parameters)) {
90 if (getReturnType() == null) {
91 if (other.getReturnType() != null) {
94 } else if (!getReturnType().equals(other.getReturnType())) {
101 public String toString() {
102 StringBuilder builder = new StringBuilder();
103 builder.append("MethodSignatureBuilderImpl [name=");
104 builder.append(getName());
105 builder.append(", returnType=");
106 builder.append(getReturnType());
107 builder.append(", parameters=");
108 builder.append(parameters);
109 builder.append(", annotationBuilders=");
110 builder.append(getAnnotationBuilders());
111 builder.append(", comment=");
112 builder.append(getComment());
114 return builder.toString();