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