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   * Addresses a single cell or multiple cells
35   * in a HBase table by column family and optionally
36   * a column qualifier and timestamp
37   */
38  public class TColumn implements org.apache.thrift.TBase<TColumn, TColumn._Fields>, java.io.Serializable, Cloneable {
39    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TColumn");
40  
41    private static final org.apache.thrift.protocol.TField FAMILY_FIELD_DESC = new org.apache.thrift.protocol.TField("family", org.apache.thrift.protocol.TType.STRING, (short)1);
42    private static final org.apache.thrift.protocol.TField QUALIFIER_FIELD_DESC = new org.apache.thrift.protocol.TField("qualifier", org.apache.thrift.protocol.TType.STRING, (short)2);
43    private static final org.apache.thrift.protocol.TField TIMESTAMP_FIELD_DESC = new org.apache.thrift.protocol.TField("timestamp", org.apache.thrift.protocol.TType.I64, (short)3);
44  
45    private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
46    static {
47      schemes.put(StandardScheme.class, new TColumnStandardSchemeFactory());
48      schemes.put(TupleScheme.class, new TColumnTupleSchemeFactory());
49    }
50  
51    public ByteBuffer family; // required
52    public ByteBuffer qualifier; // optional
53    public long timestamp; // optional
54  
55    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
56    public enum _Fields implements org.apache.thrift.TFieldIdEnum {
57      FAMILY((short)1, "family"),
58      QUALIFIER((short)2, "qualifier"),
59      TIMESTAMP((short)3, "timestamp");
60  
61      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
62  
63      static {
64        for (_Fields field : EnumSet.allOf(_Fields.class)) {
65          byName.put(field.getFieldName(), field);
66        }
67      }
68  
69      /**
70       * Find the _Fields constant that matches fieldId, or null if its not found.
71       */
72      public static _Fields findByThriftId(int fieldId) {
73        switch(fieldId) {
74          case 1: // FAMILY
75            return FAMILY;
76          case 2: // QUALIFIER
77            return QUALIFIER;
78          case 3: // TIMESTAMP
79            return TIMESTAMP;
80          default:
81            return null;
82        }
83      }
84  
85      /**
86       * Find the _Fields constant that matches fieldId, throwing an exception
87       * if it is not found.
88       */
89      public static _Fields findByThriftIdOrThrow(int fieldId) {
90        _Fields fields = findByThriftId(fieldId);
91        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
92        return fields;
93      }
94  
95      /**
96       * Find the _Fields constant that matches name, or null if its not found.
97       */
98      public static _Fields findByName(String name) {
99        return byName.get(name);
100     }
101 
102     private final short _thriftId;
103     private final String _fieldName;
104 
105     _Fields(short thriftId, String fieldName) {
106       _thriftId = thriftId;
107       _fieldName = fieldName;
108     }
109 
110     public short getThriftFieldId() {
111       return _thriftId;
112     }
113 
114     public String getFieldName() {
115       return _fieldName;
116     }
117   }
118 
119   // isset id assignments
120   private static final int __TIMESTAMP_ISSET_ID = 0;
121   private byte __isset_bitfield = 0;
122   private _Fields optionals[] = {_Fields.QUALIFIER,_Fields.TIMESTAMP};
123   public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
124   static {
125     Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
126     tmpMap.put(_Fields.FAMILY, new org.apache.thrift.meta_data.FieldMetaData("family", org.apache.thrift.TFieldRequirementType.REQUIRED, 
127         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , true)));
128     tmpMap.put(_Fields.QUALIFIER, new org.apache.thrift.meta_data.FieldMetaData("qualifier", org.apache.thrift.TFieldRequirementType.OPTIONAL, 
129         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , true)));
130     tmpMap.put(_Fields.TIMESTAMP, new org.apache.thrift.meta_data.FieldMetaData("timestamp", org.apache.thrift.TFieldRequirementType.OPTIONAL, 
131         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64)));
132     metaDataMap = Collections.unmodifiableMap(tmpMap);
133     org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TColumn.class, metaDataMap);
134   }
135 
136   public TColumn() {
137   }
138 
139   public TColumn(
140     ByteBuffer family)
141   {
142     this();
143     this.family = family;
144   }
145 
146   /**
147    * Performs a deep copy on <i>other</i>.
148    */
149   public TColumn(TColumn other) {
150     __isset_bitfield = other.__isset_bitfield;
151     if (other.isSetFamily()) {
152       this.family = org.apache.thrift.TBaseHelper.copyBinary(other.family);
153 ;
154     }
155     if (other.isSetQualifier()) {
156       this.qualifier = org.apache.thrift.TBaseHelper.copyBinary(other.qualifier);
157 ;
158     }
159     this.timestamp = other.timestamp;
160   }
161 
162   public TColumn deepCopy() {
163     return new TColumn(this);
164   }
165 
166   @Override
167   public void clear() {
168     this.family = null;
169     this.qualifier = null;
170     setTimestampIsSet(false);
171     this.timestamp = 0;
172   }
173 
174   public byte[] getFamily() {
175     setFamily(org.apache.thrift.TBaseHelper.rightSize(family));
176     return family == null ? null : family.array();
177   }
178 
179   public ByteBuffer bufferForFamily() {
180     return family;
181   }
182 
183   public TColumn setFamily(byte[] family) {
184     setFamily(family == null ? (ByteBuffer)null : ByteBuffer.wrap(family));
185     return this;
186   }
187 
188   public TColumn setFamily(ByteBuffer family) {
189     this.family = family;
190     return this;
191   }
192 
193   public void unsetFamily() {
194     this.family = null;
195   }
196 
197   /** Returns true if field family is set (has been assigned a value) and false otherwise */
198   public boolean isSetFamily() {
199     return this.family != null;
200   }
201 
202   public void setFamilyIsSet(boolean value) {
203     if (!value) {
204       this.family = null;
205     }
206   }
207 
208   public byte[] getQualifier() {
209     setQualifier(org.apache.thrift.TBaseHelper.rightSize(qualifier));
210     return qualifier == null ? null : qualifier.array();
211   }
212 
213   public ByteBuffer bufferForQualifier() {
214     return qualifier;
215   }
216 
217   public TColumn setQualifier(byte[] qualifier) {
218     setQualifier(qualifier == null ? (ByteBuffer)null : ByteBuffer.wrap(qualifier));
219     return this;
220   }
221 
222   public TColumn setQualifier(ByteBuffer qualifier) {
223     this.qualifier = qualifier;
224     return this;
225   }
226 
227   public void unsetQualifier() {
228     this.qualifier = null;
229   }
230 
231   /** Returns true if field qualifier is set (has been assigned a value) and false otherwise */
232   public boolean isSetQualifier() {
233     return this.qualifier != null;
234   }
235 
236   public void setQualifierIsSet(boolean value) {
237     if (!value) {
238       this.qualifier = null;
239     }
240   }
241 
242   public long getTimestamp() {
243     return this.timestamp;
244   }
245 
246   public TColumn setTimestamp(long timestamp) {
247     this.timestamp = timestamp;
248     setTimestampIsSet(true);
249     return this;
250   }
251 
252   public void unsetTimestamp() {
253     __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __TIMESTAMP_ISSET_ID);
254   }
255 
256   /** Returns true if field timestamp is set (has been assigned a value) and false otherwise */
257   public boolean isSetTimestamp() {
258     return EncodingUtils.testBit(__isset_bitfield, __TIMESTAMP_ISSET_ID);
259   }
260 
261   public void setTimestampIsSet(boolean value) {
262     __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __TIMESTAMP_ISSET_ID, value);
263   }
264 
265   public void setFieldValue(_Fields field, Object value) {
266     switch (field) {
267     case FAMILY:
268       if (value == null) {
269         unsetFamily();
270       } else {
271         setFamily((ByteBuffer)value);
272       }
273       break;
274 
275     case QUALIFIER:
276       if (value == null) {
277         unsetQualifier();
278       } else {
279         setQualifier((ByteBuffer)value);
280       }
281       break;
282 
283     case TIMESTAMP:
284       if (value == null) {
285         unsetTimestamp();
286       } else {
287         setTimestamp((Long)value);
288       }
289       break;
290 
291     }
292   }
293 
294   public Object getFieldValue(_Fields field) {
295     switch (field) {
296     case FAMILY:
297       return getFamily();
298 
299     case QUALIFIER:
300       return getQualifier();
301 
302     case TIMESTAMP:
303       return Long.valueOf(getTimestamp());
304 
305     }
306     throw new IllegalStateException();
307   }
308 
309   /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
310   public boolean isSet(_Fields field) {
311     if (field == null) {
312       throw new IllegalArgumentException();
313     }
314 
315     switch (field) {
316     case FAMILY:
317       return isSetFamily();
318     case QUALIFIER:
319       return isSetQualifier();
320     case TIMESTAMP:
321       return isSetTimestamp();
322     }
323     throw new IllegalStateException();
324   }
325 
326   @Override
327   public boolean equals(Object that) {
328     if (that == null)
329       return false;
330     if (that instanceof TColumn)
331       return this.equals((TColumn)that);
332     return false;
333   }
334 
335   public boolean equals(TColumn that) {
336     if (that == null)
337       return false;
338 
339     boolean this_present_family = true && this.isSetFamily();
340     boolean that_present_family = true && that.isSetFamily();
341     if (this_present_family || that_present_family) {
342       if (!(this_present_family && that_present_family))
343         return false;
344       if (!this.family.equals(that.family))
345         return false;
346     }
347 
348     boolean this_present_qualifier = true && this.isSetQualifier();
349     boolean that_present_qualifier = true && that.isSetQualifier();
350     if (this_present_qualifier || that_present_qualifier) {
351       if (!(this_present_qualifier && that_present_qualifier))
352         return false;
353       if (!this.qualifier.equals(that.qualifier))
354         return false;
355     }
356 
357     boolean this_present_timestamp = true && this.isSetTimestamp();
358     boolean that_present_timestamp = true && that.isSetTimestamp();
359     if (this_present_timestamp || that_present_timestamp) {
360       if (!(this_present_timestamp && that_present_timestamp))
361         return false;
362       if (this.timestamp != that.timestamp)
363         return false;
364     }
365 
366     return true;
367   }
368 
369   @Override
370   public int hashCode() {
371     return 0;
372   }
373 
374   public int compareTo(TColumn other) {
375     if (!getClass().equals(other.getClass())) {
376       return getClass().getName().compareTo(other.getClass().getName());
377     }
378 
379     int lastComparison = 0;
380     TColumn typedOther = (TColumn)other;
381 
382     lastComparison = Boolean.valueOf(isSetFamily()).compareTo(typedOther.isSetFamily());
383     if (lastComparison != 0) {
384       return lastComparison;
385     }
386     if (isSetFamily()) {
387       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.family, typedOther.family);
388       if (lastComparison != 0) {
389         return lastComparison;
390       }
391     }
392     lastComparison = Boolean.valueOf(isSetQualifier()).compareTo(typedOther.isSetQualifier());
393     if (lastComparison != 0) {
394       return lastComparison;
395     }
396     if (isSetQualifier()) {
397       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.qualifier, typedOther.qualifier);
398       if (lastComparison != 0) {
399         return lastComparison;
400       }
401     }
402     lastComparison = Boolean.valueOf(isSetTimestamp()).compareTo(typedOther.isSetTimestamp());
403     if (lastComparison != 0) {
404       return lastComparison;
405     }
406     if (isSetTimestamp()) {
407       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.timestamp, typedOther.timestamp);
408       if (lastComparison != 0) {
409         return lastComparison;
410       }
411     }
412     return 0;
413   }
414 
415   public _Fields fieldForId(int fieldId) {
416     return _Fields.findByThriftId(fieldId);
417   }
418 
419   public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
420     schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
421   }
422 
423   public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
424     schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
425   }
426 
427   @Override
428   public String toString() {
429     StringBuilder sb = new StringBuilder("TColumn(");
430     boolean first = true;
431 
432     sb.append("family:");
433     if (this.family == null) {
434       sb.append("null");
435     } else {
436       org.apache.thrift.TBaseHelper.toString(this.family, sb);
437     }
438     first = false;
439     if (isSetQualifier()) {
440       if (!first) sb.append(", ");
441       sb.append("qualifier:");
442       if (this.qualifier == null) {
443         sb.append("null");
444       } else {
445         org.apache.thrift.TBaseHelper.toString(this.qualifier, sb);
446       }
447       first = false;
448     }
449     if (isSetTimestamp()) {
450       if (!first) sb.append(", ");
451       sb.append("timestamp:");
452       sb.append(this.timestamp);
453       first = false;
454     }
455     sb.append(")");
456     return sb.toString();
457   }
458 
459   public void validate() throws org.apache.thrift.TException {
460     // check for required fields
461     if (family == null) {
462       throw new org.apache.thrift.protocol.TProtocolException("Required field 'family' was not present! Struct: " + toString());
463     }
464     // check for sub-struct validity
465   }
466 
467   private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
468     try {
469       write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
470     } catch (org.apache.thrift.TException te) {
471       throw new java.io.IOException(te);
472     }
473   }
474 
475   private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
476     try {
477       // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor.
478       __isset_bitfield = 0;
479       read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
480     } catch (org.apache.thrift.TException te) {
481       throw new java.io.IOException(te);
482     }
483   }
484 
485   private static class TColumnStandardSchemeFactory implements SchemeFactory {
486     public TColumnStandardScheme getScheme() {
487       return new TColumnStandardScheme();
488     }
489   }
490 
491   private static class TColumnStandardScheme extends StandardScheme<TColumn> {
492 
493     public void read(org.apache.thrift.protocol.TProtocol iprot, TColumn struct) throws org.apache.thrift.TException {
494       org.apache.thrift.protocol.TField schemeField;
495       iprot.readStructBegin();
496       while (true)
497       {
498         schemeField = iprot.readFieldBegin();
499         if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
500           break;
501         }
502         switch (schemeField.id) {
503           case 1: // FAMILY
504             if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
505               struct.family = iprot.readBinary();
506               struct.setFamilyIsSet(true);
507             } else { 
508               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
509             }
510             break;
511           case 2: // QUALIFIER
512             if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
513               struct.qualifier = iprot.readBinary();
514               struct.setQualifierIsSet(true);
515             } else { 
516               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
517             }
518             break;
519           case 3: // TIMESTAMP
520             if (schemeField.type == org.apache.thrift.protocol.TType.I64) {
521               struct.timestamp = iprot.readI64();
522               struct.setTimestampIsSet(true);
523             } else { 
524               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
525             }
526             break;
527           default:
528             org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
529         }
530         iprot.readFieldEnd();
531       }
532       iprot.readStructEnd();
533 
534       // check for required fields of primitive type, which can't be checked in the validate method
535       struct.validate();
536     }
537 
538     public void write(org.apache.thrift.protocol.TProtocol oprot, TColumn struct) throws org.apache.thrift.TException {
539       struct.validate();
540 
541       oprot.writeStructBegin(STRUCT_DESC);
542       if (struct.family != null) {
543         oprot.writeFieldBegin(FAMILY_FIELD_DESC);
544         oprot.writeBinary(struct.family);
545         oprot.writeFieldEnd();
546       }
547       if (struct.qualifier != null) {
548         if (struct.isSetQualifier()) {
549           oprot.writeFieldBegin(QUALIFIER_FIELD_DESC);
550           oprot.writeBinary(struct.qualifier);
551           oprot.writeFieldEnd();
552         }
553       }
554       if (struct.isSetTimestamp()) {
555         oprot.writeFieldBegin(TIMESTAMP_FIELD_DESC);
556         oprot.writeI64(struct.timestamp);
557         oprot.writeFieldEnd();
558       }
559       oprot.writeFieldStop();
560       oprot.writeStructEnd();
561     }
562 
563   }
564 
565   private static class TColumnTupleSchemeFactory implements SchemeFactory {
566     public TColumnTupleScheme getScheme() {
567       return new TColumnTupleScheme();
568     }
569   }
570 
571   private static class TColumnTupleScheme extends TupleScheme<TColumn> {
572 
573     @Override
574     public void write(org.apache.thrift.protocol.TProtocol prot, TColumn struct) throws org.apache.thrift.TException {
575       TTupleProtocol oprot = (TTupleProtocol) prot;
576       oprot.writeBinary(struct.family);
577       BitSet optionals = new BitSet();
578       if (struct.isSetQualifier()) {
579         optionals.set(0);
580       }
581       if (struct.isSetTimestamp()) {
582         optionals.set(1);
583       }
584       oprot.writeBitSet(optionals, 2);
585       if (struct.isSetQualifier()) {
586         oprot.writeBinary(struct.qualifier);
587       }
588       if (struct.isSetTimestamp()) {
589         oprot.writeI64(struct.timestamp);
590       }
591     }
592 
593     @Override
594     public void read(org.apache.thrift.protocol.TProtocol prot, TColumn struct) throws org.apache.thrift.TException {
595       TTupleProtocol iprot = (TTupleProtocol) prot;
596       struct.family = iprot.readBinary();
597       struct.setFamilyIsSet(true);
598       BitSet incoming = iprot.readBitSet(2);
599       if (incoming.get(0)) {
600         struct.qualifier = iprot.readBinary();
601         struct.setQualifierIsSet(true);
602       }
603       if (incoming.get(1)) {
604         struct.timestamp = iprot.readI64();
605         struct.setTimestampIsSet(true);
606       }
607     }
608   }
609 
610 }
611