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   * if no Result is found, row and columnValues will not be set.
33   */
34  public class TResult implements org.apache.thrift.TBase<TResult, TResult._Fields>, java.io.Serializable, Cloneable {
35    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TResult");
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 COLUMN_VALUES_FIELD_DESC = new org.apache.thrift.protocol.TField("columnValues", 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 TResultStandardSchemeFactory());
43      schemes.put(TupleScheme.class, new TResultTupleSchemeFactory());
44    }
45  
46    public ByteBuffer row; // optional
47    public List<TColumnValue> columnValues; // 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      COLUMN_VALUES((short)2, "columnValues");
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: // COLUMN_VALUES
70            return COLUMN_VALUES;
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   private _Fields optionals[] = {_Fields.ROW};
112   public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
113   static {
114     Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
115     tmpMap.put(_Fields.ROW, new org.apache.thrift.meta_data.FieldMetaData("row", org.apache.thrift.TFieldRequirementType.OPTIONAL, 
116         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , true)));
117     tmpMap.put(_Fields.COLUMN_VALUES, new org.apache.thrift.meta_data.FieldMetaData("columnValues", org.apache.thrift.TFieldRequirementType.REQUIRED, 
118         new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, 
119             new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TColumnValue.class))));
120     metaDataMap = Collections.unmodifiableMap(tmpMap);
121     org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TResult.class, metaDataMap);
122   }
123 
124   public TResult() {
125   }
126 
127   public TResult(
128     List<TColumnValue> columnValues)
129   {
130     this();
131     this.columnValues = columnValues;
132   }
133 
134   /**
135    * Performs a deep copy on <i>other</i>.
136    */
137   public TResult(TResult other) {
138     if (other.isSetRow()) {
139       this.row = org.apache.thrift.TBaseHelper.copyBinary(other.row);
140 ;
141     }
142     if (other.isSetColumnValues()) {
143       List<TColumnValue> __this__columnValues = new ArrayList<TColumnValue>();
144       for (TColumnValue other_element : other.columnValues) {
145         __this__columnValues.add(new TColumnValue(other_element));
146       }
147       this.columnValues = __this__columnValues;
148     }
149   }
150 
151   public TResult deepCopy() {
152     return new TResult(this);
153   }
154 
155   @Override
156   public void clear() {
157     this.row = null;
158     this.columnValues = null;
159   }
160 
161   public byte[] getRow() {
162     setRow(org.apache.thrift.TBaseHelper.rightSize(row));
163     return row == null ? null : row.array();
164   }
165 
166   public ByteBuffer bufferForRow() {
167     return row;
168   }
169 
170   public TResult setRow(byte[] row) {
171     setRow(row == null ? (ByteBuffer)null : ByteBuffer.wrap(row));
172     return this;
173   }
174 
175   public TResult setRow(ByteBuffer row) {
176     this.row = row;
177     return this;
178   }
179 
180   public void unsetRow() {
181     this.row = null;
182   }
183 
184   /** Returns true if field row is set (has been assigned a value) and false otherwise */
185   public boolean isSetRow() {
186     return this.row != null;
187   }
188 
189   public void setRowIsSet(boolean value) {
190     if (!value) {
191       this.row = null;
192     }
193   }
194 
195   public int getColumnValuesSize() {
196     return (this.columnValues == null) ? 0 : this.columnValues.size();
197   }
198 
199   public java.util.Iterator<TColumnValue> getColumnValuesIterator() {
200     return (this.columnValues == null) ? null : this.columnValues.iterator();
201   }
202 
203   public void addToColumnValues(TColumnValue elem) {
204     if (this.columnValues == null) {
205       this.columnValues = new ArrayList<TColumnValue>();
206     }
207     this.columnValues.add(elem);
208   }
209 
210   public List<TColumnValue> getColumnValues() {
211     return this.columnValues;
212   }
213 
214   public TResult setColumnValues(List<TColumnValue> columnValues) {
215     this.columnValues = columnValues;
216     return this;
217   }
218 
219   public void unsetColumnValues() {
220     this.columnValues = null;
221   }
222 
223   /** Returns true if field columnValues is set (has been assigned a value) and false otherwise */
224   public boolean isSetColumnValues() {
225     return this.columnValues != null;
226   }
227 
228   public void setColumnValuesIsSet(boolean value) {
229     if (!value) {
230       this.columnValues = null;
231     }
232   }
233 
234   public void setFieldValue(_Fields field, Object value) {
235     switch (field) {
236     case ROW:
237       if (value == null) {
238         unsetRow();
239       } else {
240         setRow((ByteBuffer)value);
241       }
242       break;
243 
244     case COLUMN_VALUES:
245       if (value == null) {
246         unsetColumnValues();
247       } else {
248         setColumnValues((List<TColumnValue>)value);
249       }
250       break;
251 
252     }
253   }
254 
255   public Object getFieldValue(_Fields field) {
256     switch (field) {
257     case ROW:
258       return getRow();
259 
260     case COLUMN_VALUES:
261       return getColumnValues();
262 
263     }
264     throw new IllegalStateException();
265   }
266 
267   /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
268   public boolean isSet(_Fields field) {
269     if (field == null) {
270       throw new IllegalArgumentException();
271     }
272 
273     switch (field) {
274     case ROW:
275       return isSetRow();
276     case COLUMN_VALUES:
277       return isSetColumnValues();
278     }
279     throw new IllegalStateException();
280   }
281 
282   @Override
283   public boolean equals(Object that) {
284     if (that == null)
285       return false;
286     if (that instanceof TResult)
287       return this.equals((TResult)that);
288     return false;
289   }
290 
291   public boolean equals(TResult that) {
292     if (that == null)
293       return false;
294 
295     boolean this_present_row = true && this.isSetRow();
296     boolean that_present_row = true && that.isSetRow();
297     if (this_present_row || that_present_row) {
298       if (!(this_present_row && that_present_row))
299         return false;
300       if (!this.row.equals(that.row))
301         return false;
302     }
303 
304     boolean this_present_columnValues = true && this.isSetColumnValues();
305     boolean that_present_columnValues = true && that.isSetColumnValues();
306     if (this_present_columnValues || that_present_columnValues) {
307       if (!(this_present_columnValues && that_present_columnValues))
308         return false;
309       if (!this.columnValues.equals(that.columnValues))
310         return false;
311     }
312 
313     return true;
314   }
315 
316   @Override
317   public int hashCode() {
318     HashCodeBuilder builder = new HashCodeBuilder();
319 
320     boolean present_row = true && (isSetRow());
321     builder.append(present_row);
322     if (present_row)
323       builder.append(row);
324 
325     boolean present_columnValues = true && (isSetColumnValues());
326     builder.append(present_columnValues);
327     if (present_columnValues)
328       builder.append(columnValues);
329 
330     return builder.toHashCode();
331   }
332 
333   public int compareTo(TResult other) {
334     if (!getClass().equals(other.getClass())) {
335       return getClass().getName().compareTo(other.getClass().getName());
336     }
337 
338     int lastComparison = 0;
339     TResult typedOther = (TResult)other;
340 
341     lastComparison = Boolean.valueOf(isSetRow()).compareTo(typedOther.isSetRow());
342     if (lastComparison != 0) {
343       return lastComparison;
344     }
345     if (isSetRow()) {
346       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.row, typedOther.row);
347       if (lastComparison != 0) {
348         return lastComparison;
349       }
350     }
351     lastComparison = Boolean.valueOf(isSetColumnValues()).compareTo(typedOther.isSetColumnValues());
352     if (lastComparison != 0) {
353       return lastComparison;
354     }
355     if (isSetColumnValues()) {
356       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.columnValues, typedOther.columnValues);
357       if (lastComparison != 0) {
358         return lastComparison;
359       }
360     }
361     return 0;
362   }
363 
364   public _Fields fieldForId(int fieldId) {
365     return _Fields.findByThriftId(fieldId);
366   }
367 
368   public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
369     schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
370   }
371 
372   public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
373     schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
374   }
375 
376   @Override
377   public String toString() {
378     StringBuilder sb = new StringBuilder("TResult(");
379     boolean first = true;
380 
381     if (isSetRow()) {
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     }
390     if (!first) sb.append(", ");
391     sb.append("columnValues:");
392     if (this.columnValues == null) {
393       sb.append("null");
394     } else {
395       sb.append(this.columnValues);
396     }
397     first = false;
398     sb.append(")");
399     return sb.toString();
400   }
401 
402   public void validate() throws org.apache.thrift.TException {
403     // check for required fields
404     if (columnValues == null) {
405       throw new org.apache.thrift.protocol.TProtocolException("Required field 'columnValues' was not present! Struct: " + toString());
406     }
407   }
408 
409   private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
410     try {
411       write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
412     } catch (org.apache.thrift.TException te) {
413       throw new java.io.IOException(te);
414     }
415   }
416 
417   private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
418     try {
419       read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
420     } catch (org.apache.thrift.TException te) {
421       throw new java.io.IOException(te);
422     }
423   }
424 
425   private static class TResultStandardSchemeFactory implements SchemeFactory {
426     public TResultStandardScheme getScheme() {
427       return new TResultStandardScheme();
428     }
429   }
430 
431   private static class TResultStandardScheme extends StandardScheme<TResult> {
432 
433     public void read(org.apache.thrift.protocol.TProtocol iprot, TResult struct) throws org.apache.thrift.TException {
434       org.apache.thrift.protocol.TField schemeField;
435       iprot.readStructBegin();
436       while (true)
437       {
438         schemeField = iprot.readFieldBegin();
439         if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
440           break;
441         }
442         switch (schemeField.id) {
443           case 1: // ROW
444             if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
445               struct.row = iprot.readBinary();
446               struct.setRowIsSet(true);
447             } else { 
448               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
449             }
450             break;
451           case 2: // COLUMN_VALUES
452             if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
453               {
454                 org.apache.thrift.protocol.TList _list0 = iprot.readListBegin();
455                 struct.columnValues = new ArrayList<TColumnValue>(_list0.size);
456                 for (int _i1 = 0; _i1 < _list0.size; ++_i1)
457                 {
458                   TColumnValue _elem2; // required
459                   _elem2 = new TColumnValue();
460                   _elem2.read(iprot);
461                   struct.columnValues.add(_elem2);
462                 }
463                 iprot.readListEnd();
464               }
465               struct.setColumnValuesIsSet(true);
466             } else { 
467               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
468             }
469             break;
470           default:
471             org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
472         }
473         iprot.readFieldEnd();
474       }
475       iprot.readStructEnd();
476 
477       // check for required fields of primitive type, which can't be checked in the validate method
478       struct.validate();
479     }
480 
481     public void write(org.apache.thrift.protocol.TProtocol oprot, TResult struct) throws org.apache.thrift.TException {
482       struct.validate();
483 
484       oprot.writeStructBegin(STRUCT_DESC);
485       if (struct.row != null) {
486         if (struct.isSetRow()) {
487           oprot.writeFieldBegin(ROW_FIELD_DESC);
488           oprot.writeBinary(struct.row);
489           oprot.writeFieldEnd();
490         }
491       }
492       if (struct.columnValues != null) {
493         oprot.writeFieldBegin(COLUMN_VALUES_FIELD_DESC);
494         {
495           oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.columnValues.size()));
496           for (TColumnValue _iter3 : struct.columnValues)
497           {
498             _iter3.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 TResultTupleSchemeFactory implements SchemeFactory {
511     public TResultTupleScheme getScheme() {
512       return new TResultTupleScheme();
513     }
514   }
515 
516   private static class TResultTupleScheme extends TupleScheme<TResult> {
517 
518     @Override
519     public void write(org.apache.thrift.protocol.TProtocol prot, TResult struct) throws org.apache.thrift.TException {
520       TTupleProtocol oprot = (TTupleProtocol) prot;
521       {
522         oprot.writeI32(struct.columnValues.size());
523         for (TColumnValue _iter4 : struct.columnValues)
524         {
525           _iter4.write(oprot);
526         }
527       }
528       BitSet optionals = new BitSet();
529       if (struct.isSetRow()) {
530         optionals.set(0);
531       }
532       oprot.writeBitSet(optionals, 1);
533       if (struct.isSetRow()) {
534         oprot.writeBinary(struct.row);
535       }
536     }
537 
538     @Override
539     public void read(org.apache.thrift.protocol.TProtocol prot, TResult struct) throws org.apache.thrift.TException {
540       TTupleProtocol iprot = (TTupleProtocol) prot;
541       {
542         org.apache.thrift.protocol.TList _list5 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
543         struct.columnValues = new ArrayList<TColumnValue>(_list5.size);
544         for (int _i6 = 0; _i6 < _list5.size; ++_i6)
545         {
546           TColumnValue _elem7; // required
547           _elem7 = new TColumnValue();
548           _elem7.read(iprot);
549           struct.columnValues.add(_elem7);
550         }
551       }
552       struct.setColumnValuesIsSet(true);
553       BitSet incoming = iprot.readBitSet(1);
554       if (incoming.get(0)) {
555         struct.row = iprot.readBinary();
556         struct.setRowIsSet(true);
557       }
558     }
559   }
560 
561 }
562