View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.thrift.generated;
19  
20  import org.apache.commons.lang.builder.HashCodeBuilder;
21  import java.util.List;
22  import java.util.ArrayList;
23  import java.util.Map;
24  import java.util.HashMap;
25  import java.util.EnumMap;
26  import java.util.Set;
27  import java.util.HashSet;
28  import java.util.EnumSet;
29  import java.util.Collections;
30  import java.util.BitSet;
31  import java.util.Arrays;
32  import org.slf4j.Logger;
33  import org.slf4j.LoggerFactory;
34  
35  import org.apache.thrift.*;
36  import org.apache.thrift.meta_data.*;
37  import org.apache.thrift.protocol.*;
38  
39  /**
40   * A TRegionInfo contains information about an HTable region.
41   */
42  public class TRegionInfo implements TBase<TRegionInfo._Fields>, java.io.Serializable, Cloneable, Comparable<TRegionInfo> {
43    private static final TStruct STRUCT_DESC = new TStruct("TRegionInfo");
44  
45    private static final TField START_KEY_FIELD_DESC = new TField("startKey", TType.STRING, (short)1);
46    private static final TField END_KEY_FIELD_DESC = new TField("endKey", TType.STRING, (short)2);
47    private static final TField ID_FIELD_DESC = new TField("id", TType.I64, (short)3);
48    private static final TField NAME_FIELD_DESC = new TField("name", TType.STRING, (short)4);
49    private static final TField VERSION_FIELD_DESC = new TField("version", TType.BYTE, (short)5);
50  
51    public byte[] startKey;
52    public byte[] endKey;
53    public long id;
54    public byte[] name;
55    public byte version;
56  
57    /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
58    public enum _Fields implements TFieldIdEnum {
59      START_KEY((short)1, "startKey"),
60      END_KEY((short)2, "endKey"),
61      ID((short)3, "id"),
62      NAME((short)4, "name"),
63      VERSION((short)5, "version");
64  
65      private static final Map<Integer, _Fields> byId = new HashMap<Integer, _Fields>();
66      private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
67  
68      static {
69        for (_Fields field : EnumSet.allOf(_Fields.class)) {
70          byId.put((int)field._thriftId, field);
71          byName.put(field.getFieldName(), field);
72        }
73      }
74  
75      /**
76       * Find the _Fields constant that matches fieldId, or null if its not found.
77       */
78      public static _Fields findByThriftId(int fieldId) {
79        return byId.get(fieldId);
80      }
81  
82      /**
83       * Find the _Fields constant that matches fieldId, throwing an exception
84       * if it is not found.
85       */
86      public static _Fields findByThriftIdOrThrow(int fieldId) {
87        _Fields fields = findByThriftId(fieldId);
88        if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
89        return fields;
90      }
91  
92      /**
93       * Find the _Fields constant that matches name, or null if its not found.
94       */
95      public static _Fields findByName(String name) {
96        return byName.get(name);
97      }
98  
99      private final short _thriftId;
100     private final String _fieldName;
101 
102     _Fields(short thriftId, String fieldName) {
103       _thriftId = thriftId;
104       _fieldName = fieldName;
105     }
106 
107     public short getThriftFieldId() {
108       return _thriftId;
109     }
110 
111     public String getFieldName() {
112       return _fieldName;
113     }
114   }
115 
116   // isset id assignments
117   private static final int __ID_ISSET_ID = 0;
118   private static final int __VERSION_ISSET_ID = 1;
119   private BitSet __isset_bit_vector = new BitSet(2);
120 
121   public static final Map<_Fields, FieldMetaData> metaDataMap = Collections.unmodifiableMap(new EnumMap<_Fields, FieldMetaData>(_Fields.class) {{
122     put(_Fields.START_KEY, new FieldMetaData("startKey", TFieldRequirementType.DEFAULT,
123         new FieldValueMetaData(TType.STRING)));
124     put(_Fields.END_KEY, new FieldMetaData("endKey", TFieldRequirementType.DEFAULT,
125         new FieldValueMetaData(TType.STRING)));
126     put(_Fields.ID, new FieldMetaData("id", TFieldRequirementType.DEFAULT,
127         new FieldValueMetaData(TType.I64)));
128     put(_Fields.NAME, new FieldMetaData("name", TFieldRequirementType.DEFAULT,
129         new FieldValueMetaData(TType.STRING)));
130     put(_Fields.VERSION, new FieldMetaData("version", TFieldRequirementType.DEFAULT,
131         new FieldValueMetaData(TType.BYTE)));
132   }});
133 
134   static {
135     FieldMetaData.addStructMetaDataMap(TRegionInfo.class, metaDataMap);
136   }
137 
138   public TRegionInfo() {
139   }
140 
141   public TRegionInfo(
142     byte[] startKey,
143     byte[] endKey,
144     long id,
145     byte[] name,
146     byte version)
147   {
148     this();
149     this.startKey = startKey;
150     this.endKey = endKey;
151     this.id = id;
152     setIdIsSet(true);
153     this.name = name;
154     this.version = version;
155     setVersionIsSet(true);
156   }
157 
158   /**
159    * Performs a deep copy on <i>other</i>.
160    */
161   public TRegionInfo(TRegionInfo other) {
162     __isset_bit_vector.clear();
163     __isset_bit_vector.or(other.__isset_bit_vector);
164     if (other.isSetStartKey()) {
165       this.startKey = other.startKey;
166     }
167     if (other.isSetEndKey()) {
168       this.endKey = other.endKey;
169     }
170     this.id = other.id;
171     if (other.isSetName()) {
172       this.name = other.name;
173     }
174     this.version = other.version;
175   }
176 
177   public TRegionInfo deepCopy() {
178     return new TRegionInfo(this);
179   }
180 
181   @Deprecated
182   public TRegionInfo clone() {
183     return new TRegionInfo(this);
184   }
185 
186   public byte[] getStartKey() {
187     return this.startKey;
188   }
189 
190   public TRegionInfo setStartKey(byte[] startKey) {
191     this.startKey = startKey;
192     return this;
193   }
194 
195   public void unsetStartKey() {
196     this.startKey = null;
197   }
198 
199   /** Returns true if field startKey is set (has been asigned a value) and false otherwise */
200   public boolean isSetStartKey() {
201     return this.startKey != null;
202   }
203 
204   public void setStartKeyIsSet(boolean value) {
205     if (!value) {
206       this.startKey = null;
207     }
208   }
209 
210   public byte[] getEndKey() {
211     return this.endKey;
212   }
213 
214   public TRegionInfo setEndKey(byte[] endKey) {
215     this.endKey = endKey;
216     return this;
217   }
218 
219   public void unsetEndKey() {
220     this.endKey = null;
221   }
222 
223   /** Returns true if field endKey is set (has been asigned a value) and false otherwise */
224   public boolean isSetEndKey() {
225     return this.endKey != null;
226   }
227 
228   public void setEndKeyIsSet(boolean value) {
229     if (!value) {
230       this.endKey = null;
231     }
232   }
233 
234   public long getId() {
235     return this.id;
236   }
237 
238   public TRegionInfo setId(long id) {
239     this.id = id;
240     setIdIsSet(true);
241     return this;
242   }
243 
244   public void unsetId() {
245     __isset_bit_vector.clear(__ID_ISSET_ID);
246   }
247 
248   /** Returns true if field id is set (has been asigned a value) and false otherwise */
249   public boolean isSetId() {
250     return __isset_bit_vector.get(__ID_ISSET_ID);
251   }
252 
253   public void setIdIsSet(boolean value) {
254     __isset_bit_vector.set(__ID_ISSET_ID, value);
255   }
256 
257   public byte[] getName() {
258     return this.name;
259   }
260 
261   public TRegionInfo setName(byte[] name) {
262     this.name = name;
263     return this;
264   }
265 
266   public void unsetName() {
267     this.name = null;
268   }
269 
270   /** Returns true if field name is set (has been asigned a value) and false otherwise */
271   public boolean isSetName() {
272     return this.name != null;
273   }
274 
275   public void setNameIsSet(boolean value) {
276     if (!value) {
277       this.name = null;
278     }
279   }
280 
281   public byte getVersion() {
282     return this.version;
283   }
284 
285   public TRegionInfo setVersion(byte version) {
286     this.version = version;
287     setVersionIsSet(true);
288     return this;
289   }
290 
291   public void unsetVersion() {
292     __isset_bit_vector.clear(__VERSION_ISSET_ID);
293   }
294 
295   /** Returns true if field version is set (has been asigned a value) and false otherwise */
296   public boolean isSetVersion() {
297     return __isset_bit_vector.get(__VERSION_ISSET_ID);
298   }
299 
300   public void setVersionIsSet(boolean value) {
301     __isset_bit_vector.set(__VERSION_ISSET_ID, value);
302   }
303 
304   public void setFieldValue(_Fields field, Object value) {
305     switch (field) {
306     case START_KEY:
307       if (value == null) {
308         unsetStartKey();
309       } else {
310         setStartKey((byte[])value);
311       }
312       break;
313 
314     case END_KEY:
315       if (value == null) {
316         unsetEndKey();
317       } else {
318         setEndKey((byte[])value);
319       }
320       break;
321 
322     case ID:
323       if (value == null) {
324         unsetId();
325       } else {
326         setId((Long)value);
327       }
328       break;
329 
330     case NAME:
331       if (value == null) {
332         unsetName();
333       } else {
334         setName((byte[])value);
335       }
336       break;
337 
338     case VERSION:
339       if (value == null) {
340         unsetVersion();
341       } else {
342         setVersion((Byte)value);
343       }
344       break;
345 
346     }
347   }
348 
349   public void setFieldValue(int fieldID, Object value) {
350     setFieldValue(_Fields.findByThriftIdOrThrow(fieldID), value);
351   }
352 
353   public Object getFieldValue(_Fields field) {
354     switch (field) {
355     case START_KEY:
356       return getStartKey();
357 
358     case END_KEY:
359       return getEndKey();
360 
361     case ID:
362       return new Long(getId());
363 
364     case NAME:
365       return getName();
366 
367     case VERSION:
368       return new Byte(getVersion());
369 
370     }
371     throw new IllegalStateException();
372   }
373 
374   public Object getFieldValue(int fieldId) {
375     return getFieldValue(_Fields.findByThriftIdOrThrow(fieldId));
376   }
377 
378   /** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */
379   public boolean isSet(_Fields field) {
380     switch (field) {
381     case START_KEY:
382       return isSetStartKey();
383     case END_KEY:
384       return isSetEndKey();
385     case ID:
386       return isSetId();
387     case NAME:
388       return isSetName();
389     case VERSION:
390       return isSetVersion();
391     }
392     throw new IllegalStateException();
393   }
394 
395   public boolean isSet(int fieldID) {
396     return isSet(_Fields.findByThriftIdOrThrow(fieldID));
397   }
398 
399   @Override
400   public boolean equals(Object that) {
401     if (that == null)
402       return false;
403     if (that instanceof TRegionInfo)
404       return this.equals((TRegionInfo)that);
405     return false;
406   }
407 
408   public boolean equals(TRegionInfo that) {
409     if (that == null)
410       return false;
411 
412     boolean this_present_startKey = true && this.isSetStartKey();
413     boolean that_present_startKey = true && that.isSetStartKey();
414     if (this_present_startKey || that_present_startKey) {
415       if (!(this_present_startKey && that_present_startKey))
416         return false;
417       if (!java.util.Arrays.equals(this.startKey, that.startKey))
418         return false;
419     }
420 
421     boolean this_present_endKey = true && this.isSetEndKey();
422     boolean that_present_endKey = true && that.isSetEndKey();
423     if (this_present_endKey || that_present_endKey) {
424       if (!(this_present_endKey && that_present_endKey))
425         return false;
426       if (!java.util.Arrays.equals(this.endKey, that.endKey))
427         return false;
428     }
429 
430     boolean this_present_id = true;
431     boolean that_present_id = true;
432     if (this_present_id || that_present_id) {
433       if (!(this_present_id && that_present_id))
434         return false;
435       if (this.id != that.id)
436         return false;
437     }
438 
439     boolean this_present_name = true && this.isSetName();
440     boolean that_present_name = true && that.isSetName();
441     if (this_present_name || that_present_name) {
442       if (!(this_present_name && that_present_name))
443         return false;
444       if (!java.util.Arrays.equals(this.name, that.name))
445         return false;
446     }
447 
448     boolean this_present_version = true;
449     boolean that_present_version = true;
450     if (this_present_version || that_present_version) {
451       if (!(this_present_version && that_present_version))
452         return false;
453       if (this.version != that.version)
454         return false;
455     }
456 
457     return true;
458   }
459 
460   @Override
461   public int hashCode() {
462     HashCodeBuilder builder = new HashCodeBuilder();
463 
464     boolean present_startKey = true && (isSetStartKey());
465     builder.append(present_startKey);
466     if (present_startKey)
467       builder.append(startKey);
468 
469     boolean present_endKey = true && (isSetEndKey());
470     builder.append(present_endKey);
471     if (present_endKey)
472       builder.append(endKey);
473 
474     boolean present_id = true;
475     builder.append(present_id);
476     if (present_id)
477       builder.append(id);
478 
479     boolean present_name = true && (isSetName());
480     builder.append(present_name);
481     if (present_name)
482       builder.append(name);
483 
484     boolean present_version = true;
485     builder.append(present_version);
486     if (present_version)
487       builder.append(version);
488 
489     return builder.toHashCode();
490   }
491 
492   public int compareTo(TRegionInfo other) {
493     if (!getClass().equals(other.getClass())) {
494       return getClass().getName().compareTo(other.getClass().getName());
495     }
496 
497     int lastComparison = 0;
498     TRegionInfo typedOther = (TRegionInfo)other;
499 
500     lastComparison = Boolean.valueOf(isSetStartKey()).compareTo(isSetStartKey());
501     if (lastComparison != 0) {
502       return lastComparison;
503     }
504     lastComparison = TBaseHelper.compareTo(startKey, typedOther.startKey);
505     if (lastComparison != 0) {
506       return lastComparison;
507     }
508     lastComparison = Boolean.valueOf(isSetEndKey()).compareTo(isSetEndKey());
509     if (lastComparison != 0) {
510       return lastComparison;
511     }
512     lastComparison = TBaseHelper.compareTo(endKey, typedOther.endKey);
513     if (lastComparison != 0) {
514       return lastComparison;
515     }
516     lastComparison = Boolean.valueOf(isSetId()).compareTo(isSetId());
517     if (lastComparison != 0) {
518       return lastComparison;
519     }
520     lastComparison = TBaseHelper.compareTo(id, typedOther.id);
521     if (lastComparison != 0) {
522       return lastComparison;
523     }
524     lastComparison = Boolean.valueOf(isSetName()).compareTo(isSetName());
525     if (lastComparison != 0) {
526       return lastComparison;
527     }
528     lastComparison = TBaseHelper.compareTo(name, typedOther.name);
529     if (lastComparison != 0) {
530       return lastComparison;
531     }
532     lastComparison = Boolean.valueOf(isSetVersion()).compareTo(isSetVersion());
533     if (lastComparison != 0) {
534       return lastComparison;
535     }
536     lastComparison = TBaseHelper.compareTo(version, typedOther.version);
537     if (lastComparison != 0) {
538       return lastComparison;
539     }
540     return 0;
541   }
542 
543   public void read(TProtocol iprot) throws TException {
544     TField field;
545     iprot.readStructBegin();
546     while (true)
547     {
548       field = iprot.readFieldBegin();
549       if (field.type == TType.STOP) {
550         break;
551       }
552       _Fields fieldId = _Fields.findByThriftId(field.id);
553       if (fieldId == null) {
554         TProtocolUtil.skip(iprot, field.type);
555       } else {
556         switch (fieldId) {
557           case START_KEY:
558             if (field.type == TType.STRING) {
559               this.startKey = iprot.readBinary();
560             } else {
561               TProtocolUtil.skip(iprot, field.type);
562             }
563             break;
564           case END_KEY:
565             if (field.type == TType.STRING) {
566               this.endKey = iprot.readBinary();
567             } else {
568               TProtocolUtil.skip(iprot, field.type);
569             }
570             break;
571           case ID:
572             if (field.type == TType.I64) {
573               this.id = iprot.readI64();
574               setIdIsSet(true);
575             } else {
576               TProtocolUtil.skip(iprot, field.type);
577             }
578             break;
579           case NAME:
580             if (field.type == TType.STRING) {
581               this.name = iprot.readBinary();
582             } else {
583               TProtocolUtil.skip(iprot, field.type);
584             }
585             break;
586           case VERSION:
587             if (field.type == TType.BYTE) {
588               this.version = iprot.readByte();
589               setVersionIsSet(true);
590             } else {
591               TProtocolUtil.skip(iprot, field.type);
592             }
593             break;
594         }
595         iprot.readFieldEnd();
596       }
597     }
598     iprot.readStructEnd();
599 
600     // check for required fields of primitive type, which can't be checked in the validate method
601     validate();
602   }
603 
604   public void write(TProtocol oprot) throws TException {
605     validate();
606 
607     oprot.writeStructBegin(STRUCT_DESC);
608     if (this.startKey != null) {
609       oprot.writeFieldBegin(START_KEY_FIELD_DESC);
610       oprot.writeBinary(this.startKey);
611       oprot.writeFieldEnd();
612     }
613     if (this.endKey != null) {
614       oprot.writeFieldBegin(END_KEY_FIELD_DESC);
615       oprot.writeBinary(this.endKey);
616       oprot.writeFieldEnd();
617     }
618     oprot.writeFieldBegin(ID_FIELD_DESC);
619     oprot.writeI64(this.id);
620     oprot.writeFieldEnd();
621     if (this.name != null) {
622       oprot.writeFieldBegin(NAME_FIELD_DESC);
623       oprot.writeBinary(this.name);
624       oprot.writeFieldEnd();
625     }
626     oprot.writeFieldBegin(VERSION_FIELD_DESC);
627     oprot.writeByte(this.version);
628     oprot.writeFieldEnd();
629     oprot.writeFieldStop();
630     oprot.writeStructEnd();
631   }
632 
633   @Override
634   public String toString() {
635     StringBuilder sb = new StringBuilder("TRegionInfo(");
636     boolean first = true;
637 
638     sb.append("startKey:");
639     if (this.startKey == null) {
640       sb.append("null");
641     } else {
642       sb.append(this.startKey);
643     }
644     first = false;
645     if (!first) sb.append(", ");
646     sb.append("endKey:");
647     if (this.endKey == null) {
648       sb.append("null");
649     } else {
650       sb.append(this.endKey);
651     }
652     first = false;
653     if (!first) sb.append(", ");
654     sb.append("id:");
655     sb.append(this.id);
656     first = false;
657     if (!first) sb.append(", ");
658     sb.append("name:");
659     if (this.name == null) {
660       sb.append("null");
661     } else {
662       sb.append(this.name);
663     }
664     first = false;
665     if (!first) sb.append(", ");
666     sb.append("version:");
667     sb.append(this.version);
668     first = false;
669     sb.append(")");
670     return sb.toString();
671   }
672 
673   public void validate() throws TException {
674     // check for required fields
675   }
676 
677 }
678