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