be5d73aabf62c17a3b5a33b63f908a9c22bf7449
[mdsal.git] / binding2 / prototype / src / test / java / org / opendaylight / yang / gen / v1 / urn / test / mainyangtest / grp / main / group / main / group / cont / main / group / cont / choice / ABuilder.java
1 package org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice;
2 import org.opendaylight.yangtools.yang.binding.Augmentation;
3 import org.opendaylight.yangtools.yang.binding.AugmentationHolder;
4 import org.opendaylight.yangtools.yang.binding.TreeNode;
5 import java.util.HashMap;
6 import org.opendaylight.yangtools.concepts.Builder;
7 import java.util.Objects;
8 import java.util.Collections;
9 import java.util.Map;
10
11
12 /**
13  * Class that builds {@link org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A} instances.
14  *
15  * @see org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A
16  *
17  */
18 public class ABuilder implements Builder <org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A> {
19
20     private java.lang.String _case1;
21
22     Map<java.lang.Class<? extends Augmentation<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A>>, Augmentation<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A>> augmentation = Collections.emptyMap();
23
24     public ABuilder() {
25     }
26
27     public ABuilder(A base) {
28         this._case1 = base.getCase1();
29         if (base instanceof AImpl) {
30             AImpl impl = (AImpl) base;
31             if (!impl.augmentation.isEmpty()) {
32                 this.augmentation = new HashMap<>(impl.augmentation);
33             }
34         } else if (base instanceof AugmentationHolder) {
35             @SuppressWarnings("unchecked")
36             AugmentationHolder<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A> casted =(AugmentationHolder<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A>) base;
37             if (!casted.augmentations().isEmpty()) {
38                 this.augmentation = new HashMap<>(casted.augmentations());
39             }
40         }
41     }
42
43
44     public java.lang.String getCase1() {
45         return _case1;
46     }
47
48     @SuppressWarnings("unchecked")
49     public <E extends Augmentation<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A>> E getAugmentation(java.lang.Class<E> augmentationType) {
50         if (augmentationType == null) {
51             throw new IllegalArgumentException("Augmentation Type reference cannot be NULL!");
52         }
53         return (E) augmentation.get(augmentationType);
54     }
55
56
57     public ABuilder setCase1(final java.lang.String value) {
58         this._case1 = value;
59         return this;
60     }
61
62     public ABuilder addAugmentation(java.lang.Class<? extends Augmentation<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A>> augmentationType, Augmentation<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A> augmentation) {
63         if (augmentation == null) {
64             return removeAugmentation(augmentationType);
65         }
66
67         if (!(this.augmentation instanceof HashMap)) {
68             this.augmentation = new HashMap<>();
69         }
70
71         this.augmentation.put(augmentationType, augmentation);
72         return this;
73     }
74
75     public ABuilder removeAugmentation(java.lang.Class<? extends Augmentation<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A>> augmentationType) {
76         if (this.augmentation instanceof HashMap) {
77             this.augmentation.remove(augmentationType);
78         }
79         return this;
80     }
81
82     public A build() {
83         return new AImpl(this);
84     }
85
86     private static final class AImpl implements A {
87
88         public java.lang.Class<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A> implementedInterface() {
89             return org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A.class;
90         }
91
92         private final java.lang.String _case1;
93
94         private Map<java.lang.Class<? extends Augmentation<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A>>, Augmentation<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A>> augmentation = Collections.emptyMap();
95
96         private AImpl(ABuilder base) {
97             this._case1 = base.getCase1();
98             switch (base.augmentation.size()) {
99             case 0:
100                 this.augmentation = Collections.emptyMap();
101                 break;
102             case 1:
103                 final Map.Entry<java.lang.Class<? extends Augmentation<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A>>, Augmentation<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A>> e = base.augmentation.entrySet().iterator().next();
104                 this.augmentation = Collections.<java.lang.Class<? extends Augmentation<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A>>, Augmentation<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A>>singletonMap(e.getKey(), e.getValue());
105                 break;
106             default :
107                 this.augmentation = new HashMap<>(base.augmentation);
108             }
109         }
110
111         @Override
112         public java.lang.String getCase1() {
113             return _case1;
114         }
115
116         @SuppressWarnings("unchecked")
117         @Override
118         public <E extends Augmentation<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A>> E getAugmentation(java.lang.Class<E> augmentationType) {
119             if (augmentationType == null) {
120                 throw new IllegalArgumentException("Augmentation Type reference cannot be NULL!");
121             }
122             return (E) augmentation.get(augmentationType);
123         }
124
125         private int hash = 0;
126         private volatile boolean hashValid = false;
127
128         @Override
129         public int hashCode() {
130             if (hashValid) {
131                 return hash;
132             }
133
134             final int prime = 31;
135             int result = 1;
136             result = prime * result + Objects.hashCode(_case1);
137             result = prime * result + Objects.hashCode(augmentation);
138
139             hash = result;
140             hashValid = true;
141             return result;
142         }
143
144         @Override
145         public boolean equals(java.lang.Object obj) {
146             if (this == obj) {
147                 return true;
148             }
149             if (!(obj instanceof TreeNode)) {
150                 return false;
151             }
152             if (!org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A.class.equals(((TreeNode)obj).implementedInterface())) {
153                 return false;
154             }
155             org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A other = (org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A)obj;
156             if (!Objects.equals(_case1, other.getCase1())) {
157                 return false;
158             }
159             if (getClass() == obj.getClass()) {
160                 // Simple case: we are comparing against self
161                 AImpl otherImpl = (AImpl) obj;
162                 if (!Objects.equals(augmentation, otherImpl.augmentation)) {
163                     return false;
164                 }
165             } else {
166                 // Hard case: compare our augments with presence there...
167                 for (Map.Entry<java.lang.Class<? extends Augmentation<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A>>, Augmentation<org.opendaylight.yang.gen.v1.urn.test.mainyangtest.grp.main.group.main.group.cont.main.group.cont.choice.A>> e : augmentation.entrySet()) {
168                     if (!e.getValue().equals(other.getAugmentation(e.getKey()))) {
169                         return false;
170                     }
171                 }
172                 // .. and give the other one the chance to do the same
173                 if (!obj.equals(this)) {
174                     return false;
175                 }
176             }
177             return true;
178         }
179
180         @Override
181         public java.lang.String toString() {
182             java.lang.StringBuilder builder = new java.lang.StringBuilder ("A [");
183             boolean first = true;
184
185             if (_case1 != null) {
186                 if (first) {
187                     first = false;
188                 } else {
189                     builder.append(", ");
190                 }
191                 builder.append("_case1=");
192                 builder.append(_case1);
193              }
194             if (first) {
195                 first = false;
196             } else {
197                 builder.append(", ");
198             }
199             builder.append("augmentation=");
200             builder.append(augmentation.values());
201             return builder.append(']').toString();
202         }
203     }
204
205 }