| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| /** |
| * Autogenerated by Thrift |
| * |
| * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING |
| */ |
| package com.example.tutorial; |
| |
| import java.util.ArrayList; |
| import java.util.BitSet; |
| import java.util.Collections; |
| import java.util.EnumMap; |
| import java.util.EnumSet; |
| import java.util.HashMap; |
| import java.util.List; |
| import java.util.Map; |
| |
| public class Person implements org.apache.thrift.TBase<Person, Person._Fields>, java.io.Serializable, Cloneable { |
| private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Person"); |
| |
| private static final org.apache.thrift.protocol.TField NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("name", org.apache.thrift.protocol.TType.STRING, (short)1); |
| private static final org.apache.thrift.protocol.TField ID_FIELD_DESC = new org.apache.thrift.protocol.TField("id", org.apache.thrift.protocol.TType.I32, (short)2); |
| private static final org.apache.thrift.protocol.TField EMAIL_FIELD_DESC = new org.apache.thrift.protocol.TField("email", org.apache.thrift.protocol.TType.STRING, (short)3); |
| private static final org.apache.thrift.protocol.TField PHONE_FIELD_DESC = new org.apache.thrift.protocol.TField("phone", org.apache.thrift.protocol.TType.LIST, (short)4); |
| |
| public String name; |
| public int id; |
| public String email; |
| public List<PhoneNumber> phone; |
| |
| /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ |
| public enum _Fields implements org.apache.thrift.TFieldIdEnum { |
| NAME((short)1, "name"), |
| ID((short)2, "id"), |
| EMAIL((short)3, "email"), |
| PHONE((short)4, "phone"); |
| |
| private static final Map<String, _Fields> byName = new HashMap<String, _Fields>(); |
| |
| static { |
| for (_Fields field : EnumSet.allOf(_Fields.class)) { |
| byName.put(field.getFieldName(), field); |
| } |
| } |
| |
| /** |
| * Find the _Fields constant that matches fieldId, or null if its not found. |
| */ |
| public static _Fields findByThriftId(int fieldId) { |
| switch(fieldId) { |
| case 1: // NAME |
| return NAME; |
| case 2: // ID |
| return ID; |
| case 3: // EMAIL |
| return EMAIL; |
| case 4: // PHONE |
| return PHONE; |
| default: |
| return null; |
| } |
| } |
| |
| /** |
| * Find the _Fields constant that matches fieldId, throwing an exception |
| * if it is not found. |
| */ |
| public static _Fields findByThriftIdOrThrow(int fieldId) { |
| _Fields fields = findByThriftId(fieldId); |
| if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); |
| return fields; |
| } |
| |
| /** |
| * Find the _Fields constant that matches name, or null if its not found. |
| */ |
| public static _Fields findByName(String name) { |
| return byName.get(name); |
| } |
| |
| private final short _thriftId; |
| private final String _fieldName; |
| |
| _Fields(short thriftId, String fieldName) { |
| _thriftId = thriftId; |
| _fieldName = fieldName; |
| } |
| |
| public short getThriftFieldId() { |
| return _thriftId; |
| } |
| |
| public String getFieldName() { |
| return _fieldName; |
| } |
| } |
| |
| // isset id assignments |
| private static final int __ID_ISSET_ID = 0; |
| private BitSet __isset_bit_vector = new BitSet(1); |
| |
| public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; |
| static { |
| Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); |
| tmpMap.put(_Fields.NAME, new org.apache.thrift.meta_data.FieldMetaData("name", org.apache.thrift.TFieldRequirementType.DEFAULT, |
| new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); |
| tmpMap.put(_Fields.ID, new org.apache.thrift.meta_data.FieldMetaData("id", org.apache.thrift.TFieldRequirementType.DEFAULT, |
| new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); |
| tmpMap.put(_Fields.EMAIL, new org.apache.thrift.meta_data.FieldMetaData("email", org.apache.thrift.TFieldRequirementType.DEFAULT, |
| new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); |
| tmpMap.put(_Fields.PHONE, new org.apache.thrift.meta_data.FieldMetaData("phone", org.apache.thrift.TFieldRequirementType.DEFAULT, |
| new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, |
| new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, PhoneNumber.class)))); |
| metaDataMap = Collections.unmodifiableMap(tmpMap); |
| org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Person.class, metaDataMap); |
| } |
| |
| public Person() { |
| } |
| |
| public Person( |
| String name, |
| int id, |
| String email, |
| List<PhoneNumber> phone) |
| { |
| this(); |
| this.name = name; |
| this.id = id; |
| setIdIsSet(true); |
| this.email = email; |
| this.phone = phone; |
| } |
| |
| /** |
| * Performs a deep copy on <i>other</i>. |
| */ |
| public Person(Person other) { |
| __isset_bit_vector.clear(); |
| __isset_bit_vector.or(other.__isset_bit_vector); |
| if (other.isSetName()) { |
| this.name = other.name; |
| } |
| this.id = other.id; |
| if (other.isSetEmail()) { |
| this.email = other.email; |
| } |
| if (other.isSetPhone()) { |
| List<PhoneNumber> __this__phone = new ArrayList<PhoneNumber>(); |
| for (PhoneNumber other_element : other.phone) { |
| __this__phone.add(new PhoneNumber(other_element)); |
| } |
| this.phone = __this__phone; |
| } |
| } |
| |
| public Person deepCopy() { |
| return new Person(this); |
| } |
| |
| // @Override |
| public void clear() { |
| this.name = null; |
| setIdIsSet(false); |
| this.id = 0; |
| this.email = null; |
| this.phone = null; |
| } |
| |
| public String getName() { |
| return this.name; |
| } |
| |
| public Person setName(String name) { |
| this.name = name; |
| return this; |
| } |
| |
| public void unsetName() { |
| this.name = null; |
| } |
| |
| /** Returns true if field name is set (has been assigned a value) and false otherwise */ |
| public boolean isSetName() { |
| return this.name != null; |
| } |
| |
| public void setNameIsSet(boolean value) { |
| if (!value) { |
| this.name = null; |
| } |
| } |
| |
| public int getId() { |
| return this.id; |
| } |
| |
| public Person setId(int id) { |
| this.id = id; |
| setIdIsSet(true); |
| return this; |
| } |
| |
| public void unsetId() { |
| __isset_bit_vector.clear(__ID_ISSET_ID); |
| } |
| |
| /** Returns true if field id is set (has been assigned a value) and false otherwise */ |
| public boolean isSetId() { |
| return __isset_bit_vector.get(__ID_ISSET_ID); |
| } |
| |
| public void setIdIsSet(boolean value) { |
| __isset_bit_vector.set(__ID_ISSET_ID, value); |
| } |
| |
| public String getEmail() { |
| return this.email; |
| } |
| |
| public Person setEmail(String email) { |
| this.email = email; |
| return this; |
| } |
| |
| public void unsetEmail() { |
| this.email = null; |
| } |
| |
| /** Returns true if field email is set (has been assigned a value) and false otherwise */ |
| public boolean isSetEmail() { |
| return this.email != null; |
| } |
| |
| public void setEmailIsSet(boolean value) { |
| if (!value) { |
| this.email = null; |
| } |
| } |
| |
| public int getPhoneSize() { |
| return (this.phone == null) ? 0 : this.phone.size(); |
| } |
| |
| public java.util.Iterator<PhoneNumber> getPhoneIterator() { |
| return (this.phone == null) ? null : this.phone.iterator(); |
| } |
| |
| public void addToPhone(PhoneNumber elem) { |
| if (this.phone == null) { |
| this.phone = new ArrayList<PhoneNumber>(); |
| } |
| this.phone.add(elem); |
| } |
| |
| public List<PhoneNumber> getPhone() { |
| return this.phone; |
| } |
| |
| public Person setPhone(List<PhoneNumber> phone) { |
| this.phone = phone; |
| return this; |
| } |
| |
| public void unsetPhone() { |
| this.phone = null; |
| } |
| |
| /** Returns true if field phone is set (has been assigned a value) and false otherwise */ |
| public boolean isSetPhone() { |
| return this.phone != null; |
| } |
| |
| public void setPhoneIsSet(boolean value) { |
| if (!value) { |
| this.phone = null; |
| } |
| } |
| |
| public void setFieldValue(_Fields field, Object value) { |
| switch (field) { |
| case NAME: |
| if (value == null) { |
| unsetName(); |
| } else { |
| setName((String)value); |
| } |
| break; |
| |
| case ID: |
| if (value == null) { |
| unsetId(); |
| } else { |
| setId((Integer)value); |
| } |
| break; |
| |
| case EMAIL: |
| if (value == null) { |
| unsetEmail(); |
| } else { |
| setEmail((String)value); |
| } |
| break; |
| |
| case PHONE: |
| if (value == null) { |
| unsetPhone(); |
| } else { |
| setPhone((List<PhoneNumber>)value); |
| } |
| break; |
| |
| } |
| } |
| |
| public Object getFieldValue(_Fields field) { |
| switch (field) { |
| case NAME: |
| return getName(); |
| |
| case ID: |
| return new Integer(getId()); |
| |
| case EMAIL: |
| return getEmail(); |
| |
| case PHONE: |
| return getPhone(); |
| |
| } |
| throw new IllegalStateException(); |
| } |
| |
| /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ |
| public boolean isSet(_Fields field) { |
| if (field == null) { |
| throw new IllegalArgumentException(); |
| } |
| |
| switch (field) { |
| case NAME: |
| return isSetName(); |
| case ID: |
| return isSetId(); |
| case EMAIL: |
| return isSetEmail(); |
| case PHONE: |
| return isSetPhone(); |
| } |
| throw new IllegalStateException(); |
| } |
| |
| @Override |
| public boolean equals(Object that) { |
| if (that == null) |
| return false; |
| if (that instanceof Person) |
| return this.equals((Person)that); |
| return false; |
| } |
| |
| public boolean equals(Person that) { |
| if (that == null) |
| return false; |
| |
| boolean this_present_name = true && this.isSetName(); |
| boolean that_present_name = true && that.isSetName(); |
| if (this_present_name || that_present_name) { |
| if (!(this_present_name && that_present_name)) |
| return false; |
| if (!this.name.equals(that.name)) |
| return false; |
| } |
| |
| boolean this_present_id = true; |
| boolean that_present_id = true; |
| if (this_present_id || that_present_id) { |
| if (!(this_present_id && that_present_id)) |
| return false; |
| if (this.id != that.id) |
| return false; |
| } |
| |
| boolean this_present_email = true && this.isSetEmail(); |
| boolean that_present_email = true && that.isSetEmail(); |
| if (this_present_email || that_present_email) { |
| if (!(this_present_email && that_present_email)) |
| return false; |
| if (!this.email.equals(that.email)) |
| return false; |
| } |
| |
| boolean this_present_phone = true && this.isSetPhone(); |
| boolean that_present_phone = true && that.isSetPhone(); |
| if (this_present_phone || that_present_phone) { |
| if (!(this_present_phone && that_present_phone)) |
| return false; |
| if (!this.phone.equals(that.phone)) |
| return false; |
| } |
| |
| return true; |
| } |
| |
| @Override |
| public int hashCode() { |
| return 0; |
| } |
| |
| public int compareTo(Person other) { |
| if (!getClass().equals(other.getClass())) { |
| return getClass().getName().compareTo(other.getClass().getName()); |
| } |
| |
| int lastComparison = 0; |
| Person typedOther = (Person)other; |
| |
| lastComparison = Boolean.valueOf(isSetName()).compareTo(typedOther.isSetName()); |
| if (lastComparison != 0) { |
| return lastComparison; |
| } |
| if (isSetName()) { |
| lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.name, typedOther.name); |
| if (lastComparison != 0) { |
| return lastComparison; |
| } |
| } |
| lastComparison = Boolean.valueOf(isSetId()).compareTo(typedOther.isSetId()); |
| if (lastComparison != 0) { |
| return lastComparison; |
| } |
| if (isSetId()) { |
| lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.id, typedOther.id); |
| if (lastComparison != 0) { |
| return lastComparison; |
| } |
| } |
| lastComparison = Boolean.valueOf(isSetEmail()).compareTo(typedOther.isSetEmail()); |
| if (lastComparison != 0) { |
| return lastComparison; |
| } |
| if (isSetEmail()) { |
| lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.email, typedOther.email); |
| if (lastComparison != 0) { |
| return lastComparison; |
| } |
| } |
| lastComparison = Boolean.valueOf(isSetPhone()).compareTo(typedOther.isSetPhone()); |
| if (lastComparison != 0) { |
| return lastComparison; |
| } |
| if (isSetPhone()) { |
| lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.phone, typedOther.phone); |
| if (lastComparison != 0) { |
| return lastComparison; |
| } |
| } |
| return 0; |
| } |
| |
| public _Fields fieldForId(int fieldId) { |
| return _Fields.findByThriftId(fieldId); |
| } |
| |
| public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { |
| org.apache.thrift.protocol.TField field; |
| iprot.readStructBegin(); |
| while (true) |
| { |
| field = iprot.readFieldBegin(); |
| if (field.type == org.apache.thrift.protocol.TType.STOP) { |
| break; |
| } |
| switch (field.id) { |
| case 1: // NAME |
| if (field.type == org.apache.thrift.protocol.TType.STRING) { |
| this.name = iprot.readString(); |
| } else { |
| org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); |
| } |
| break; |
| case 2: // ID |
| if (field.type == org.apache.thrift.protocol.TType.I32) { |
| this.id = iprot.readI32(); |
| setIdIsSet(true); |
| } else { |
| org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); |
| } |
| break; |
| case 3: // EMAIL |
| if (field.type == org.apache.thrift.protocol.TType.STRING) { |
| this.email = iprot.readString(); |
| } else { |
| org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); |
| } |
| break; |
| case 4: // PHONE |
| if (field.type == org.apache.thrift.protocol.TType.LIST) { |
| { |
| org.apache.thrift.protocol.TList _list0 = iprot.readListBegin(); |
| this.phone = new ArrayList<PhoneNumber>(_list0.size); |
| for (int _i1 = 0; _i1 < _list0.size; ++_i1) |
| { |
| PhoneNumber _elem2; |
| _elem2 = new PhoneNumber(); |
| _elem2.read(iprot); |
| this.phone.add(_elem2); |
| } |
| iprot.readListEnd(); |
| } |
| } else { |
| org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); |
| } |
| break; |
| default: |
| org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); |
| } |
| iprot.readFieldEnd(); |
| } |
| iprot.readStructEnd(); |
| |
| // check for required fields of primitive type, which can't be checked in the validate method |
| validate(); |
| } |
| |
| public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { |
| validate(); |
| |
| oprot.writeStructBegin(STRUCT_DESC); |
| if (this.name != null) { |
| oprot.writeFieldBegin(NAME_FIELD_DESC); |
| oprot.writeString(this.name); |
| oprot.writeFieldEnd(); |
| } |
| oprot.writeFieldBegin(ID_FIELD_DESC); |
| oprot.writeI32(this.id); |
| oprot.writeFieldEnd(); |
| if (this.email != null) { |
| oprot.writeFieldBegin(EMAIL_FIELD_DESC); |
| oprot.writeString(this.email); |
| oprot.writeFieldEnd(); |
| } |
| if (this.phone != null) { |
| oprot.writeFieldBegin(PHONE_FIELD_DESC); |
| { |
| oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, this.phone.size())); |
| for (PhoneNumber _iter3 : this.phone) |
| { |
| _iter3.write(oprot); |
| } |
| oprot.writeListEnd(); |
| } |
| oprot.writeFieldEnd(); |
| } |
| oprot.writeFieldStop(); |
| oprot.writeStructEnd(); |
| } |
| |
| @Override |
| public String toString() { |
| StringBuilder sb = new StringBuilder("Person("); |
| boolean first = true; |
| |
| sb.append("name:"); |
| if (this.name == null) { |
| sb.append("null"); |
| } else { |
| sb.append(this.name); |
| } |
| first = false; |
| if (!first) sb.append(", "); |
| sb.append("id:"); |
| sb.append(this.id); |
| first = false; |
| if (!first) sb.append(", "); |
| sb.append("email:"); |
| if (this.email == null) { |
| sb.append("null"); |
| } else { |
| sb.append(this.email); |
| } |
| first = false; |
| if (!first) sb.append(", "); |
| sb.append("phone:"); |
| if (this.phone == null) { |
| sb.append("null"); |
| } else { |
| sb.append(this.phone); |
| } |
| first = false; |
| sb.append(")"); |
| return sb.toString(); |
| } |
| |
| public void validate() throws org.apache.thrift.TException { |
| // check for required fields |
| } |
| |
| private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { |
| try { |
| write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); |
| } catch (org.apache.thrift.TException te) { |
| throw new java.io.IOException(te.getMessage()); |
| } |
| } |
| |
| private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { |
| try { |
| // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. |
| __isset_bit_vector = new BitSet(1); |
| read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); |
| } catch (org.apache.thrift.TException te) { |
| throw new java.io.IOException(te.getMessage()); |
| } |
| } |
| |
| } |
| |