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>
20 implements MethodSignatureBuilder {
22 private List<MethodSignature.Parameter> parameters = Collections.emptyList();
23 private List<MethodSignature.Parameter> unmodifiableParams = Collections.emptyList();
24 private boolean isAbstract;
25 private boolean isDefault;
27 MethodSignatureBuilderImpl(final String name) {
32 public MethodSignatureBuilder setAbstract(final boolean newIsAbstract) {
33 this.isAbstract = newIsAbstract;
38 public MethodSignatureBuilder setDefault(final boolean newIsDefault) {
39 this.isDefault = newIsDefault;
44 public MethodSignatureBuilder addParameter(final Type type, final String name) {
45 this.parameters = LazyCollections.lazyAdd(this.parameters, new MethodParameterImpl(name, type));
46 this.unmodifiableParams = Collections.unmodifiableList(this.parameters);
51 protected MethodSignatureBuilder thisInstance() {
56 public MethodSignature toInstance(final Type definingType) {
57 final List<AnnotationType> annotations = toAnnotationTypes();
58 return new MethodSignatureImpl(definingType, getName(), annotations, getComment(), getAccessModifier(),
59 getReturnType(), this.unmodifiableParams, isFinal(), this.isAbstract, isStatic(), isDefault);
63 public int hashCode() {
66 result = prime * result + Objects.hashCode(getName());
67 result = prime * result + Objects.hashCode(this.parameters);
68 result = prime * result + Objects.hashCode(getReturnType());
73 public boolean equals(final Object obj) {
77 if (obj == null || getClass() != obj.getClass()) {
80 final MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
81 return Objects.equals(getName(), other.getName())
82 && Objects.equals(this.parameters, other.parameters)
83 && Objects.equals(getReturnType(), other.getReturnType());
87 public String toString() {
88 return new StringBuilder().append("MethodSignatureBuilderImpl [name=").append(getName())
89 .append(", returnType=").append(getReturnType())
90 .append(", parameters=").append(this.parameters)
91 .append(", annotationBuilders=").append(getAnnotationBuilders())
92 .append(", comment=").append(getComment())
93 .append(']').toString();