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