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