2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data;
24 import java.util.Collections;
25 import java.util.HashMap;
27 import java.util.Objects;
28 import javax.annotation.processing.Generated;
29 import org.opendaylight.yangtools.concepts.Builder;
30 import org.opendaylight.yangtools.yang.binding.AbstractAugmentable;
31 import org.opendaylight.yangtools.yang.binding.Augmentation;
32 import org.opendaylight.yangtools.yang.binding.DataObject;
35 * Class that builds {@link UserdataBuilder} instances. Overall design of the class is that of a
36 * <a href="https://en.wikipedia.org/wiki/Fluent_interface">fluent interface</a>, where method chaining is used.
39 * In general, this class is supposed to be used like this template:
43 * UserdataBuilder createTarget(int fooXyzzy, int barBaz) {
44 * return new UserdataBuilderBuilder()
45 * .setFoo(new FooBuilder().setXyzzy(fooXyzzy).build())
46 * .setBar(new BarBuilder().setBaz(barBaz).build())
53 * This pattern is supported by the immutable nature of UserdataBuilder, as instances can be freely passed around
54 * without worrying about synchronization issues.
57 * As a side note: method chaining results in:
59 * <li>very efficient Java bytecode, as the method invocation result, in this case the Builder reference, is on the
60 * stack, so further method invocations just need to fill method arguments for the next method invocation, which is
61 * terminated by {@link #build()}, which is then returned from the method</li>
62 * <li>better understanding by humans, as the scope of mutable state (the builder) is kept to a minimum and is very
64 * <li>better optimization oportunities, as the object scope is minimized in terms of invocation (rather than method)
65 * stack, making <a href="https://en.wikipedia.org/wiki/Escape_analysis">escape analysis</a> a lot easier. Given enough
66 * compiler (JIT/AOT) prowess, the cost of th builder object can be completely eliminated</li>
69 * @see UserdataBuilder
73 @Generated("mdsal-binding-generator")
74 public class UserdataBuilder implements Builder<Userdata> {
77 private String _value;
80 Map<Class<? extends Augmentation<Userdata>>, Augmentation<Userdata>> augmentation = Collections.emptyMap();
82 public UserdataBuilder() {}
86 public UserdataBuilder(Userdata base) {
87 Map<Class<? extends Augmentation<Userdata>>, Augmentation<Userdata>> aug = base.augmentations();
89 this.augmentation = new HashMap<>(aug);
91 this._id = base.getId();
92 this._value = base.getValue();
96 public String getId() {
100 public String getValue() {
104 @SuppressWarnings({"unchecked", "checkstyle:methodTypeParameterName"})
105 public <E$$ extends Augmentation<Userdata>> E$$ augmentation(Class<E$$> augmentationType) {
106 return (E$$) augmentation.get(Objects.requireNonNull(augmentationType));
110 public UserdataBuilder setId(final String value) {
115 public UserdataBuilder setValue(final String value) {
121 * Add an augmentation to this builder's product.
123 * @param augmentation augmentation to be added
124 * @return this builder
125 * @throws NullPointerException if {@code augmentation} is null
127 public UserdataBuilder addAugmentation(Augmentation<Userdata> augmentation) {
128 Class<? extends Augmentation<Userdata>> augmentationType = augmentation.implementedInterface();
129 if (!(this.augmentation instanceof HashMap)) {
130 this.augmentation = new HashMap<>();
133 this.augmentation.put(augmentationType, augmentation);
138 * Remove an augmentation from this builder's product. If this builder does not track such an augmentation type,
139 * this method does nothing.
141 * @param augmentationType augmentation type to be removed
142 * @return this builder
144 public UserdataBuilder removeAugmentation(Class<? extends Augmentation<Userdata>> augmentationType) {
145 if (this.augmentation instanceof HashMap) {
146 this.augmentation.remove(augmentationType);
152 public Userdata build() {
153 return new UserdataImpl(this);
156 private static final class UserdataImpl extends AbstractAugmentable<Userdata> implements Userdata {
158 private final String _id;
159 private final String _value;
161 UserdataImpl(UserdataBuilder base) {
162 super(base.augmentation);
163 this._id = base.getId();
164 this._value = base.getValue();
168 public String getId() {
173 public String getValue() {
177 private int hash = 0;
178 private volatile boolean hashValid = false;
181 public int hashCode() {
186 final int result = Userdata.bindingHashCode(this);
193 public boolean equals(Object obj) {
194 return Userdata.bindingEquals(this, obj);
198 public String toString() {
199 return Userdata.bindingToString(this);
203 public Class<? extends DataObject> implementedInterface() {
204 return Userdata.class;