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.yang.binding.AbstractAugmentable;
30 import org.opendaylight.yangtools.yang.binding.Augmentation;
31 import org.opendaylight.yangtools.yang.binding.DataObject;
34 * Class that builds {@link UserdataBuilder} instances. Overall design of the class is that of a
35 * <a href="https://en.wikipedia.org/wiki/Fluent_interface">fluent interface</a>, where method chaining is used.
38 * In general, this class is supposed to be used like this template:
42 * UserdataBuilder createTarget(int fooXyzzy, int barBaz) {
43 * return new UserdataBuilderBuilder()
44 * .setFoo(new FooBuilder().setXyzzy(fooXyzzy).build())
45 * .setBar(new BarBuilder().setBaz(barBaz).build())
52 * This pattern is supported by the immutable nature of UserdataBuilder, as instances can be freely passed around
53 * without worrying about synchronization issues.
56 * As a side note: method chaining results in:
58 * <li>very efficient Java bytecode, as the method invocation result, in this case the Builder reference, is on the
59 * stack, so further method invocations just need to fill method arguments for the next method invocation, which is
60 * terminated by {@link #build()}, which is then returned from the method</li>
61 * <li>better understanding by humans, as the scope of mutable state (the builder) is kept to a minimum and is very
63 * <li>better optimization oportunities, as the object scope is minimized in terms of invocation (rather than method)
64 * stack, making <a href="https://en.wikipedia.org/wiki/Escape_analysis">escape analysis</a> a lot easier. Given enough
65 * compiler (JIT/AOT) prowess, the cost of th builder object can be completely eliminated</li>
68 * @see UserdataBuilder
72 @Generated("mdsal-binding-generator")
73 public class UserdataBuilder {
76 private String _value;
79 Map<Class<? extends Augmentation<Userdata>>, Augmentation<Userdata>> augmentation = Collections.emptyMap();
81 public UserdataBuilder() {}
85 public UserdataBuilder(Userdata base) {
86 Map<Class<? extends Augmentation<Userdata>>, Augmentation<Userdata>> aug = base.augmentations();
88 this.augmentation = new HashMap<>(aug);
90 this._id = base.getId();
91 this._value = base.getValue();
95 public String getId() {
99 public String getValue() {
103 @SuppressWarnings({"unchecked", "checkstyle:methodTypeParameterName"})
104 public <E$$ extends Augmentation<Userdata>> E$$ augmentation(Class<E$$> augmentationType) {
105 return (E$$) augmentation.get(Objects.requireNonNull(augmentationType));
109 public UserdataBuilder setId(final String value) {
114 public UserdataBuilder setValue(final String value) {
120 * Add an augmentation to this builder's product.
122 * @param augmentation augmentation to be added
123 * @return this builder
124 * @throws NullPointerException if {@code augmentation} is null
126 public UserdataBuilder addAugmentation(Augmentation<Userdata> augmentation) {
127 Class<? extends Augmentation<Userdata>> augmentationType = augmentation.implementedInterface();
128 if (!(this.augmentation instanceof HashMap)) {
129 this.augmentation = new HashMap<>();
132 this.augmentation.put(augmentationType, augmentation);
137 * Remove an augmentation from this builder's product. If this builder does not track such an augmentation type,
138 * this method does nothing.
140 * @param augmentationType augmentation type to be removed
141 * @return this builder
143 public UserdataBuilder removeAugmentation(Class<? extends Augmentation<Userdata>> augmentationType) {
144 if (this.augmentation instanceof HashMap) {
145 this.augmentation.remove(augmentationType);
151 public Userdata build() {
152 return new UserdataImpl(this);
155 private static final class UserdataImpl extends AbstractAugmentable<Userdata> implements Userdata {
157 private final String _id;
158 private final String _value;
160 UserdataImpl(UserdataBuilder base) {
161 super(base.augmentation);
162 this._id = base.getId();
163 this._value = base.getValue();
167 public String getId() {
172 public String getValue() {
176 private int hash = 0;
177 private volatile boolean hashValid = false;
180 public int hashCode() {
185 final int result = Userdata.bindingHashCode(this);
192 public boolean equals(Object obj) {
193 return Userdata.bindingEquals(this, obj);
197 public String toString() {
198 return Userdata.bindingToString(this);
202 public Class<? extends DataObject> implementedInterface() {
203 return Userdata.class;