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 {
25 private List<MethodSignature.Parameter> parameters = Collections.emptyList();
26 private List<MethodSignature.Parameter> unmodifiableParams = Collections.emptyList();
27 private ValueMechanics mechanics = ValueMechanics.NORMAL;
28 private boolean isAbstract;
29 private boolean isDefault;
31 MethodSignatureBuilderImpl(final String name) {
36 public MethodSignatureBuilder setAbstract(final boolean newIsAbstract) {
37 this.isAbstract = newIsAbstract;
42 public MethodSignatureBuilder setDefault(final boolean newIsDefault) {
43 this.isDefault = newIsDefault;
49 public MethodSignatureBuilder setMechanics(final ValueMechanics newMechanics) {
50 this.mechanics = requireNonNull(newMechanics);
55 public MethodSignatureBuilder addParameter(final Type type, final String name) {
56 this.parameters = LazyCollections.lazyAdd(this.parameters, new MethodParameterImpl(name, type));
57 this.unmodifiableParams = Collections.unmodifiableList(this.parameters);
62 protected MethodSignatureBuilder thisInstance() {
67 public MethodSignature toInstance(final Type definingType) {
68 final List<AnnotationType> annotations = toAnnotationTypes();
69 return new MethodSignatureImpl(definingType, getName(), annotations, getComment(), getAccessModifier(),
70 getReturnType(), this.unmodifiableParams, isFinal(), this.isAbstract, isStatic(), isDefault, mechanics);
74 public int hashCode() {
77 result = prime * result + Objects.hashCode(getName());
78 result = prime * result + Objects.hashCode(this.parameters);
79 result = prime * result + Objects.hashCode(getReturnType());
84 public boolean equals(final Object obj) {
88 if (obj == null || getClass() != obj.getClass()) {
91 final MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
92 return Objects.equals(getName(), other.getName())
93 && Objects.equals(this.parameters, other.parameters)
94 && Objects.equals(getReturnType(), other.getReturnType());
98 public String toString() {
99 return new StringBuilder().append("MethodSignatureBuilderImpl [name=").append(getName())
100 .append(", returnType=").append(getReturnType())
101 .append(", parameters=").append(this.parameters)
102 .append(", annotationBuilders=").append(getAnnotationBuilders())
103 .append(", comment=").append(getComment())
104 .append(']').toString();