View Javadoc

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