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.thrift.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   * TCell - Used to transport a cell value (byte[]) and the timestamp it was
32   * stored with together as a result for get and getRow methods. This promotes
33   * the timestamp of a cell to a first-class value, making it easy to take
34   * note of temporal data. Cell is used all the way from HStore up to HTable.
35   */
36  public class TCell implements org.apache.thrift.TBase<TCell, TCell._Fields>, java.io.Serializable, Cloneable {
37    private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TCell");
38  
39    private static final org.apache.thrift.protocol.TField VALUE_FIELD_DESC = new org.apache.thrift.protocol.TField("value", org.apache.thrift.protocol.TType.STRING, (short)1);
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)2);
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 TCellStandardSchemeFactory());
45      schemes.put(TupleScheme.class, new TCellTupleSchemeFactory());
46    }
47  
48    public ByteBuffer value; // required
49    public long timestamp; // required
50  
51    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
52    public enum _Fields implements org.apache.thrift.TFieldIdEnum {
53      VALUE((short)1, "value"),
54      TIMESTAMP((short)2, "timestamp");
55  
56      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
57  
58      static {
59        for (_Fields field : EnumSet.allOf(_Fields.class)) {
60          byName.put(field.getFieldName(), field);
61        }
62      }
63  
64      /**
65       * Find the _Fields constant that matches fieldId, or null if its not found.
66       */
67      public static _Fields findByThriftId(int fieldId) {
68        switch(fieldId) {
69          case 1: // VALUE
70            return VALUE;
71          case 2: // TIMESTAMP
72            return TIMESTAMP;
73          default:
74            return null;
75        }
76      }
77  
78      /**
79       * Find the _Fields constant that matches fieldId, throwing an exception
80       * if it is not found.
81       */
82      public static _Fields findByThriftIdOrThrow(int fieldId) {
83        _Fields fields = findByThriftId(fieldId);
84        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
85        return fields;
86      }
87  
88      /**
89       * Find the _Fields constant that matches name, or null if its not found.
90       */
91      public static _Fields findByName(String name) {
92        return byName.get(name);
93      }
94  
95      private final short _thriftId;
96      private final String _fieldName;
97  
98      _Fields(short thriftId, String fieldName) {
99        _thriftId = thriftId;
100       _fieldName = fieldName;
101     }
102 
103     public short getThriftFieldId() {
104       return _thriftId;
105     }
106 
107     public String getFieldName() {
108       return _fieldName;
109     }
110   }
111 
112   // isset id assignments
113   private static final int __TIMESTAMP_ISSET_ID = 0;
114   private BitSet __isset_bit_vector = new BitSet(1);
115   public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
116   static {
117     Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
118     tmpMap.put(_Fields.VALUE, new org.apache.thrift.meta_data.FieldMetaData("value", org.apache.thrift.TFieldRequirementType.DEFAULT, 
119         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , "Bytes")));
120     tmpMap.put(_Fields.TIMESTAMP, new org.apache.thrift.meta_data.FieldMetaData("timestamp", org.apache.thrift.TFieldRequirementType.DEFAULT, 
121         new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64)));
122     metaDataMap = Collections.unmodifiableMap(tmpMap);
123     org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TCell.class, metaDataMap);
124   }
125 
126   public TCell() {
127   }
128 
129   public TCell(
130     ByteBuffer value,
131     long timestamp)
132   {
133     this();
134     this.value = value;
135     this.timestamp = timestamp;
136     setTimestampIsSet(true);
137   }
138 
139   /**
140    * Performs a deep copy on <i>other</i>.
141    */
142   public TCell(TCell other) {
143     __isset_bit_vector.clear();
144     __isset_bit_vector.or(other.__isset_bit_vector);
145     if (other.isSetValue()) {
146       this.value = other.value;
147     }
148     this.timestamp = other.timestamp;
149   }
150 
151   public TCell deepCopy() {
152     return new TCell(this);
153   }
154 
155   @Override
156   public void clear() {
157     this.value = null;
158     setTimestampIsSet(false);
159     this.timestamp = 0;
160   }
161 
162   public byte[] getValue() {
163     setValue(org.apache.thrift.TBaseHelper.rightSize(value));
164     return value == null ? null : value.array();
165   }
166 
167   public ByteBuffer bufferForValue() {
168     return value;
169   }
170 
171   public TCell setValue(byte[] value) {
172     setValue(value == null ? (ByteBuffer)null : ByteBuffer.wrap(value));
173     return this;
174   }
175 
176   public TCell setValue(ByteBuffer value) {
177     this.value = value;
178     return this;
179   }
180 
181   public void unsetValue() {
182     this.value = null;
183   }
184 
185   /** Returns true if field value is set (has been assigned a value) and false otherwise */
186   public boolean isSetValue() {
187     return this.value != null;
188   }
189 
190   public void setValueIsSet(boolean value) {
191     if (!value) {
192       this.value = null;
193     }
194   }
195 
196   public long getTimestamp() {
197     return this.timestamp;
198   }
199 
200   public TCell setTimestamp(long timestamp) {
201     this.timestamp = timestamp;
202     setTimestampIsSet(true);
203     return this;
204   }
205 
206   public void unsetTimestamp() {
207     __isset_bit_vector.clear(__TIMESTAMP_ISSET_ID);
208   }
209 
210   /** Returns true if field timestamp is set (has been assigned a value) and false otherwise */
211   public boolean isSetTimestamp() {
212     return __isset_bit_vector.get(__TIMESTAMP_ISSET_ID);
213   }
214 
215   public void setTimestampIsSet(boolean value) {
216     __isset_bit_vector.set(__TIMESTAMP_ISSET_ID, value);
217   }
218 
219   public void setFieldValue(_Fields field, Object value) {
220     switch (field) {
221     case VALUE:
222       if (value == null) {
223         unsetValue();
224       } else {
225         setValue((ByteBuffer)value);
226       }
227       break;
228 
229     case TIMESTAMP:
230       if (value == null) {
231         unsetTimestamp();
232       } else {
233         setTimestamp((Long)value);
234       }
235       break;
236 
237     }
238   }
239 
240   public Object getFieldValue(_Fields field) {
241     switch (field) {
242     case VALUE:
243       return getValue();
244 
245     case TIMESTAMP:
246       return Long.valueOf(getTimestamp());
247 
248     }
249     throw new IllegalStateException();
250   }
251 
252   /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
253   public boolean isSet(_Fields field) {
254     if (field == null) {
255       throw new IllegalArgumentException();
256     }
257 
258     switch (field) {
259     case VALUE:
260       return isSetValue();
261     case TIMESTAMP:
262       return isSetTimestamp();
263     }
264     throw new IllegalStateException();
265   }
266 
267   @Override
268   public boolean equals(Object that) {
269     if (that == null)
270       return false;
271     if (that instanceof TCell)
272       return this.equals((TCell)that);
273     return false;
274   }
275 
276   public boolean equals(TCell that) {
277     if (that == null)
278       return false;
279 
280     boolean this_present_value = true && this.isSetValue();
281     boolean that_present_value = true && that.isSetValue();
282     if (this_present_value || that_present_value) {
283       if (!(this_present_value && that_present_value))
284         return false;
285       if (!this.value.equals(that.value))
286         return false;
287     }
288 
289     boolean this_present_timestamp = true;
290     boolean that_present_timestamp = true;
291     if (this_present_timestamp || that_present_timestamp) {
292       if (!(this_present_timestamp && that_present_timestamp))
293         return false;
294       if (this.timestamp != that.timestamp)
295         return false;
296     }
297 
298     return true;
299   }
300 
301   @Override
302   public int hashCode() {
303     return 0;
304   }
305 
306   public int compareTo(TCell other) {
307     if (!getClass().equals(other.getClass())) {
308       return getClass().getName().compareTo(other.getClass().getName());
309     }
310 
311     int lastComparison = 0;
312     TCell typedOther = (TCell)other;
313 
314     lastComparison = Boolean.valueOf(isSetValue()).compareTo(typedOther.isSetValue());
315     if (lastComparison != 0) {
316       return lastComparison;
317     }
318     if (isSetValue()) {
319       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.value, typedOther.value);
320       if (lastComparison != 0) {
321         return lastComparison;
322       }
323     }
324     lastComparison = Boolean.valueOf(isSetTimestamp()).compareTo(typedOther.isSetTimestamp());
325     if (lastComparison != 0) {
326       return lastComparison;
327     }
328     if (isSetTimestamp()) {
329       lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.timestamp, typedOther.timestamp);
330       if (lastComparison != 0) {
331         return lastComparison;
332       }
333     }
334     return 0;
335   }
336 
337   public _Fields fieldForId(int fieldId) {
338     return _Fields.findByThriftId(fieldId);
339   }
340 
341   public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
342     schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
343   }
344 
345   public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
346     schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
347   }
348 
349   @Override
350   public String toString() {
351     StringBuilder sb = new StringBuilder("TCell(");
352     boolean first = true;
353 
354     sb.append("value:");
355     if (this.value == null) {
356       sb.append("null");
357     } else {
358       sb.append(this.value);
359     }
360     first = false;
361     if (!first) sb.append(", ");
362     sb.append("timestamp:");
363     sb.append(this.timestamp);
364     first = false;
365     sb.append(")");
366     return sb.toString();
367   }
368 
369   public void validate() throws org.apache.thrift.TException {
370     // check for required fields
371   }
372 
373   private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
374     try {
375       write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
376     } catch (org.apache.thrift.TException te) {
377       throw new java.io.IOException(te);
378     }
379   }
380 
381   private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
382     try {
383       // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor.
384       __isset_bit_vector = new BitSet(1);
385       read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
386     } catch (org.apache.thrift.TException te) {
387       throw new java.io.IOException(te);
388     }
389   }
390 
391   private static class TCellStandardSchemeFactory implements SchemeFactory {
392     public TCellStandardScheme getScheme() {
393       return new TCellStandardScheme();
394     }
395   }
396 
397   private static class TCellStandardScheme extends StandardScheme<TCell> {
398 
399     public void read(org.apache.thrift.protocol.TProtocol iprot, TCell struct) throws org.apache.thrift.TException {
400       org.apache.thrift.protocol.TField schemeField;
401       iprot.readStructBegin();
402       while (true)
403       {
404         schemeField = iprot.readFieldBegin();
405         if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
406           break;
407         }
408         switch (schemeField.id) {
409           case 1: // VALUE
410             if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
411               struct.value = iprot.readBinary();
412               struct.setValueIsSet(true);
413             } else { 
414               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
415             }
416             break;
417           case 2: // TIMESTAMP
418             if (schemeField.type == org.apache.thrift.protocol.TType.I64) {
419               struct.timestamp = iprot.readI64();
420               struct.setTimestampIsSet(true);
421             } else { 
422               org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
423             }
424             break;
425           default:
426             org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
427         }
428         iprot.readFieldEnd();
429       }
430       iprot.readStructEnd();
431 
432       // check for required fields of primitive type, which can't be checked in the validate method
433       struct.validate();
434     }
435 
436     public void write(org.apache.thrift.protocol.TProtocol oprot, TCell struct) throws org.apache.thrift.TException {
437       struct.validate();
438 
439       oprot.writeStructBegin(STRUCT_DESC);
440       if (struct.value != null) {
441         oprot.writeFieldBegin(VALUE_FIELD_DESC);
442         oprot.writeBinary(struct.value);
443         oprot.writeFieldEnd();
444       }
445       oprot.writeFieldBegin(TIMESTAMP_FIELD_DESC);
446       oprot.writeI64(struct.timestamp);
447       oprot.writeFieldEnd();
448       oprot.writeFieldStop();
449       oprot.writeStructEnd();
450     }
451 
452   }
453 
454   private static class TCellTupleSchemeFactory implements SchemeFactory {
455     public TCellTupleScheme getScheme() {
456       return new TCellTupleScheme();
457     }
458   }
459 
460   private static class TCellTupleScheme extends TupleScheme<TCell> {
461 
462     @Override
463     public void write(org.apache.thrift.protocol.TProtocol prot, TCell struct) throws org.apache.thrift.TException {
464       TTupleProtocol oprot = (TTupleProtocol) prot;
465       BitSet optionals = new BitSet();
466       if (struct.isSetValue()) {
467         optionals.set(0);
468       }
469       if (struct.isSetTimestamp()) {
470         optionals.set(1);
471       }
472       oprot.writeBitSet(optionals, 2);
473       if (struct.isSetValue()) {
474         oprot.writeBinary(struct.value);
475       }
476       if (struct.isSetTimestamp()) {
477         oprot.writeI64(struct.timestamp);
478       }
479     }
480 
481     @Override
482     public void read(org.apache.thrift.protocol.TProtocol prot, TCell struct) throws org.apache.thrift.TException {
483       TTupleProtocol iprot = (TTupleProtocol) prot;
484       BitSet incoming = iprot.readBitSet(2);
485       if (incoming.get(0)) {
486         struct.value = iprot.readBinary();
487         struct.setValueIsSet(true);
488       }
489       if (incoming.get(1)) {
490         struct.timestamp = iprot.readI64();
491         struct.setTimestampIsSet(true);
492       }
493     }
494   }
495 
496 }
497