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