View Javadoc

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