View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.giraph.io.gora.generated;
19  
20  /**
21   * Example class for defining a Giraph-vertex.
22   */
23  @SuppressWarnings("all")
24  public class GVertex extends org.apache.gora.persistency.impl.PersistentBase
25      implements org.apache.avro.specific.SpecificRecord,
26      org.apache.gora.persistency.Persistent {
27  
28    /**
29     * Schema used for the class.
30     */
31    public static final org.apache.avro.Schema SCHEMAS =
32        new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\"," +
33              "\"name\":\"GVertex\"," +
34              "\"namespace\":\"org.apache.giraph.io.gora.generated\"," +
35              "\"fields\":[{\"name\":\"vertexId\",\"type\":\"string\"}," +
36              "{\"name\":\"vertexValue\",\"type\":\"float\"}," +
37              "{\"name\":\"edges\",\"type\":" +
38              "{\"type\":\"map\",\"values\":\"string\"}}]}");
39  
40    /** Enum containing all data bean's fields. */
41    public static enum Field {
42      /**
43       * Vertex id.
44       */
45      VERTEX_ID(0, "vertexId"),
46  
47      /**
48       * Vertex value.
49       */
50      VERTEX_VALUE(1, "vertexValue"),
51  
52      /**
53       * Vertex edges.
54       */
55      EDGES(2, "edges");
56  
57      /**
58       * Field's index.
59       */
60      private int index;
61  
62      /**
63       * Field's name.
64       */
65      private String name;
66  
67      /**
68       * Field's constructor
69       * @param index field's index.
70       * @param name field's name.
71       */
72      Field(int index, String name) {
73        this.index = index;
74        this.name = name;
75      }
76  
77      /**
78       * Gets field's index.
79       * @return int field's index.
80       */
81      public int getIndex() {
82        return index;
83      }
84  
85      /**
86       * Gets field's name.
87       * @return String field's name.
88       */
89      public String getName() {
90        return name;
91      }
92  
93      /**
94       * Gets field's attributes to string.
95       * @return String field's attributes to string.
96       */
97      public String toString() {
98        return name;
99      }
100   };
101 
102   /**
103    * Array containing all fields/
104    */
105   private static final String[] ALL_FIELDS = {
106     "vertexId", "vertexValue", "edges", };
107 
108   /**
109    * Tombstone.
110    */
111   private static final Tombstone TOMBSTONE = new Tombstone();
112 
113   /**
114    * vertexId.
115    */
116   private java.lang.CharSequence vertexId;
117 
118   /**
119    * vertexValue.
120    */
121   private float vertexValue;
122 
123   /**
124    * edges.
125    */
126   private java.util.Map<java.lang.CharSequence, java.lang.CharSequence> edges;
127 
128   /**
129    * Gets the total field count.
130    * @return int field count
131    */
132   public int getFieldsCount() {
133     return GVertex.ALL_FIELDS.length;
134   }
135 
136   /**
137    * Gets the schema
138    * @return Schema
139    */
140   public org.apache.avro.Schema getSchema() {
141     return SCHEMAS;
142   }
143 
144   /**
145    * Gets field
146    * @param field index field.
147    * @return Object from an index.
148    */
149   public java.lang.Object get(int field) {
150     switch (field) {
151     case 0:
152       return vertexId;
153     case 1:
154       return vertexValue;
155     case 2:
156       return edges;
157     default:
158       throw new org.apache.avro.AvroRuntimeException("Bad index");
159     }
160   }
161 
162   /**
163    * Puts a value into a field.
164    * @param field index of field used.
165    * @param value value of field used.
166    */
167   @SuppressWarnings(value = "unchecked")
168   public void put(int field, java.lang.Object value) {
169     switch (field) {
170     case 0:
171       vertexId = (java.lang.CharSequence) value;
172       break;
173     case 1:
174       vertexValue = (java.lang.Float) value;
175       break;
176     case 2:
177       edges = (java.util.Map<java.lang.CharSequence, java.lang.CharSequence>)
178         ((value instanceof org.apache.gora.persistency.Dirtyable) ? value :
179         new org.apache.gora.persistency.impl.DirtyMapWrapper((java.util.Map)
180             value));
181       break;
182     default:
183       throw new org.apache.avro.AvroRuntimeException("Bad index");
184     }
185   }
186 
187   /**
188    * Gets the value of the 'vertexId' field.
189    * @return CharSequence
190    */
191   public java.lang.CharSequence getVertexId() {
192     return vertexId;
193   }
194 
195   /**
196    * Sets the value of the 'vertexId' field.
197    * @param value the value to set.
198    */
199   public void setVertexId(java.lang.CharSequence value) {
200     this.vertexId = value;
201     setDirty(0);
202   }
203 
204   /**
205    * Checks the dirty status of the 'vertexId' field. A field is dirty if it
206    * represents a change that has not yet been written to the database.
207    * @param value the value to set.
208    * @return boolean
209    */
210   public boolean isVertexIdDirty(java.lang.CharSequence value) {
211     return isDirty(0);
212   }
213 
214   /**
215    * Gets the value of the 'vertexValue' field.
216    * @return Float
217    */
218   public java.lang.Float getVertexValue() {
219     return vertexValue;
220   }
221 
222   /**
223    * Sets the value of the 'vertexValue' field.
224    * @param value the value to set.
225    */
226   public void setVertexValue(java.lang.Float value) {
227     this.vertexValue = value;
228     setDirty(1);
229   }
230 
231   /**
232    * Checks the dirty status of the 'vertexValue' field. A field is dirty if it
233    * represents a change that has not yet been written to the database.
234    * @param value the value to set.
235    * @return boolean
236    */
237   public boolean isVertexValueDirty(java.lang.Float value) {
238     return isDirty(1);
239   }
240 
241   /**
242    * Gets the value of the 'edges' field.
243    * @return java.util.Map
244    */
245   public java.util.Map<java.lang.CharSequence, java.lang.CharSequence>
246   getEdges() {
247     return edges;
248   }
249 
250   /**
251    * Sets the value of the 'edges' field.
252    * @param value the value to set.
253    */
254   public void setEdges(
255       java.util.Map<java.lang.CharSequence, java.lang.CharSequence> value) {
256     this.edges =
257       (value instanceof org.apache.gora.persistency.Dirtyable) ? value :
258       new org.apache.gora.persistency.impl.DirtyMapWrapper(value);
259     setDirty(2);
260   }
261 
262   /**
263    * Checks the dirty status of the 'edges' field. A field is dirty if it
264    * represents a change that has not yet been written to the database.
265    * @param value the value to set.
266    * @return boolean
267    */
268   public boolean isEdgesDirty(
269       java.util.Map<java.lang.CharSequence, java.lang.CharSequence> value) {
270     return isDirty(2);
271   }
272 
273   /**
274    * Creates a new GVertex RecordBuilder.
275    * @return GVertex.Builder
276    */
277   public static org.apache.giraph.io.gora.generated.GVertex.Builder
278   newBuilder() {
279     return new org.apache.giraph.io.gora.generated.GVertex.Builder();
280   }
281 
282   /**
283    * Creates a new GVertex RecordBuilder by copying an existing Builder.
284    * @param other GVertex.Builder
285    * @return GVertex.Builder
286    */
287   public static org.apache.giraph.io.gora.generated.GVertex.Builder newBuilder(
288       org.apache.giraph.io.gora.generated.GVertex.Builder other) {
289     return new org.apache.giraph.io.gora.generated.GVertex.Builder(other);
290   }
291 
292   /**
293    * Creates a new GVertex RecordBuilder by copying
294    * an existing GVertex instance
295    * @param other GVertex
296    * @return GVertex.Builder
297    */
298   public static org.apache.giraph.io.gora.generated.GVertex.Builder newBuilder(
299       org.apache.giraph.io.gora.generated.GVertex other) {
300     return new org.apache.giraph.io.gora.generated.GVertex.Builder(other);
301   }
302 
303   /**
304    * Makes a deep copy from a bytebuffer.
305    * @param input ByteBuffer
306    * @return ByteBuffer
307    */
308   private static java.nio.ByteBuffer deepCopyToReadOnlyBuffer(
309       java.nio.ByteBuffer input) {
310     java.nio.ByteBuffer copy = java.nio.ByteBuffer.allocate(input.capacity());
311     int position = input.position();
312     input.reset();
313     int mark = input.position();
314     int limit = input.limit();
315     input.rewind();
316     input.limit(input.capacity());
317     copy.put(input);
318     input.rewind();
319     copy.rewind();
320     input.position(mark);
321     input.mark();
322     copy.position(mark);
323     copy.mark();
324     input.position(position);
325     copy.position(position);
326     input.limit(limit);
327     copy.limit(limit);
328     return copy.asReadOnlyBuffer();
329   }
330 
331   /**
332    * RecordBuilder for GVertex instances.
333    */
334   public static class Builder extends
335       org.apache.avro.specific.SpecificRecordBuilderBase<GVertex> implements
336       org.apache.avro.data.RecordBuilder<GVertex> {
337 
338     /**
339      * vertexId
340      */
341     private java.lang.CharSequence vertexId;
342 
343     /**
344      * vertexValue
345      */
346     private float vertexValue;
347 
348     /**
349      * edges
350      */
351     private java.util.Map<java.lang.CharSequence, java.lang.CharSequence> edges;
352 
353     /** Creates a new Builder */
354     private Builder() {
355       super(org.apache.giraph.io.gora.generated.GVertex.SCHEMAS);
356     }
357 
358     /**
359      * Creates a Builder by copying an existing Builder.
360      * @param other GVertex
361      */
362     private Builder(org.apache.giraph.io.gora.generated.GVertex.Builder other) {
363       super(other);
364     }
365 
366     /**
367      * Creates a Builder by copying an existing GVertex instance.
368      * @param other GVertex
369      */
370     // CHECKSTYLE: stop Indentation
371     private Builder(org.apache.giraph.io.gora.generated.GVertex other) {
372       super(org.apache.giraph.io.gora.generated.GVertex.SCHEMAS);
373       if (isValidValue(fields()[0], other.vertexId)) {
374         this.vertexId = (java.lang.CharSequence) data().deepCopy(
375             fields()[0].schema(), other.vertexId);
376         fieldSetFlags()[0] = true;
377       }
378       if (isValidValue(fields()[1], other.vertexValue)) {
379         this.vertexValue = (java.lang.Float) data().deepCopy(
380             fields()[1].schema(), other.vertexValue);
381         fieldSetFlags()[1] = true;
382       }
383       if (isValidValue(fields()[2], other.edges)) {
384         this.edges =
385             (java.util.Map<java.lang.CharSequence, java.lang.CharSequence>)
386             data().deepCopy(fields()[2].schema(), other.edges);
387         fieldSetFlags()[2] = true;
388       }
389     }
390     // CHECKSTYLE: resume Indentation
391 
392     /**
393      * Gets the value of the 'vertexId' field.
394      * @return CharSsequence
395      */
396     public java.lang.CharSequence getVertexId() {
397       return vertexId;
398     }
399 
400     /**
401      * Sets the value of the 'vertexId' field.
402      * @param value CharSequence
403      * @return GVertex.Builder
404      */
405     // CHECKSTYLE: stop Indentation
406     public org.apache.giraph.io.gora.generated.GVertex.Builder setVertexId(
407         java.lang.CharSequence value) {
408       validate(fields()[0], value);
409       this.vertexId = value;
410       fieldSetFlags()[0] = true;
411       return this;
412     }
413     // CHECKSTYLE: resume Indentation
414 
415     /**
416      * Checks whether the 'vertexId' field has been set.
417      * @return boolean
418      */
419     public boolean hasVertexId() {
420       return fieldSetFlags()[0];
421     }
422 
423     /**
424      * Clears the value of the 'vertexId' field
425      * @return GVertex.Builder
426      */
427     // CHECKSTYLE: stop Indentation
428     public org.apache.giraph.io.gora.generated.GVertex.Builder clearVertexId() {
429       vertexId = null;
430       fieldSetFlags()[0] = false;
431       return this;
432     }
433    // CHECKSTYLE: resume Indentation
434 
435     /**
436      * Gets the value of the 'vertexValue' field
437      * @return Float
438      */
439     public java.lang.Float getVertexValue() {
440       return vertexValue;
441     }
442 
443     /**
444      * Sets the value of the 'vertexValue' field.
445      * @param value float
446      * @return GVertex.Builder
447      */
448     // CHECKSTYLE: stop Indentation
449     public org.apache.giraph.io.gora.generated.GVertex.Builder setVertexValue(
450         float value) {
451       validate(fields()[1], value);
452       this.vertexValue = value;
453       fieldSetFlags()[1] = true;
454       return this;
455     }
456     // CHECKSTYLE: resume Indentation
457 
458     /**
459      * Checks whether the 'vertexValue' field has been set.
460      * @return boolean
461      */
462     public boolean hasVertexValue() {
463       return fieldSetFlags()[1];
464     }
465 
466     /**
467      * Clears the value of the 'vertexValue' field.
468      * @return GVertex.Builder
469      */
470     // CHECKSTYLE: stop Indentation
471     public org.apache.giraph.io.gora.generated.GVertex.Builder
472     clearVertexValue() {
473       fieldSetFlags()[1] = false;
474       return this;
475     }
476     // CHECKSTYLE: resume Indentation
477 
478     /**
479      * Gets the value of the 'edges' field.
480      * @return java.util.Map
481      */
482     public java.util.Map<java.lang.CharSequence, java.lang.CharSequence>
483     getEdges() {
484       return edges;
485     }
486 
487     /**
488      * Sets the value of the 'edges' field.
489      * @param value java.util.Map
490      * @return GVertex.Builder
491      */
492     // CHECKSTYLE: stop Indentation
493     public org.apache.giraph.io.gora.generated.GVertex.Builder setEdges(
494         java.util.Map<java.lang.CharSequence, java.lang.CharSequence> value) {
495       validate(fields()[2], value);
496       this.edges = value;
497       fieldSetFlags()[2] = true;
498       return this;
499     }
500     // CHECKSTYLE: resume Indentation
501 
502     /**
503      * Checks whether the 'edges' field has been set.
504      * @return boolean
505      */
506     public boolean hasEdges() {
507       return fieldSetFlags()[2];
508     }
509 
510     /**
511      * Clears the value of the 'edges' field.
512      * @return org.apache.giraph.io.gora.generated.GVertex.Builder
513      */
514     // CHECKSTYLE: stop Indentation
515     public org.apache.giraph.io.gora.generated.GVertex.Builder clearEdges() {
516       edges = null;
517       fieldSetFlags()[2] = false;
518       return this;
519     }
520     // CHECKSTYLE: resume Indentation
521 
522     @Override
523     /**
524      * Builds a GVertex.
525      * @return GVertex
526      */
527     // CHECKSTYLE: stop IllegalCatch
528     public GVertex build() {
529       try {
530         GVertex record = new GVertex();
531         record.vertexId = fieldSetFlags()[0] ? this.vertexId :
532           (java.lang.CharSequence) defaultValue(fields()[0]);
533         record.vertexValue = fieldSetFlags()[1] ? this.vertexValue :
534           (java.lang.Float) defaultValue(fields()[1]);
535         record.edges = fieldSetFlags()[2] ? this.edges :
536           (java.util.Map<java.lang.CharSequence, java.lang.CharSequence>)
537           new org.apache.gora.persistency.impl.DirtyMapWrapper(
538             (java.util.Map) defaultValue(fields()[2]));
539         return record;
540       } catch (Exception e) {
541         throw new org.apache.avro.AvroRuntimeException(e);
542       }
543     }
544     // CHECKSTYLE: resume IllegalCatch
545   }
546 
547   /**
548    * Gets tombstone
549    * @return GVertex.Tombstone
550    */
551   public GVertex.Tombstone getTombstone() {
552     return TOMBSTONE;
553   }
554 
555   /**
556    * Gets a new instance
557    * @return GVertex.
558    */
559   public GVertex newInstance() {
560     return newBuilder().build();
561   }
562 
563   /**
564    * Tombstone class.
565    */
566   public static final class Tombstone extends GVertex implements
567       org.apache.gora.persistency.Tombstone {
568 
569     /**
570      * Default constructor.
571      */
572     private Tombstone() {
573     }
574 
575     /**
576      * Gets the value of the 'vertexId' field.
577      * @return java.lang.CharSequence
578      */
579     public java.lang.CharSequence getVertexId() {
580       throw new java.lang.UnsupportedOperationException(
581           "Get is not supported on tombstones");
582     }
583 
584     /**
585      * Sets the value of the 'vertexId' field.
586      * @param value the value to set.
587      */
588     public void setVertexId(java.lang.CharSequence value) {
589       throw new java.lang.UnsupportedOperationException(
590           "Set is not supported on tombstones");
591     }
592 
593     /**
594      * Checks the dirty status of the 'vertexId' field. A field is dirty if it
595      * represents a change that has not yet been written to the database.
596      * @param value the value to set.
597      * @return boolean
598      */
599     public boolean isVertexIdDirty(java.lang.CharSequence value) {
600       throw new java.lang.UnsupportedOperationException(
601           "IsDirty is not supported on tombstones");
602     }
603 
604     /**
605      * Gets the value of the 'vertexValue' field.
606      * @return Float
607      */
608     public java.lang.Float getVertexValue() {
609       throw new java.lang.UnsupportedOperationException(
610           "Get is not supported on tombstones");
611     }
612 
613     /**
614      * Sets the value of the 'vertexValue' field.
615      * @param value the value to set.
616      */
617     public void setVertexValue(java.lang.Float value) {
618       throw new java.lang.UnsupportedOperationException(
619           "Set is not supported on tombstones");
620     }
621 
622     /**
623      * Checks the dirty status of the 'vertexValue' field. A field is dirty if
624      * it represents a change that has not yet been written to the database.
625      * @param value the value to set.
626      * @return boolean
627      */
628     public boolean isVertexValueDirty(java.lang.Float value) {
629       throw new java.lang.UnsupportedOperationException(
630           "IsDirty is not supported on tombstones");
631     }
632 
633     /**
634      * Gets the value of the 'edges' field.
635      * @return java.util.Map
636      */
637     public java.util.Map<java.lang.CharSequence, java.lang.CharSequence>
638     getEdges() {
639       throw new java.lang.UnsupportedOperationException(
640           "Get is not supported on tombstones");
641     }
642 
643     /**
644      * Sets the value of the 'edges' field.
645      * @param value the value to set.
646      */
647     public void setEdges(
648         java.util.Map<java.lang.CharSequence, java.lang.CharSequence> value) {
649       throw new java.lang.UnsupportedOperationException(
650           "Set is not supported on tombstones");
651     }
652 
653     /**
654      * Checks the dirty status of the 'edges' field. A field is dirty if it
655      * represents a change that has not yet been written to the database.
656      * @param value the value to set.
657      * @return boolean
658      */
659     public boolean isEdgesDirty(
660         java.util.Map<java.lang.CharSequence, java.lang.CharSequence> value) {
661       throw new java.lang.UnsupportedOperationException(
662           "IsDirty is not supported on tombstones");
663     }
664   }
665 }