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 static java.util.Objects.requireNonNull;
12 import java.util.Collections;
13 import java.util.List;
14 import java.util.Objects;
15 import org.opendaylight.mdsal.binding.model.api.AnnotationType;
16 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
17 import org.opendaylight.mdsal.binding.model.api.MethodSignature.ValueMechanics;
18 import org.opendaylight.mdsal.binding.model.api.Type;
19 import org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder;
20 import org.opendaylight.yangtools.util.LazyCollections;
22 final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder<MethodSignatureBuilder>
23 implements MethodSignatureBuilder {
24 private List<MethodSignature.Parameter> parameters = Collections.emptyList();
25 private List<MethodSignature.Parameter> unmodifiableParams = Collections.emptyList();
26 private ValueMechanics mechanics = ValueMechanics.NORMAL;
27 private boolean isAbstract;
28 private boolean isDefault;
30 MethodSignatureBuilderImpl(final String name) {
35 public MethodSignatureBuilder setAbstract(final boolean newIsAbstract) {
36 this.isAbstract = newIsAbstract;
41 public MethodSignatureBuilder setDefault(final boolean newIsDefault) {
42 this.isDefault = newIsDefault;
47 public MethodSignatureBuilder setMechanics(final ValueMechanics newMechanics) {
48 this.mechanics = requireNonNull(newMechanics);
53 public MethodSignatureBuilder addParameter(final Type type, final String name) {
54 this.parameters = LazyCollections.lazyAdd(this.parameters, new MethodParameterImpl(name, type));
55 this.unmodifiableParams = Collections.unmodifiableList(this.parameters);
60 protected MethodSignatureBuilder thisInstance() {
65 public MethodSignature toInstance(final Type definingType) {
66 final List<AnnotationType> annotations = toAnnotationTypes();
67 return new MethodSignatureImpl(definingType, getName(), annotations, getComment(), getAccessModifier(),
68 getReturnType(), this.unmodifiableParams, isFinal(), this.isAbstract, isStatic(), isDefault, mechanics);
72 public int hashCode() {
73 return Objects.hash(getName(), parameters, getReturnType());
77 public boolean equals(final Object obj) {
81 if (obj == null || getClass() != obj.getClass()) {
84 final MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
85 return Objects.equals(getName(), other.getName())
86 && Objects.equals(this.parameters, other.parameters)
87 && Objects.equals(getReturnType(), other.getReturnType());
91 public String toString() {
92 return new StringBuilder().append("MethodSignatureBuilderImpl [name=").append(getName())
93 .append(", returnType=").append(getReturnType())
94 .append(", parameters=").append(this.parameters)
95 .append(", annotationBuilders=").append(getAnnotationBuilders())
96 .append(", comment=").append(getComment())
97 .append(']').toString();