View Javadoc

1   /**
2    * Autogenerated by Thrift Compiler (0.8.0)
3    *
4    * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5    *  @generated
6    */
7   package org.apache.hadoop.hbase.thrift2.generated;
8   
9   import org.apache.commons.lang.builder.HashCodeBuilder;
10  import org.apache.thrift.scheme.IScheme;
11  import org.apache.thrift.scheme.SchemeFactory;
12  import org.apache.thrift.scheme.StandardScheme;
13  
14  import org.apache.thrift.scheme.TupleScheme;
15  import org.apache.thrift.protocol.TTupleProtocol;
16  import java.util.List;
17  import java.util.ArrayList;
18  import java.util.Map;
19  import java.util.HashMap;
20  import java.util.EnumMap;
21  import java.util.Set;
22  import java.util.HashSet;
23  import java.util.EnumSet;
24  import java.util.Collections;
25  import java.util.BitSet;
26  import java.nio.ByteBuffer;
27  import java.util.Arrays;
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  
31  /**
32   * A TRowMutations object is used to apply a number of Mutations to a single row.
33   */
34  public class TRowMutations implements org.apache.thrift.TBase<TRowMutations, TRowMutations._Fields>, java.io.Serializable, Cloneable {
35    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TRowMutations");
36  
37    private static final org.apache.thrift.protocol.TField ROW_FIELD_DESC = new org.apache.thrift.protocol.TField("row", org.apache.thrift.protocol.TType.STRING, (short)1);
38    private static final org.apache.thrift.protocol.TField MUTATIONS_FIELD_DESC = new org.apache.thrift.protocol.TField("mutations", org.apache.thrift.protocol.TType.LIST, (short)2);
39  
40    private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
41    static {
42      schemes.put(StandardScheme.class, new TRowMutationsStandardSchemeFactory());
43      schemes.put(TupleScheme.class, new TRowMutationsTupleSchemeFactory());
44    }
45  
46    public ByteBuffer row; // required
47    public List<TMutation> mutations; // required
48  
49    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
50    public enum _Fields implements org.apache.thrift.TFieldIdEnum {
51      ROW((short)1, "row"),
52      MUTATIONS((short)2, "mutations");
53  
54      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
55  
56      static {
57        for (_Fields field : EnumSet.allOf(_Fields.class)) {
58          byName.put(field.getFieldName(), field);
59        }
60      }
61  
62      /**
63       * Find the _Fields constant that matches fieldId, or null if its not found.
64       */
65      public static _Fields findByThriftId(int fieldId) {
66        switch(fieldId) {
67          case 1: // ROW
68            return ROW;
69          case 2: // MUTATIONS
70            return MUTATIONS;
71          default:
72            return null;
73        }
74      }
75  
76      /**
77       * Find the _Fields constant that matches fieldId, throwing an exception
78       * if it is not found.
79       */
80      public static _Fields findByThriftIdOrThrow(int fieldId) {
81        _Fields fields = findByThriftId(fieldId);
82        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
83        return fields;
84      }
85  
86      /**
87       * Find the _Fields constant that matches name, or null if its not found.
88       */
89      public static _Fields findByName(String name) {
90        return byName.get(name);
91      }
92  
93      private final short _thriftId;
94      private final String _fieldName;
95  
96      _Fields(short thriftId, String fieldName) {
97        _thriftId = thriftId;
98        _fieldName = fieldName;
99      }
100 
101     public short getThriftFieldId() {
102       return _thriftId;
103     }
104 
105     public String getFieldName() {
106       return _fieldName;
107     }
108   }
109 
110   // isset id assignments
111   public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
112   static {
113     Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
114     tmpMap.put(_Fields.ROW, new org.apache.thrift.meta_data.FieldMetaData("row", org.apache.thrift.TFieldRequirementType.REQUIRED, 
115         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , true)));
116     tmpMap.put(_Fields.MUTATIONS, new org.apache.thrift.meta_data.FieldMetaData("mutations", org.apache.thrift.TFieldRequirementType.REQUIRED, 
117         new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, 
118             new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TMutation.class))));
119     metaDataMap = Collections.unmodifiableMap(tmpMap);
120     org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TRowMutations.class, metaDataMap);
121   }
122 
123   public TRowMutations() {
124   }
125 
126   public TRowMutations(
127     ByteBuffer row,
128     List<TMutation> mutations)
129   {
130     this();
131     this.row = row;
132     this.mutations = mutations;
133   }
134 
135   /**
136    * Performs a deep copy on <i>other</i>.
137    */
138   public TRowMutations(TRowMutations other) {
139     if (other.isSetRow()) {
140       this.row = org.apache.thrift.TBaseHelper.copyBinary(other.row);
141 ;
142     }
143     if (other.isSetMutations()) {
144       List<TMutation> __this__mutations = new ArrayList<TMutation>();
145       for (TMutation other_element : other.mutations) {
146         __this__mutations.add(new TMutation(other_element));
147       }
148       this.mutations = __this__mutations;
149     }
150   }
151 
152   public TRowMutations deepCopy() {
153     return new TRowMutations(this);
154   }
155 
156   @Override
157   public void clear() {
158     this.row = null;
159     this.mutations = null;
160   }
161 
162   public byte[] getRow() {
163     setRow(org.apache.thrift.TBaseHelper.rightSize(row));
164     return row == null ? null : row.array();
165   }
166 
167   public ByteBuffer bufferForRow() {
168     return row;
169   }
170 
171   public TRowMutations setRow(byte[] row) {
172     setRow(row == null ? (ByteBuffer)null : ByteBuffer.wrap(row));
173     return this;
174   }
175 
176   public TRowMutations setRow(ByteBuffer row) {
177     this.row = row;
178     return this;
179   }
180 
181   public void unsetRow() {
182     this.row = null;
183   }
184 
185   /** Returns true if field row is set (has been assigned a value) and false otherwise */
186   public boolean isSetRow() {
187     return this.row != null;
188   }
189 
190   public void setRowIsSet(boolean value) {
191     if (!value) {
192       this.row = null;
193     }
194   }
195 
196   public int getMutationsSize() {
197     return (this.mutations == null) ? 0 : this.mutations.size();
198   }
199 
200   public java.util.Iterator<TMutation> getMutationsIterator() {
201     return (this.mutations == null) ? null : this.mutations.iterator();
202   }
203 
204   public void addToMutations(TMutation elem) {
205     if (this.mutations == null) {
206       this.mutations = new ArrayList<TMutation>();
207     }
208     this.mutations.add(elem);
209   }
210 
211   public List<TMutation> getMutations() {
212     return this.mutations;
213   }
214 
215   public TRowMutations setMutations(List<TMutation> mutations) {
216     this.mutations = mutations;
217     return this;
218   }
219 
220   public void unsetMutations() {
221     this.mutations = null;
222   }
223 
224   /** Returns true if field mutations is set (has been assigned a value) and false otherwise */
225   public boolean isSetMutations() {
226     return this.mutations != null;
227   }
228 
229   public void setMutationsIsSet(boolean value) {
230     if (!value) {
231       this.mutations = null;
232     }
233   }
234 
235   public void setFieldValue(_Fields field, Object value) {
236     switch (field) {
237     case ROW:
238       if (value == null) {
239         unsetRow();
240       } else {
241         setRow((ByteBuffer)value);
242       }
243       break;
244 
245     case MUTATIONS:
246       if (value == null) {
247         unsetMutations();
248       } else {
249         setMutations((List<TMutation>)value);
250       }
251       break;
252 
253     }
254   }
255 
256   public Object getFieldValue(_Fields field) {
257     switch (field) {
258     case ROW:
259       return getRow();
260 
261     case MUTATIONS:
262       return getMutations();
263 
264     }
265     throw new IllegalStateException();
266   }
267 
268   /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
269   public boolean isSet(_Fields field) {
270     if (field == null) {
271       throw new IllegalArgumentException();
272     }
273 
274     switch (field) {
275     case ROW:
276       return isSetRow();
277     case MUTATIONS:
278       return isSetMutations();
279     }
280     throw new IllegalStateException();
281   }
282 
283   @Override
284   public boolean equals(Object that) {
285     if (that == null)
286       return false;
287     if (that instanceof TRowMutations)
288       return this.equals((TRowMutations)that);
289     return false;
290   }
291 
292   public boolean equals(TRowMutations that) {
293     if (that == null)
294       return false;
295 
296     boolean this_present_row = true && this.isSetRow();
297     boolean that_present_row = true && that.isSetRow();
298     if (this_present_row || that_present_row) {
299       if (!(this_present_row && that_present_row))
300         return false;
301       if (!this.row.equals(that.row))
302         return false;
303     }
304 
305     boolean this_present_mutations = true && this.isSetMutations();
306     boolean that_present_mutations = true && that.isSetMutations();
307     if (this_present_mutations || that_present_mutations) {
308       if (!(this_present_mutations && that_present_mutations))
309         return false;
310       if (!this.mutations.equals(that.mutations))
311         return false;
312     }
313 
314     return true;
315   }
316 
317   @Override
318   public int hashCode() {
319     HashCodeBuilder builder = new HashCodeBuilder();
320 
321     boolean present_row = true && (isSetRow());
322     builder.append(present_row);
323     if (present_row)
324       builder.append(row);
325 
326     boolean present_mutations = true && (isSetMutations());
327     builder.append(present_mutations);
328     if (present_mutations)
329       builder.append(mutations);
330 
331     return builder.toHashCode();
332   }
333 
334   public int compareTo(TRowMutations other) {
335     if (!getClass().equals(other.getClass())) {
336       return getClass().getName().compareTo(other.getClass().getName());
337     }
338 
339     int lastComparison = 0;
340     TRowMutations typedOther = (TRowMutations)other;
341 
342     lastComparison = Boolean.valueOf(isSetRow()).compareTo(typedOther.isSetRow());
343     if (lastComparison != 0) {
344       return lastComparison;
345     }
346     if (isSetRow()) {
347       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.row, typedOther.row);
348       if (lastComparison != 0) {
349         return lastComparison;
350       }
351     }
352     lastComparison = Boolean.valueOf(isSetMutations()).compareTo(typedOther.isSetMutations());
353     if (lastComparison != 0) {
354       return lastComparison;
355     }
356     if (isSetMutations()) {
357       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.mutations, typedOther.mutations);
358       if (lastComparison != 0) {
359         return lastComparison;
360       }
361     }
362     return 0;
363   }
364 
365   public _Fields fieldForId(int fieldId) {
366     return _Fields.findByThriftId(fieldId);
367   }
368 
369   public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
370     schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
371   }
372 
373   public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
374     schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
375   }
376 
377   @Override
378   public String toString() {
379     StringBuilder sb = new StringBuilder("TRowMutations(");
380     boolean first = true;
381 
382     sb.append("row:");
383     if (this.row == null) {
384       sb.append("null");
385     } else {
386       org.apache.thrift.TBaseHelper.toString(this.row, sb);
387     }
388     first = false;
389     if (!first) sb.append(", ");
390     sb.append("mutations:");
391     if (this.mutations == null) {
392       sb.append("null");
393     } else {
394       sb.append(this.mutations);
395     }
396     first = false;
397     sb.append(")");
398     return sb.toString();
399   }
400 
401   public void validate() throws org.apache.thrift.TException {
402     // check for required fields
403     if (row == null) {
404       throw new org.apache.thrift.protocol.TProtocolException("Required field 'row' was not present! Struct: " + toString());
405     }
406     if (mutations == null) {
407       throw new org.apache.thrift.protocol.TProtocolException("Required field 'mutations' was not present! Struct: " + toString());
408     }
409   }
410 
411   private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
412     try {
413       write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
414     } catch (org.apache.thrift.TException te) {
415       throw new java.io.IOException(te);
416     }
417   }
418 
419   private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
420     try {
421       read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
422     } catch (org.apache.thrift.TException te) {
423       throw new java.io.IOException(te);
424     }
425   }
426 
427   private static class TRowMutationsStandardSchemeFactory implements SchemeFactory {
428     public TRowMutationsStandardScheme getScheme() {
429       return new TRowMutationsStandardScheme();
430     }
431   }
432 
433   private static class TRowMutationsStandardScheme extends StandardScheme<TRowMutations> {
434 
435     public void read(org.apache.thrift.protocol.TProtocol iprot, TRowMutations struct) throws org.apache.thrift.TException {
436       org.apache.thrift.protocol.TField schemeField;
437       iprot.readStructBegin();
438       while (true)
439       {
440         schemeField = iprot.readFieldBegin();
441         if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
442           break;
443         }
444         switch (schemeField.id) {
445           case 1: // ROW
446             if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
447               struct.row = iprot.readBinary();
448               struct.setRowIsSet(true);
449             } else { 
450               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
451             }
452             break;
453           case 2: // MUTATIONS
454             if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
455               {
456                 org.apache.thrift.protocol.TList _list88 = iprot.readListBegin();
457                 struct.mutations = new ArrayList<TMutation>(_list88.size);
458                 for (int _i89 = 0; _i89 < _list88.size; ++_i89)
459                 {
460                   TMutation _elem90; // required
461                   _elem90 = new TMutation();
462                   _elem90.read(iprot);
463                   struct.mutations.add(_elem90);
464                 }
465                 iprot.readListEnd();
466               }
467               struct.setMutationsIsSet(true);
468             } else { 
469               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
470             }
471             break;
472           default:
473             org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
474         }
475         iprot.readFieldEnd();
476       }
477       iprot.readStructEnd();
478 
479       // check for required fields of primitive type, which can't be checked in the validate method
480       struct.validate();
481     }
482 
483     public void write(org.apache.thrift.protocol.TProtocol oprot, TRowMutations struct) throws org.apache.thrift.TException {
484       struct.validate();
485 
486       oprot.writeStructBegin(STRUCT_DESC);
487       if (struct.row != null) {
488         oprot.writeFieldBegin(ROW_FIELD_DESC);
489         oprot.writeBinary(struct.row);
490         oprot.writeFieldEnd();
491       }
492       if (struct.mutations != null) {
493         oprot.writeFieldBegin(MUTATIONS_FIELD_DESC);
494         {
495           oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.mutations.size()));
496           for (TMutation _iter91 : struct.mutations)
497           {
498             _iter91.write(oprot);
499           }
500           oprot.writeListEnd();
501         }
502         oprot.writeFieldEnd();
503       }
504       oprot.writeFieldStop();
505       oprot.writeStructEnd();
506     }
507 
508   }
509 
510   private static class TRowMutationsTupleSchemeFactory implements SchemeFactory {
511     public TRowMutationsTupleScheme getScheme() {
512       return new TRowMutationsTupleScheme();
513     }
514   }
515 
516   private static class TRowMutationsTupleScheme extends TupleScheme<TRowMutations> {
517 
518     @Override
519     public void write(org.apache.thrift.protocol.TProtocol prot, TRowMutations struct) throws org.apache.thrift.TException {
520       TTupleProtocol oprot = (TTupleProtocol) prot;
521       oprot.writeBinary(struct.row);
522       {
523         oprot.writeI32(struct.mutations.size());
524         for (TMutation _iter92 : struct.mutations)
525         {
526           _iter92.write(oprot);
527         }
528       }
529     }
530 
531     @Override
532     public void read(org.apache.thrift.protocol.TProtocol prot, TRowMutations struct) throws org.apache.thrift.TException {
533       TTupleProtocol iprot = (TTupleProtocol) prot;
534       struct.row = iprot.readBinary();
535       struct.setRowIsSet(true);
536       {
537         org.apache.thrift.protocol.TList _list93 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
538         struct.mutations = new ArrayList<TMutation>(_list93.size);
539         for (int _i94 = 0; _i94 < _list93.size; ++_i94)
540         {
541           TMutation _elem95; // required
542           _elem95 = new TMutation();
543           _elem95.read(iprot);
544           struct.mutations.add(_elem95);
545         }
546       }
547       struct.setMutationsIsSet(true);
548     }
549   }
550 
551 }
552