d3b9cfb5a171f4522343786794173b7b5ccfd2f2
[demos/microservices] / validate-user / src / main / java / de / trion / microservices / avro / OrderAndUser.java
1 /**
2  * Autogenerated by Avro
3  *
4  * DO NOT EDIT DIRECTLY
5  */
6 package de.trion.microservices.avro;
7
8 import org.apache.avro.generic.GenericArray;
9 import org.apache.avro.specific.SpecificData;
10 import org.apache.avro.util.Utf8;
11 import org.apache.avro.message.BinaryMessageEncoder;
12 import org.apache.avro.message.BinaryMessageDecoder;
13 import org.apache.avro.message.SchemaStore;
14
15 @org.apache.avro.specific.AvroGenerated
16 public class OrderAndUser extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
17   private static final long serialVersionUID = 6432660008992245598L;
18   public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"OrderAndUser\",\"namespace\":\"de.trion.microservices.avro\",\"fields\":[{\"name\":\"order\",\"type\":{\"type\":\"record\",\"name\":\"Order\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"state\",\"type\":{\"type\":\"enum\",\"name\":\"OrderState\",\"symbols\":[\"CREATED\",\"APPROVED\",\"DECLINED\"],\"default\":\"CREATED\"}},{\"name\":\"customerId\",\"type\":\"long\"},{\"name\":\"orderId\",\"type\":\"long\"},{\"name\":\"productId\",\"type\":\"long\"},{\"name\":\"quantity\",\"type\":\"int\"}]}},{\"name\":\"user\",\"type\":[\"null\",{\"type\":\"record\",\"name\":\"User\",\"fields\":[{\"name\":\"id\",\"type\":\"long\"},{\"name\":\"level\",\"type\":{\"type\":\"enum\",\"name\":\"CustomerLevel\",\"symbols\":[\"BRONZE\",\"SILVER\",\"GOLD\",\"UNWANTED\"]}},{\"name\":\"name\",\"type\":\"string\"}]}]}]}");
19   public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
20
21   private static SpecificData MODEL$ = new SpecificData();
22
23   private static final BinaryMessageEncoder<OrderAndUser> ENCODER =
24       new BinaryMessageEncoder<OrderAndUser>(MODEL$, SCHEMA$);
25
26   private static final BinaryMessageDecoder<OrderAndUser> DECODER =
27       new BinaryMessageDecoder<OrderAndUser>(MODEL$, SCHEMA$);
28
29   /**
30    * Return the BinaryMessageEncoder instance used by this class.
31    * @return the message encoder used by this class
32    */
33   public static BinaryMessageEncoder<OrderAndUser> getEncoder() {
34     return ENCODER;
35   }
36
37   /**
38    * Return the BinaryMessageDecoder instance used by this class.
39    * @return the message decoder used by this class
40    */
41   public static BinaryMessageDecoder<OrderAndUser> getDecoder() {
42     return DECODER;
43   }
44
45   /**
46    * Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}.
47    * @param resolver a {@link SchemaStore} used to find schemas by fingerprint
48    * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore
49    */
50   public static BinaryMessageDecoder<OrderAndUser> createDecoder(SchemaStore resolver) {
51     return new BinaryMessageDecoder<OrderAndUser>(MODEL$, SCHEMA$, resolver);
52   }
53
54   /**
55    * Serializes this OrderAndUser to a ByteBuffer.
56    * @return a buffer holding the serialized data for this instance
57    * @throws java.io.IOException if this instance could not be serialized
58    */
59   public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException {
60     return ENCODER.encode(this);
61   }
62
63   /**
64    * Deserializes a OrderAndUser from a ByteBuffer.
65    * @param b a byte buffer holding serialized data for an instance of this class
66    * @return a OrderAndUser instance decoded from the given buffer
67    * @throws java.io.IOException if the given bytes could not be deserialized into an instance of this class
68    */
69   public static OrderAndUser fromByteBuffer(
70       java.nio.ByteBuffer b) throws java.io.IOException {
71     return DECODER.decode(b);
72   }
73
74   @Deprecated public de.trion.microservices.avro.Order order;
75   @Deprecated public de.trion.microservices.avro.User user;
76
77   /**
78    * Default constructor.  Note that this does not initialize fields
79    * to their default values from the schema.  If that is desired then
80    * one should use <code>newBuilder()</code>.
81    */
82   public OrderAndUser() {}
83
84   /**
85    * All-args constructor.
86    * @param order The new value for order
87    * @param user The new value for user
88    */
89   public OrderAndUser(de.trion.microservices.avro.Order order, de.trion.microservices.avro.User user) {
90     this.order = order;
91     this.user = user;
92   }
93
94   public org.apache.avro.specific.SpecificData getSpecificData() { return MODEL$; }
95   public org.apache.avro.Schema getSchema() { return SCHEMA$; }
96   // Used by DatumWriter.  Applications should not call.
97   public java.lang.Object get(int field$) {
98     switch (field$) {
99     case 0: return order;
100     case 1: return user;
101     default: throw new org.apache.avro.AvroRuntimeException("Bad index");
102     }
103   }
104
105   // Used by DatumReader.  Applications should not call.
106   @SuppressWarnings(value="unchecked")
107   public void put(int field$, java.lang.Object value$) {
108     switch (field$) {
109     case 0: order = (de.trion.microservices.avro.Order)value$; break;
110     case 1: user = (de.trion.microservices.avro.User)value$; break;
111     default: throw new org.apache.avro.AvroRuntimeException("Bad index");
112     }
113   }
114
115   /**
116    * Gets the value of the 'order' field.
117    * @return The value of the 'order' field.
118    */
119   public de.trion.microservices.avro.Order getOrder() {
120     return order;
121   }
122
123
124   /**
125    * Sets the value of the 'order' field.
126    * @param value the value to set.
127    */
128   public void setOrder(de.trion.microservices.avro.Order value) {
129     this.order = value;
130   }
131
132   /**
133    * Gets the value of the 'user' field.
134    * @return The value of the 'user' field.
135    */
136   public de.trion.microservices.avro.User getUser() {
137     return user;
138   }
139
140
141   /**
142    * Sets the value of the 'user' field.
143    * @param value the value to set.
144    */
145   public void setUser(de.trion.microservices.avro.User value) {
146     this.user = value;
147   }
148
149   /**
150    * Creates a new OrderAndUser RecordBuilder.
151    * @return A new OrderAndUser RecordBuilder
152    */
153   public static de.trion.microservices.avro.OrderAndUser.Builder newBuilder() {
154     return new de.trion.microservices.avro.OrderAndUser.Builder();
155   }
156
157   /**
158    * Creates a new OrderAndUser RecordBuilder by copying an existing Builder.
159    * @param other The existing builder to copy.
160    * @return A new OrderAndUser RecordBuilder
161    */
162   public static de.trion.microservices.avro.OrderAndUser.Builder newBuilder(de.trion.microservices.avro.OrderAndUser.Builder other) {
163     if (other == null) {
164       return new de.trion.microservices.avro.OrderAndUser.Builder();
165     } else {
166       return new de.trion.microservices.avro.OrderAndUser.Builder(other);
167     }
168   }
169
170   /**
171    * Creates a new OrderAndUser RecordBuilder by copying an existing OrderAndUser instance.
172    * @param other The existing instance to copy.
173    * @return A new OrderAndUser RecordBuilder
174    */
175   public static de.trion.microservices.avro.OrderAndUser.Builder newBuilder(de.trion.microservices.avro.OrderAndUser other) {
176     if (other == null) {
177       return new de.trion.microservices.avro.OrderAndUser.Builder();
178     } else {
179       return new de.trion.microservices.avro.OrderAndUser.Builder(other);
180     }
181   }
182
183   /**
184    * RecordBuilder for OrderAndUser instances.
185    */
186   public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<OrderAndUser>
187     implements org.apache.avro.data.RecordBuilder<OrderAndUser> {
188
189     private de.trion.microservices.avro.Order order;
190     private de.trion.microservices.avro.Order.Builder orderBuilder;
191     private de.trion.microservices.avro.User user;
192     private de.trion.microservices.avro.User.Builder userBuilder;
193
194     /** Creates a new Builder */
195     private Builder() {
196       super(SCHEMA$);
197     }
198
199     /**
200      * Creates a Builder by copying an existing Builder.
201      * @param other The existing Builder to copy.
202      */
203     private Builder(de.trion.microservices.avro.OrderAndUser.Builder other) {
204       super(other);
205       if (isValidValue(fields()[0], other.order)) {
206         this.order = data().deepCopy(fields()[0].schema(), other.order);
207         fieldSetFlags()[0] = other.fieldSetFlags()[0];
208       }
209       if (other.hasOrderBuilder()) {
210         this.orderBuilder = de.trion.microservices.avro.Order.newBuilder(other.getOrderBuilder());
211       }
212       if (isValidValue(fields()[1], other.user)) {
213         this.user = data().deepCopy(fields()[1].schema(), other.user);
214         fieldSetFlags()[1] = other.fieldSetFlags()[1];
215       }
216       if (other.hasUserBuilder()) {
217         this.userBuilder = de.trion.microservices.avro.User.newBuilder(other.getUserBuilder());
218       }
219     }
220
221     /**
222      * Creates a Builder by copying an existing OrderAndUser instance
223      * @param other The existing instance to copy.
224      */
225     private Builder(de.trion.microservices.avro.OrderAndUser other) {
226       super(SCHEMA$);
227       if (isValidValue(fields()[0], other.order)) {
228         this.order = data().deepCopy(fields()[0].schema(), other.order);
229         fieldSetFlags()[0] = true;
230       }
231       this.orderBuilder = null;
232       if (isValidValue(fields()[1], other.user)) {
233         this.user = data().deepCopy(fields()[1].schema(), other.user);
234         fieldSetFlags()[1] = true;
235       }
236       this.userBuilder = null;
237     }
238
239     /**
240       * Gets the value of the 'order' field.
241       * @return The value.
242       */
243     public de.trion.microservices.avro.Order getOrder() {
244       return order;
245     }
246
247
248     /**
249       * Sets the value of the 'order' field.
250       * @param value The value of 'order'.
251       * @return This builder.
252       */
253     public de.trion.microservices.avro.OrderAndUser.Builder setOrder(de.trion.microservices.avro.Order value) {
254       validate(fields()[0], value);
255       this.orderBuilder = null;
256       this.order = value;
257       fieldSetFlags()[0] = true;
258       return this;
259     }
260
261     /**
262       * Checks whether the 'order' field has been set.
263       * @return True if the 'order' field has been set, false otherwise.
264       */
265     public boolean hasOrder() {
266       return fieldSetFlags()[0];
267     }
268
269     /**
270      * Gets the Builder instance for the 'order' field and creates one if it doesn't exist yet.
271      * @return This builder.
272      */
273     public de.trion.microservices.avro.Order.Builder getOrderBuilder() {
274       if (orderBuilder == null) {
275         if (hasOrder()) {
276           setOrderBuilder(de.trion.microservices.avro.Order.newBuilder(order));
277         } else {
278           setOrderBuilder(de.trion.microservices.avro.Order.newBuilder());
279         }
280       }
281       return orderBuilder;
282     }
283
284     /**
285      * Sets the Builder instance for the 'order' field
286      * @param value The builder instance that must be set.
287      * @return This builder.
288      */
289     public de.trion.microservices.avro.OrderAndUser.Builder setOrderBuilder(de.trion.microservices.avro.Order.Builder value) {
290       clearOrder();
291       orderBuilder = value;
292       return this;
293     }
294
295     /**
296      * Checks whether the 'order' field has an active Builder instance
297      * @return True if the 'order' field has an active Builder instance
298      */
299     public boolean hasOrderBuilder() {
300       return orderBuilder != null;
301     }
302
303     /**
304       * Clears the value of the 'order' field.
305       * @return This builder.
306       */
307     public de.trion.microservices.avro.OrderAndUser.Builder clearOrder() {
308       order = null;
309       orderBuilder = null;
310       fieldSetFlags()[0] = false;
311       return this;
312     }
313
314     /**
315       * Gets the value of the 'user' field.
316       * @return The value.
317       */
318     public de.trion.microservices.avro.User getUser() {
319       return user;
320     }
321
322
323     /**
324       * Sets the value of the 'user' field.
325       * @param value The value of 'user'.
326       * @return This builder.
327       */
328     public de.trion.microservices.avro.OrderAndUser.Builder setUser(de.trion.microservices.avro.User value) {
329       validate(fields()[1], value);
330       this.userBuilder = null;
331       this.user = value;
332       fieldSetFlags()[1] = true;
333       return this;
334     }
335
336     /**
337       * Checks whether the 'user' field has been set.
338       * @return True if the 'user' field has been set, false otherwise.
339       */
340     public boolean hasUser() {
341       return fieldSetFlags()[1];
342     }
343
344     /**
345      * Gets the Builder instance for the 'user' field and creates one if it doesn't exist yet.
346      * @return This builder.
347      */
348     public de.trion.microservices.avro.User.Builder getUserBuilder() {
349       if (userBuilder == null) {
350         if (hasUser()) {
351           setUserBuilder(de.trion.microservices.avro.User.newBuilder(user));
352         } else {
353           setUserBuilder(de.trion.microservices.avro.User.newBuilder());
354         }
355       }
356       return userBuilder;
357     }
358
359     /**
360      * Sets the Builder instance for the 'user' field
361      * @param value The builder instance that must be set.
362      * @return This builder.
363      */
364     public de.trion.microservices.avro.OrderAndUser.Builder setUserBuilder(de.trion.microservices.avro.User.Builder value) {
365       clearUser();
366       userBuilder = value;
367       return this;
368     }
369
370     /**
371      * Checks whether the 'user' field has an active Builder instance
372      * @return True if the 'user' field has an active Builder instance
373      */
374     public boolean hasUserBuilder() {
375       return userBuilder != null;
376     }
377
378     /**
379       * Clears the value of the 'user' field.
380       * @return This builder.
381       */
382     public de.trion.microservices.avro.OrderAndUser.Builder clearUser() {
383       user = null;
384       userBuilder = null;
385       fieldSetFlags()[1] = false;
386       return this;
387     }
388
389     @Override
390     @SuppressWarnings("unchecked")
391     public OrderAndUser build() {
392       try {
393         OrderAndUser record = new OrderAndUser();
394         if (orderBuilder != null) {
395           try {
396             record.order = this.orderBuilder.build();
397           } catch (org.apache.avro.AvroMissingFieldException e) {
398             e.addParentField(record.getSchema().getField("order"));
399             throw e;
400           }
401         } else {
402           record.order = fieldSetFlags()[0] ? this.order : (de.trion.microservices.avro.Order) defaultValue(fields()[0]);
403         }
404         if (userBuilder != null) {
405           try {
406             record.user = this.userBuilder.build();
407           } catch (org.apache.avro.AvroMissingFieldException e) {
408             e.addParentField(record.getSchema().getField("user"));
409             throw e;
410           }
411         } else {
412           record.user = fieldSetFlags()[1] ? this.user : (de.trion.microservices.avro.User) defaultValue(fields()[1]);
413         }
414         return record;
415       } catch (org.apache.avro.AvroMissingFieldException e) {
416         throw e;
417       } catch (java.lang.Exception e) {
418         throw new org.apache.avro.AvroRuntimeException(e);
419       }
420     }
421   }
422
423   @SuppressWarnings("unchecked")
424   private static final org.apache.avro.io.DatumWriter<OrderAndUser>
425     WRITER$ = (org.apache.avro.io.DatumWriter<OrderAndUser>)MODEL$.createDatumWriter(SCHEMA$);
426
427   @Override public void writeExternal(java.io.ObjectOutput out)
428     throws java.io.IOException {
429     WRITER$.write(this, SpecificData.getEncoder(out));
430   }
431
432   @SuppressWarnings("unchecked")
433   private static final org.apache.avro.io.DatumReader<OrderAndUser>
434     READER$ = (org.apache.avro.io.DatumReader<OrderAndUser>)MODEL$.createDatumReader(SCHEMA$);
435
436   @Override public void readExternal(java.io.ObjectInput in)
437     throws java.io.IOException {
438     READER$.read(this, SpecificData.getDecoder(in));
439   }
440
441   @Override protected boolean hasCustomCoders() { return true; }
442
443   @Override public void customEncode(org.apache.avro.io.Encoder out)
444     throws java.io.IOException
445   {
446     this.order.customEncode(out);
447
448     if (this.user == null) {
449       out.writeIndex(0);
450       out.writeNull();
451     } else {
452       out.writeIndex(1);
453       this.user.customEncode(out);
454     }
455
456   }
457
458   @Override public void customDecode(org.apache.avro.io.ResolvingDecoder in)
459     throws java.io.IOException
460   {
461     org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff();
462     if (fieldOrder == null) {
463       if (this.order == null) {
464         this.order = new de.trion.microservices.avro.Order();
465       }
466       this.order.customDecode(in);
467
468       if (in.readIndex() != 1) {
469         in.readNull();
470         this.user = null;
471       } else {
472         if (this.user == null) {
473           this.user = new de.trion.microservices.avro.User();
474         }
475         this.user.customDecode(in);
476       }
477
478     } else {
479       for (int i = 0; i < 2; i++) {
480         switch (fieldOrder[i].pos()) {
481         case 0:
482           if (this.order == null) {
483             this.order = new de.trion.microservices.avro.Order();
484           }
485           this.order.customDecode(in);
486           break;
487
488         case 1:
489           if (in.readIndex() != 1) {
490             in.readNull();
491             this.user = null;
492           } else {
493             if (this.user == null) {
494               this.user = new de.trion.microservices.avro.User();
495             }
496             this.user.customDecode(in);
497           }
498           break;
499
500         default:
501           throw new java.io.IOException("Corrupt ResolvingDecoder.");
502         }
503       }
504     }
505   }
506 }
507
508
509
510
511
512
513
514
515
516