TMP
[demos/microservices] / validate-user / src / main / java / de / trion / microservices / avro / User.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 User extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
17   private static final long serialVersionUID = 2154150202977610190L;
18   public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"User\",\"namespace\":\"de.trion.microservices.avro\",\"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<User> ENCODER =
24       new BinaryMessageEncoder<User>(MODEL$, SCHEMA$);
25
26   private static final BinaryMessageDecoder<User> DECODER =
27       new BinaryMessageDecoder<User>(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<User> 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<User> 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<User> createDecoder(SchemaStore resolver) {
51     return new BinaryMessageDecoder<User>(MODEL$, SCHEMA$, resolver);
52   }
53
54   /**
55    * Serializes this User 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 User from a ByteBuffer.
65    * @param b a byte buffer holding serialized data for an instance of this class
66    * @return a User 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 User fromByteBuffer(
70       java.nio.ByteBuffer b) throws java.io.IOException {
71     return DECODER.decode(b);
72   }
73
74   @Deprecated public long id;
75   @Deprecated public de.trion.microservices.avro.CustomerLevel level;
76   @Deprecated public java.lang.CharSequence name;
77
78   /**
79    * Default constructor.  Note that this does not initialize fields
80    * to their default values from the schema.  If that is desired then
81    * one should use <code>newBuilder()</code>.
82    */
83   public User() {}
84
85   /**
86    * All-args constructor.
87    * @param id The new value for id
88    * @param level The new value for level
89    * @param name The new value for name
90    */
91   public User(java.lang.Long id, de.trion.microservices.avro.CustomerLevel level, java.lang.CharSequence name) {
92     this.id = id;
93     this.level = level;
94     this.name = name;
95   }
96
97   public org.apache.avro.specific.SpecificData getSpecificData() { return MODEL$; }
98   public org.apache.avro.Schema getSchema() { return SCHEMA$; }
99   // Used by DatumWriter.  Applications should not call.
100   public java.lang.Object get(int field$) {
101     switch (field$) {
102     case 0: return id;
103     case 1: return level;
104     case 2: return name;
105     default: throw new org.apache.avro.AvroRuntimeException("Bad index");
106     }
107   }
108
109   // Used by DatumReader.  Applications should not call.
110   @SuppressWarnings(value="unchecked")
111   public void put(int field$, java.lang.Object value$) {
112     switch (field$) {
113     case 0: id = (java.lang.Long)value$; break;
114     case 1: level = (de.trion.microservices.avro.CustomerLevel)value$; break;
115     case 2: name = (java.lang.CharSequence)value$; break;
116     default: throw new org.apache.avro.AvroRuntimeException("Bad index");
117     }
118   }
119
120   /**
121    * Gets the value of the 'id' field.
122    * @return The value of the 'id' field.
123    */
124   public long getId() {
125     return id;
126   }
127
128
129   /**
130    * Sets the value of the 'id' field.
131    * @param value the value to set.
132    */
133   public void setId(long value) {
134     this.id = value;
135   }
136
137   /**
138    * Gets the value of the 'level' field.
139    * @return The value of the 'level' field.
140    */
141   public de.trion.microservices.avro.CustomerLevel getLevel() {
142     return level;
143   }
144
145
146   /**
147    * Sets the value of the 'level' field.
148    * @param value the value to set.
149    */
150   public void setLevel(de.trion.microservices.avro.CustomerLevel value) {
151     this.level = value;
152   }
153
154   /**
155    * Gets the value of the 'name' field.
156    * @return The value of the 'name' field.
157    */
158   public java.lang.CharSequence getName() {
159     return name;
160   }
161
162
163   /**
164    * Sets the value of the 'name' field.
165    * @param value the value to set.
166    */
167   public void setName(java.lang.CharSequence value) {
168     this.name = value;
169   }
170
171   /**
172    * Creates a new User RecordBuilder.
173    * @return A new User RecordBuilder
174    */
175   public static de.trion.microservices.avro.User.Builder newBuilder() {
176     return new de.trion.microservices.avro.User.Builder();
177   }
178
179   /**
180    * Creates a new User RecordBuilder by copying an existing Builder.
181    * @param other The existing builder to copy.
182    * @return A new User RecordBuilder
183    */
184   public static de.trion.microservices.avro.User.Builder newBuilder(de.trion.microservices.avro.User.Builder other) {
185     if (other == null) {
186       return new de.trion.microservices.avro.User.Builder();
187     } else {
188       return new de.trion.microservices.avro.User.Builder(other);
189     }
190   }
191
192   /**
193    * Creates a new User RecordBuilder by copying an existing User instance.
194    * @param other The existing instance to copy.
195    * @return A new User RecordBuilder
196    */
197   public static de.trion.microservices.avro.User.Builder newBuilder(de.trion.microservices.avro.User other) {
198     if (other == null) {
199       return new de.trion.microservices.avro.User.Builder();
200     } else {
201       return new de.trion.microservices.avro.User.Builder(other);
202     }
203   }
204
205   /**
206    * RecordBuilder for User instances.
207    */
208   public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<User>
209     implements org.apache.avro.data.RecordBuilder<User> {
210
211     private long id;
212     private de.trion.microservices.avro.CustomerLevel level;
213     private java.lang.CharSequence name;
214
215     /** Creates a new Builder */
216     private Builder() {
217       super(SCHEMA$);
218     }
219
220     /**
221      * Creates a Builder by copying an existing Builder.
222      * @param other The existing Builder to copy.
223      */
224     private Builder(de.trion.microservices.avro.User.Builder other) {
225       super(other);
226       if (isValidValue(fields()[0], other.id)) {
227         this.id = data().deepCopy(fields()[0].schema(), other.id);
228         fieldSetFlags()[0] = other.fieldSetFlags()[0];
229       }
230       if (isValidValue(fields()[1], other.level)) {
231         this.level = data().deepCopy(fields()[1].schema(), other.level);
232         fieldSetFlags()[1] = other.fieldSetFlags()[1];
233       }
234       if (isValidValue(fields()[2], other.name)) {
235         this.name = data().deepCopy(fields()[2].schema(), other.name);
236         fieldSetFlags()[2] = other.fieldSetFlags()[2];
237       }
238     }
239
240     /**
241      * Creates a Builder by copying an existing User instance
242      * @param other The existing instance to copy.
243      */
244     private Builder(de.trion.microservices.avro.User other) {
245       super(SCHEMA$);
246       if (isValidValue(fields()[0], other.id)) {
247         this.id = data().deepCopy(fields()[0].schema(), other.id);
248         fieldSetFlags()[0] = true;
249       }
250       if (isValidValue(fields()[1], other.level)) {
251         this.level = data().deepCopy(fields()[1].schema(), other.level);
252         fieldSetFlags()[1] = true;
253       }
254       if (isValidValue(fields()[2], other.name)) {
255         this.name = data().deepCopy(fields()[2].schema(), other.name);
256         fieldSetFlags()[2] = true;
257       }
258     }
259
260     /**
261       * Gets the value of the 'id' field.
262       * @return The value.
263       */
264     public long getId() {
265       return id;
266     }
267
268
269     /**
270       * Sets the value of the 'id' field.
271       * @param value The value of 'id'.
272       * @return This builder.
273       */
274     public de.trion.microservices.avro.User.Builder setId(long value) {
275       validate(fields()[0], value);
276       this.id = value;
277       fieldSetFlags()[0] = true;
278       return this;
279     }
280
281     /**
282       * Checks whether the 'id' field has been set.
283       * @return True if the 'id' field has been set, false otherwise.
284       */
285     public boolean hasId() {
286       return fieldSetFlags()[0];
287     }
288
289
290     /**
291       * Clears the value of the 'id' field.
292       * @return This builder.
293       */
294     public de.trion.microservices.avro.User.Builder clearId() {
295       fieldSetFlags()[0] = false;
296       return this;
297     }
298
299     /**
300       * Gets the value of the 'level' field.
301       * @return The value.
302       */
303     public de.trion.microservices.avro.CustomerLevel getLevel() {
304       return level;
305     }
306
307
308     /**
309       * Sets the value of the 'level' field.
310       * @param value The value of 'level'.
311       * @return This builder.
312       */
313     public de.trion.microservices.avro.User.Builder setLevel(de.trion.microservices.avro.CustomerLevel value) {
314       validate(fields()[1], value);
315       this.level = value;
316       fieldSetFlags()[1] = true;
317       return this;
318     }
319
320     /**
321       * Checks whether the 'level' field has been set.
322       * @return True if the 'level' field has been set, false otherwise.
323       */
324     public boolean hasLevel() {
325       return fieldSetFlags()[1];
326     }
327
328
329     /**
330       * Clears the value of the 'level' field.
331       * @return This builder.
332       */
333     public de.trion.microservices.avro.User.Builder clearLevel() {
334       level = null;
335       fieldSetFlags()[1] = false;
336       return this;
337     }
338
339     /**
340       * Gets the value of the 'name' field.
341       * @return The value.
342       */
343     public java.lang.CharSequence getName() {
344       return name;
345     }
346
347
348     /**
349       * Sets the value of the 'name' field.
350       * @param value The value of 'name'.
351       * @return This builder.
352       */
353     public de.trion.microservices.avro.User.Builder setName(java.lang.CharSequence value) {
354       validate(fields()[2], value);
355       this.name = value;
356       fieldSetFlags()[2] = true;
357       return this;
358     }
359
360     /**
361       * Checks whether the 'name' field has been set.
362       * @return True if the 'name' field has been set, false otherwise.
363       */
364     public boolean hasName() {
365       return fieldSetFlags()[2];
366     }
367
368
369     /**
370       * Clears the value of the 'name' field.
371       * @return This builder.
372       */
373     public de.trion.microservices.avro.User.Builder clearName() {
374       name = null;
375       fieldSetFlags()[2] = false;
376       return this;
377     }
378
379     @Override
380     @SuppressWarnings("unchecked")
381     public User build() {
382       try {
383         User record = new User();
384         record.id = fieldSetFlags()[0] ? this.id : (java.lang.Long) defaultValue(fields()[0]);
385         record.level = fieldSetFlags()[1] ? this.level : (de.trion.microservices.avro.CustomerLevel) defaultValue(fields()[1]);
386         record.name = fieldSetFlags()[2] ? this.name : (java.lang.CharSequence) defaultValue(fields()[2]);
387         return record;
388       } catch (org.apache.avro.AvroMissingFieldException e) {
389         throw e;
390       } catch (java.lang.Exception e) {
391         throw new org.apache.avro.AvroRuntimeException(e);
392       }
393     }
394   }
395
396   @SuppressWarnings("unchecked")
397   private static final org.apache.avro.io.DatumWriter<User>
398     WRITER$ = (org.apache.avro.io.DatumWriter<User>)MODEL$.createDatumWriter(SCHEMA$);
399
400   @Override public void writeExternal(java.io.ObjectOutput out)
401     throws java.io.IOException {
402     WRITER$.write(this, SpecificData.getEncoder(out));
403   }
404
405   @SuppressWarnings("unchecked")
406   private static final org.apache.avro.io.DatumReader<User>
407     READER$ = (org.apache.avro.io.DatumReader<User>)MODEL$.createDatumReader(SCHEMA$);
408
409   @Override public void readExternal(java.io.ObjectInput in)
410     throws java.io.IOException {
411     READER$.read(this, SpecificData.getDecoder(in));
412   }
413
414   @Override protected boolean hasCustomCoders() { return true; }
415
416   @Override public void customEncode(org.apache.avro.io.Encoder out)
417     throws java.io.IOException
418   {
419     out.writeLong(this.id);
420
421     out.writeEnum(this.level.ordinal());
422
423     out.writeString(this.name);
424
425   }
426
427   @Override public void customDecode(org.apache.avro.io.ResolvingDecoder in)
428     throws java.io.IOException
429   {
430     org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff();
431     if (fieldOrder == null) {
432       this.id = in.readLong();
433
434       this.level = de.trion.microservices.avro.CustomerLevel.values()[in.readEnum()];
435
436       this.name = in.readString(this.name instanceof Utf8 ? (Utf8)this.name : null);
437
438     } else {
439       for (int i = 0; i < 3; i++) {
440         switch (fieldOrder[i].pos()) {
441         case 0:
442           this.id = in.readLong();
443           break;
444
445         case 1:
446           this.level = de.trion.microservices.avro.CustomerLevel.values()[in.readEnum()];
447           break;
448
449         case 2:
450           this.name = in.readString(this.name instanceof Utf8 ? (Utf8)this.name : null);
451           break;
452
453         default:
454           throw new java.io.IOException("Corrupt ResolvingDecoder.");
455         }
456       }
457     }
458   }
459 }
460
461
462
463
464
465
466
467
468
469