/**
 * Autogenerated by Thrift Compiler (0.7.0)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 */
package org.apache.avro.thrift.test;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Set;
import java.util.HashSet;
import java.util.EnumSet;
import java.util.Collections;
import java.util.BitSet;
import java.nio.ByteBuffer;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Test implements org.apache.thrift.TBase<Test, Test._Fields>, java.io.Serializable, Cloneable {
  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Test");

  private static final org.apache.thrift.protocol.TField BOOL_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("boolField", org.apache.thrift.protocol.TType.BOOL, (short)1);
  private static final org.apache.thrift.protocol.TField BYTE_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("byteField", org.apache.thrift.protocol.TType.BYTE, (short)2);
  private static final org.apache.thrift.protocol.TField I16_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("i16Field", org.apache.thrift.protocol.TType.I16, (short)3);
  private static final org.apache.thrift.protocol.TField I16_OPTIONAL_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("i16OptionalField", org.apache.thrift.protocol.TType.I16, (short)15);
  private static final org.apache.thrift.protocol.TField I32_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("i32Field", org.apache.thrift.protocol.TType.I32, (short)4);
  private static final org.apache.thrift.protocol.TField I64_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("i64Field", org.apache.thrift.protocol.TType.I64, (short)5);
  private static final org.apache.thrift.protocol.TField DOUBLE_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("doubleField", org.apache.thrift.protocol.TType.DOUBLE, (short)6);
  private static final org.apache.thrift.protocol.TField STRING_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("stringField", org.apache.thrift.protocol.TType.STRING, (short)7);
  private static final org.apache.thrift.protocol.TField BINARY_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("binaryField", org.apache.thrift.protocol.TType.STRING, (short)8);
  private static final org.apache.thrift.protocol.TField MAP_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("mapField", org.apache.thrift.protocol.TType.MAP, (short)9);
  private static final org.apache.thrift.protocol.TField LIST_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("listField", org.apache.thrift.protocol.TType.LIST, (short)10);
  private static final org.apache.thrift.protocol.TField SET_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("setField", org.apache.thrift.protocol.TType.SET, (short)11);
  private static final org.apache.thrift.protocol.TField ENUM_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("enumField", org.apache.thrift.protocol.TType.I32, (short)12);
  private static final org.apache.thrift.protocol.TField STRUCT_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("structField", org.apache.thrift.protocol.TType.STRUCT, (short)13);
  private static final org.apache.thrift.protocol.TField FOO_OR_BAR_FIELD_DESC = new org.apache.thrift.protocol.TField("fooOrBar", org.apache.thrift.protocol.TType.STRUCT, (short)14);

  private boolean boolField; // required
  private byte byteField; // required
  private short i16Field; // required
  private short i16OptionalField; // required
  private int i32Field; // required
  private long i64Field; // required
  private double doubleField; // required
  private String stringField; // required
  private ByteBuffer binaryField; // required
  private Map<String,Integer> mapField; // required
  private List<Integer> listField; // required
  private Set<Integer> setField; // required
  private E enumField; // required
  private Nested structField; // required
  private FooOrBar fooOrBar; // required

  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
  public enum _Fields implements org.apache.thrift.TFieldIdEnum {
    BOOL_FIELD((short)1, "boolField"),
    BYTE_FIELD((short)2, "byteField"),
    I16_FIELD((short)3, "i16Field"),
    I16_OPTIONAL_FIELD((short)15, "i16OptionalField"),
    I32_FIELD((short)4, "i32Field"),
    I64_FIELD((short)5, "i64Field"),
    DOUBLE_FIELD((short)6, "doubleField"),
    STRING_FIELD((short)7, "stringField"),
    BINARY_FIELD((short)8, "binaryField"),
    MAP_FIELD((short)9, "mapField"),
    LIST_FIELD((short)10, "listField"),
    SET_FIELD((short)11, "setField"),
    /**
     * 
     * @see E
     */
    ENUM_FIELD((short)12, "enumField"),
    STRUCT_FIELD((short)13, "structField"),
    FOO_OR_BAR((short)14, "fooOrBar");

    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: // BOOL_FIELD
          return BOOL_FIELD;
        case 2: // BYTE_FIELD
          return BYTE_FIELD;
        case 3: // I16_FIELD
          return I16_FIELD;
        case 15: // I16_OPTIONAL_FIELD
          return I16_OPTIONAL_FIELD;
        case 4: // I32_FIELD
          return I32_FIELD;
        case 5: // I64_FIELD
          return I64_FIELD;
        case 6: // DOUBLE_FIELD
          return DOUBLE_FIELD;
        case 7: // STRING_FIELD
          return STRING_FIELD;
        case 8: // BINARY_FIELD
          return BINARY_FIELD;
        case 9: // MAP_FIELD
          return MAP_FIELD;
        case 10: // LIST_FIELD
          return LIST_FIELD;
        case 11: // SET_FIELD
          return SET_FIELD;
        case 12: // ENUM_FIELD
          return ENUM_FIELD;
        case 13: // STRUCT_FIELD
          return STRUCT_FIELD;
        case 14: // FOO_OR_BAR
          return FOO_OR_BAR;
        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 __BOOLFIELD_ISSET_ID = 0;
  private static final int __BYTEFIELD_ISSET_ID = 1;
  private static final int __I16FIELD_ISSET_ID = 2;
  private static final int __I16OPTIONALFIELD_ISSET_ID = 3;
  private static final int __I32FIELD_ISSET_ID = 4;
  private static final int __I64FIELD_ISSET_ID = 5;
  private static final int __DOUBLEFIELD_ISSET_ID = 6;
  private BitSet __isset_bit_vector = new BitSet(7);

  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.BOOL_FIELD, new org.apache.thrift.meta_data.FieldMetaData("boolField", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BOOL)));
    tmpMap.put(_Fields.BYTE_FIELD, new org.apache.thrift.meta_data.FieldMetaData("byteField", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BYTE)));
    tmpMap.put(_Fields.I16_FIELD, new org.apache.thrift.meta_data.FieldMetaData("i16Field", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I16)));
    tmpMap.put(_Fields.I16_OPTIONAL_FIELD, new org.apache.thrift.meta_data.FieldMetaData("i16OptionalField", org.apache.thrift.TFieldRequirementType.OPTIONAL, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I16)));
    tmpMap.put(_Fields.I32_FIELD, new org.apache.thrift.meta_data.FieldMetaData("i32Field", org.apache.thrift.TFieldRequirementType.OPTIONAL, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
    tmpMap.put(_Fields.I64_FIELD, new org.apache.thrift.meta_data.FieldMetaData("i64Field", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64)));
    tmpMap.put(_Fields.DOUBLE_FIELD, new org.apache.thrift.meta_data.FieldMetaData("doubleField", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.DOUBLE)));
    tmpMap.put(_Fields.STRING_FIELD, new org.apache.thrift.meta_data.FieldMetaData("stringField", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    tmpMap.put(_Fields.BINARY_FIELD, new org.apache.thrift.meta_data.FieldMetaData("binaryField", org.apache.thrift.TFieldRequirementType.OPTIONAL, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , true)));
    tmpMap.put(_Fields.MAP_FIELD, new org.apache.thrift.meta_data.FieldMetaData("mapField", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.MapMetaData(org.apache.thrift.protocol.TType.MAP, 
            new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING), 
            new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))));
    tmpMap.put(_Fields.LIST_FIELD, new org.apache.thrift.meta_data.FieldMetaData("listField", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, 
            new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))));
    tmpMap.put(_Fields.SET_FIELD, new org.apache.thrift.meta_data.FieldMetaData("setField", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.SetMetaData(org.apache.thrift.protocol.TType.SET, 
            new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))));
    tmpMap.put(_Fields.ENUM_FIELD, new org.apache.thrift.meta_data.FieldMetaData("enumField", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.EnumMetaData(org.apache.thrift.protocol.TType.ENUM, E.class)));
    tmpMap.put(_Fields.STRUCT_FIELD, new org.apache.thrift.meta_data.FieldMetaData("structField", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, Nested.class)));
    tmpMap.put(_Fields.FOO_OR_BAR, new org.apache.thrift.meta_data.FieldMetaData("fooOrBar", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, FooOrBar.class)));
    metaDataMap = Collections.unmodifiableMap(tmpMap);
    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Test.class, metaDataMap);
  }

  public Test() {
  }

  public Test(
    boolean boolField,
    byte byteField,
    short i16Field,
    long i64Field,
    double doubleField,
    String stringField,
    Map<String,Integer> mapField,
    List<Integer> listField,
    Set<Integer> setField,
    E enumField,
    Nested structField,
    FooOrBar fooOrBar)
  {
    this();
    this.boolField = boolField;
    setBoolFieldIsSet(true);
    this.byteField = byteField;
    setByteFieldIsSet(true);
    this.i16Field = i16Field;
    setI16FieldIsSet(true);
    this.i64Field = i64Field;
    setI64FieldIsSet(true);
    this.doubleField = doubleField;
    setDoubleFieldIsSet(true);
    this.stringField = stringField;
    this.mapField = mapField;
    this.listField = listField;
    this.setField = setField;
    this.enumField = enumField;
    this.structField = structField;
    this.fooOrBar = fooOrBar;
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public Test(Test other) {
    __isset_bit_vector.clear();
    __isset_bit_vector.or(other.__isset_bit_vector);
    this.boolField = other.boolField;
    this.byteField = other.byteField;
    this.i16Field = other.i16Field;
    this.i16OptionalField = other.i16OptionalField;
    this.i32Field = other.i32Field;
    this.i64Field = other.i64Field;
    this.doubleField = other.doubleField;
    if (other.isSetStringField()) {
      this.stringField = other.stringField;
    }
    if (other.isSetBinaryField()) {
      this.binaryField = org.apache.thrift.TBaseHelper.copyBinary(other.binaryField);
;
    }
    if (other.isSetMapField()) {
      Map<String,Integer> __this__mapField = new HashMap<String,Integer>();
      for (Map.Entry<String, Integer> other_element : other.mapField.entrySet()) {

        String other_element_key = other_element.getKey();
        Integer other_element_value = other_element.getValue();

        String __this__mapField_copy_key = other_element_key;

        Integer __this__mapField_copy_value = other_element_value;

        __this__mapField.put(__this__mapField_copy_key, __this__mapField_copy_value);
      }
      this.mapField = __this__mapField;
    }
    if (other.isSetListField()) {
      List<Integer> __this__listField = new ArrayList<Integer>();
      for (Integer other_element : other.listField) {
        __this__listField.add(other_element);
      }
      this.listField = __this__listField;
    }
    if (other.isSetSetField()) {
      Set<Integer> __this__setField = new HashSet<Integer>();
      for (Integer other_element : other.setField) {
        __this__setField.add(other_element);
      }
      this.setField = __this__setField;
    }
    if (other.isSetEnumField()) {
      this.enumField = other.enumField;
    }
    if (other.isSetStructField()) {
      this.structField = new Nested(other.structField);
    }
    if (other.isSetFooOrBar()) {
      this.fooOrBar = new FooOrBar(other.fooOrBar);
    }
  }

  public Test deepCopy() {
    return new Test(this);
  }

  @Override
  public void clear() {
    setBoolFieldIsSet(false);
    this.boolField = false;
    setByteFieldIsSet(false);
    this.byteField = 0;
    setI16FieldIsSet(false);
    this.i16Field = 0;
    setI16OptionalFieldIsSet(false);
    this.i16OptionalField = 0;
    setI32FieldIsSet(false);
    this.i32Field = 0;
    setI64FieldIsSet(false);
    this.i64Field = 0;
    setDoubleFieldIsSet(false);
    this.doubleField = 0.0;
    this.stringField = null;
    this.binaryField = null;
    this.mapField = null;
    this.listField = null;
    this.setField = null;
    this.enumField = null;
    this.structField = null;
    this.fooOrBar = null;
  }

  public boolean isBoolField() {
    return this.boolField;
  }

  public void setBoolField(boolean boolField) {
    this.boolField = boolField;
    setBoolFieldIsSet(true);
  }

  public void unsetBoolField() {
    __isset_bit_vector.clear(__BOOLFIELD_ISSET_ID);
  }

  /** Returns true if field boolField is set (has been assigned a value) and false otherwise */
  public boolean isSetBoolField() {
    return __isset_bit_vector.get(__BOOLFIELD_ISSET_ID);
  }

  public void setBoolFieldIsSet(boolean value) {
    __isset_bit_vector.set(__BOOLFIELD_ISSET_ID, value);
  }

  public byte getByteField() {
    return this.byteField;
  }

  public void setByteField(byte byteField) {
    this.byteField = byteField;
    setByteFieldIsSet(true);
  }

  public void unsetByteField() {
    __isset_bit_vector.clear(__BYTEFIELD_ISSET_ID);
  }

  /** Returns true if field byteField is set (has been assigned a value) and false otherwise */
  public boolean isSetByteField() {
    return __isset_bit_vector.get(__BYTEFIELD_ISSET_ID);
  }

  public void setByteFieldIsSet(boolean value) {
    __isset_bit_vector.set(__BYTEFIELD_ISSET_ID, value);
  }

  public short getI16Field() {
    return this.i16Field;
  }

  public void setI16Field(short i16Field) {
    this.i16Field = i16Field;
    setI16FieldIsSet(true);
  }

  public void unsetI16Field() {
    __isset_bit_vector.clear(__I16FIELD_ISSET_ID);
  }

  /** Returns true if field i16Field is set (has been assigned a value) and false otherwise */
  public boolean isSetI16Field() {
    return __isset_bit_vector.get(__I16FIELD_ISSET_ID);
  }

  public void setI16FieldIsSet(boolean value) {
    __isset_bit_vector.set(__I16FIELD_ISSET_ID, value);
  }

  public short getI16OptionalField() {
    return this.i16OptionalField;
  }

  public void setI16OptionalField(short i16OptionalField) {
    this.i16OptionalField = i16OptionalField;
    setI16OptionalFieldIsSet(true);
  }

  public void unsetI16OptionalField() {
    __isset_bit_vector.clear(__I16OPTIONALFIELD_ISSET_ID);
  }

  /** Returns true if field i16OptionalField is set (has been assigned a value) and false otherwise */
  public boolean isSetI16OptionalField() {
    return __isset_bit_vector.get(__I16OPTIONALFIELD_ISSET_ID);
  }

  public void setI16OptionalFieldIsSet(boolean value) {
    __isset_bit_vector.set(__I16OPTIONALFIELD_ISSET_ID, value);
  }

  public int getI32Field() {
    return this.i32Field;
  }

  public void setI32Field(int i32Field) {
    this.i32Field = i32Field;
    setI32FieldIsSet(true);
  }

  public void unsetI32Field() {
    __isset_bit_vector.clear(__I32FIELD_ISSET_ID);
  }

  /** Returns true if field i32Field is set (has been assigned a value) and false otherwise */
  public boolean isSetI32Field() {
    return __isset_bit_vector.get(__I32FIELD_ISSET_ID);
  }

  public void setI32FieldIsSet(boolean value) {
    __isset_bit_vector.set(__I32FIELD_ISSET_ID, value);
  }

  public long getI64Field() {
    return this.i64Field;
  }

  public void setI64Field(long i64Field) {
    this.i64Field = i64Field;
    setI64FieldIsSet(true);
  }

  public void unsetI64Field() {
    __isset_bit_vector.clear(__I64FIELD_ISSET_ID);
  }

  /** Returns true if field i64Field is set (has been assigned a value) and false otherwise */
  public boolean isSetI64Field() {
    return __isset_bit_vector.get(__I64FIELD_ISSET_ID);
  }

  public void setI64FieldIsSet(boolean value) {
    __isset_bit_vector.set(__I64FIELD_ISSET_ID, value);
  }

  public double getDoubleField() {
    return this.doubleField;
  }

  public void setDoubleField(double doubleField) {
    this.doubleField = doubleField;
    setDoubleFieldIsSet(true);
  }

  public void unsetDoubleField() {
    __isset_bit_vector.clear(__DOUBLEFIELD_ISSET_ID);
  }

  /** Returns true if field doubleField is set (has been assigned a value) and false otherwise */
  public boolean isSetDoubleField() {
    return __isset_bit_vector.get(__DOUBLEFIELD_ISSET_ID);
  }

  public void setDoubleFieldIsSet(boolean value) {
    __isset_bit_vector.set(__DOUBLEFIELD_ISSET_ID, value);
  }

  public String getStringField() {
    return this.stringField;
  }

  public void setStringField(String stringField) {
    this.stringField = stringField;
  }

  public void unsetStringField() {
    this.stringField = null;
  }

  /** Returns true if field stringField is set (has been assigned a value) and false otherwise */
  public boolean isSetStringField() {
    return this.stringField != null;
  }

  public void setStringFieldIsSet(boolean value) {
    if (!value) {
      this.stringField = null;
    }
  }

  public byte[] getBinaryField() {
    setBinaryField(org.apache.thrift.TBaseHelper.rightSize(binaryField));
    return binaryField == null ? null : binaryField.array();
  }

  public ByteBuffer bufferForBinaryField() {
    return binaryField;
  }

  public void setBinaryField(byte[] binaryField) {
    setBinaryField(binaryField == null ? (ByteBuffer)null : ByteBuffer.wrap(binaryField));
  }

  public void setBinaryField(ByteBuffer binaryField) {
    this.binaryField = binaryField;
  }

  public void unsetBinaryField() {
    this.binaryField = null;
  }

  /** Returns true if field binaryField is set (has been assigned a value) and false otherwise */
  public boolean isSetBinaryField() {
    return this.binaryField != null;
  }

  public void setBinaryFieldIsSet(boolean value) {
    if (!value) {
      this.binaryField = null;
    }
  }

  public int getMapFieldSize() {
    return (this.mapField == null) ? 0 : this.mapField.size();
  }

  public void putToMapField(String key, int val) {
    if (this.mapField == null) {
      this.mapField = new HashMap<String,Integer>();
    }
    this.mapField.put(key, val);
  }

  public Map<String,Integer> getMapField() {
    return this.mapField;
  }

  public void setMapField(Map<String,Integer> mapField) {
    this.mapField = mapField;
  }

  public void unsetMapField() {
    this.mapField = null;
  }

  /** Returns true if field mapField is set (has been assigned a value) and false otherwise */
  public boolean isSetMapField() {
    return this.mapField != null;
  }

  public void setMapFieldIsSet(boolean value) {
    if (!value) {
      this.mapField = null;
    }
  }

  public int getListFieldSize() {
    return (this.listField == null) ? 0 : this.listField.size();
  }

  public java.util.Iterator<Integer> getListFieldIterator() {
    return (this.listField == null) ? null : this.listField.iterator();
  }

  public void addToListField(int elem) {
    if (this.listField == null) {
      this.listField = new ArrayList<Integer>();
    }
    this.listField.add(elem);
  }

  public List<Integer> getListField() {
    return this.listField;
  }

  public void setListField(List<Integer> listField) {
    this.listField = listField;
  }

  public void unsetListField() {
    this.listField = null;
  }

  /** Returns true if field listField is set (has been assigned a value) and false otherwise */
  public boolean isSetListField() {
    return this.listField != null;
  }

  public void setListFieldIsSet(boolean value) {
    if (!value) {
      this.listField = null;
    }
  }

  public int getSetFieldSize() {
    return (this.setField == null) ? 0 : this.setField.size();
  }

  public java.util.Iterator<Integer> getSetFieldIterator() {
    return (this.setField == null) ? null : this.setField.iterator();
  }

  public void addToSetField(int elem) {
    if (this.setField == null) {
      this.setField = new HashSet<Integer>();
    }
    this.setField.add(elem);
  }

  public Set<Integer> getSetField() {
    return this.setField;
  }

  public void setSetField(Set<Integer> setField) {
    this.setField = setField;
  }

  public void unsetSetField() {
    this.setField = null;
  }

  /** Returns true if field setField is set (has been assigned a value) and false otherwise */
  public boolean isSetSetField() {
    return this.setField != null;
  }

  public void setSetFieldIsSet(boolean value) {
    if (!value) {
      this.setField = null;
    }
  }

  /**
   * 
   * @see E
   */
  public E getEnumField() {
    return this.enumField;
  }

  /**
   * 
   * @see E
   */
  public void setEnumField(E enumField) {
    this.enumField = enumField;
  }

  public void unsetEnumField() {
    this.enumField = null;
  }

  /** Returns true if field enumField is set (has been assigned a value) and false otherwise */
  public boolean isSetEnumField() {
    return this.enumField != null;
  }

  public void setEnumFieldIsSet(boolean value) {
    if (!value) {
      this.enumField = null;
    }
  }

  public Nested getStructField() {
    return this.structField;
  }

  public void setStructField(Nested structField) {
    this.structField = structField;
  }

  public void unsetStructField() {
    this.structField = null;
  }

  /** Returns true if field structField is set (has been assigned a value) and false otherwise */
  public boolean isSetStructField() {
    return this.structField != null;
  }

  public void setStructFieldIsSet(boolean value) {
    if (!value) {
      this.structField = null;
    }
  }

  public FooOrBar getFooOrBar() {
    return this.fooOrBar;
  }

  public void setFooOrBar(FooOrBar fooOrBar) {
    this.fooOrBar = fooOrBar;
  }

  public void unsetFooOrBar() {
    this.fooOrBar = null;
  }

  /** Returns true if field fooOrBar is set (has been assigned a value) and false otherwise */
  public boolean isSetFooOrBar() {
    return this.fooOrBar != null;
  }

  public void setFooOrBarIsSet(boolean value) {
    if (!value) {
      this.fooOrBar = null;
    }
  }

  public void setFieldValue(_Fields field, Object value) {
    switch (field) {
    case BOOL_FIELD:
      if (value == null) {
        unsetBoolField();
      } else {
        setBoolField((Boolean)value);
      }
      break;

    case BYTE_FIELD:
      if (value == null) {
        unsetByteField();
      } else {
        setByteField((Byte)value);
      }
      break;

    case I16_FIELD:
      if (value == null) {
        unsetI16Field();
      } else {
        setI16Field((Short)value);
      }
      break;

    case I16_OPTIONAL_FIELD:
      if (value == null) {
        unsetI16OptionalField();
      } else {
        setI16OptionalField((Short)value);
      }
      break;

    case I32_FIELD:
      if (value == null) {
        unsetI32Field();
      } else {
        setI32Field((Integer)value);
      }
      break;

    case I64_FIELD:
      if (value == null) {
        unsetI64Field();
      } else {
        setI64Field((Long)value);
      }
      break;

    case DOUBLE_FIELD:
      if (value == null) {
        unsetDoubleField();
      } else {
        setDoubleField((Double)value);
      }
      break;

    case STRING_FIELD:
      if (value == null) {
        unsetStringField();
      } else {
        setStringField((String)value);
      }
      break;

    case BINARY_FIELD:
      if (value == null) {
        unsetBinaryField();
      } else {
        setBinaryField((ByteBuffer)value);
      }
      break;

    case MAP_FIELD:
      if (value == null) {
        unsetMapField();
      } else {
        setMapField((Map<String,Integer>)value);
      }
      break;

    case LIST_FIELD:
      if (value == null) {
        unsetListField();
      } else {
        setListField((List<Integer>)value);
      }
      break;

    case SET_FIELD:
      if (value == null) {
        unsetSetField();
      } else {
        setSetField((Set<Integer>)value);
      }
      break;

    case ENUM_FIELD:
      if (value == null) {
        unsetEnumField();
      } else {
        setEnumField((E)value);
      }
      break;

    case STRUCT_FIELD:
      if (value == null) {
        unsetStructField();
      } else {
        setStructField((Nested)value);
      }
      break;

    case FOO_OR_BAR:
      if (value == null) {
        unsetFooOrBar();
      } else {
        setFooOrBar((FooOrBar)value);
      }
      break;

    }
  }

  public Object getFieldValue(_Fields field) {
    switch (field) {
    case BOOL_FIELD:
      return Boolean.valueOf(isBoolField());

    case BYTE_FIELD:
      return Byte.valueOf(getByteField());

    case I16_FIELD:
      return Short.valueOf(getI16Field());

    case I16_OPTIONAL_FIELD:
      return Short.valueOf(getI16OptionalField());

    case I32_FIELD:
      return Integer.valueOf(getI32Field());

    case I64_FIELD:
      return Long.valueOf(getI64Field());

    case DOUBLE_FIELD:
      return Double.valueOf(getDoubleField());

    case STRING_FIELD:
      return getStringField();

    case BINARY_FIELD:
      return getBinaryField();

    case MAP_FIELD:
      return getMapField();

    case LIST_FIELD:
      return getListField();

    case SET_FIELD:
      return getSetField();

    case ENUM_FIELD:
      return getEnumField();

    case STRUCT_FIELD:
      return getStructField();

    case FOO_OR_BAR:
      return getFooOrBar();

    }
    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 BOOL_FIELD:
      return isSetBoolField();
    case BYTE_FIELD:
      return isSetByteField();
    case I16_FIELD:
      return isSetI16Field();
    case I16_OPTIONAL_FIELD:
      return isSetI16OptionalField();
    case I32_FIELD:
      return isSetI32Field();
    case I64_FIELD:
      return isSetI64Field();
    case DOUBLE_FIELD:
      return isSetDoubleField();
    case STRING_FIELD:
      return isSetStringField();
    case BINARY_FIELD:
      return isSetBinaryField();
    case MAP_FIELD:
      return isSetMapField();
    case LIST_FIELD:
      return isSetListField();
    case SET_FIELD:
      return isSetSetField();
    case ENUM_FIELD:
      return isSetEnumField();
    case STRUCT_FIELD:
      return isSetStructField();
    case FOO_OR_BAR:
      return isSetFooOrBar();
    }
    throw new IllegalStateException();
  }

  @Override
  public boolean equals(Object that) {
    if (that == null)
      return false;
    if (that instanceof Test)
      return this.equals((Test)that);
    return false;
  }

  public boolean equals(Test that) {
    if (that == null)
      return false;

    boolean this_present_boolField = true;
    boolean that_present_boolField = true;
    if (this_present_boolField || that_present_boolField) {
      if (!(this_present_boolField && that_present_boolField))
        return false;
      if (this.boolField != that.boolField)
        return false;
    }

    boolean this_present_byteField = true;
    boolean that_present_byteField = true;
    if (this_present_byteField || that_present_byteField) {
      if (!(this_present_byteField && that_present_byteField))
        return false;
      if (this.byteField != that.byteField)
        return false;
    }

    boolean this_present_i16Field = true;
    boolean that_present_i16Field = true;
    if (this_present_i16Field || that_present_i16Field) {
      if (!(this_present_i16Field && that_present_i16Field))
        return false;
      if (this.i16Field != that.i16Field)
        return false;
    }

    boolean this_present_i16OptionalField = true && this.isSetI16OptionalField();
    boolean that_present_i16OptionalField = true && that.isSetI16OptionalField();
    if (this_present_i16OptionalField || that_present_i16OptionalField) {
      if (!(this_present_i16OptionalField && that_present_i16OptionalField))
        return false;
      if (this.i16OptionalField != that.i16OptionalField)
        return false;
    }

    boolean this_present_i32Field = true && this.isSetI32Field();
    boolean that_present_i32Field = true && that.isSetI32Field();
    if (this_present_i32Field || that_present_i32Field) {
      if (!(this_present_i32Field && that_present_i32Field))
        return false;
      if (this.i32Field != that.i32Field)
        return false;
    }

    boolean this_present_i64Field = true;
    boolean that_present_i64Field = true;
    if (this_present_i64Field || that_present_i64Field) {
      if (!(this_present_i64Field && that_present_i64Field))
        return false;
      if (this.i64Field != that.i64Field)
        return false;
    }

    boolean this_present_doubleField = true;
    boolean that_present_doubleField = true;
    if (this_present_doubleField || that_present_doubleField) {
      if (!(this_present_doubleField && that_present_doubleField))
        return false;
      if (this.doubleField != that.doubleField)
        return false;
    }

    boolean this_present_stringField = true && this.isSetStringField();
    boolean that_present_stringField = true && that.isSetStringField();
    if (this_present_stringField || that_present_stringField) {
      if (!(this_present_stringField && that_present_stringField))
        return false;
      if (!this.stringField.equals(that.stringField))
        return false;
    }

    boolean this_present_binaryField = true && this.isSetBinaryField();
    boolean that_present_binaryField = true && that.isSetBinaryField();
    if (this_present_binaryField || that_present_binaryField) {
      if (!(this_present_binaryField && that_present_binaryField))
        return false;
      if (!this.binaryField.equals(that.binaryField))
        return false;
    }

    boolean this_present_mapField = true && this.isSetMapField();
    boolean that_present_mapField = true && that.isSetMapField();
    if (this_present_mapField || that_present_mapField) {
      if (!(this_present_mapField && that_present_mapField))
        return false;
      if (!this.mapField.equals(that.mapField))
        return false;
    }

    boolean this_present_listField = true && this.isSetListField();
    boolean that_present_listField = true && that.isSetListField();
    if (this_present_listField || that_present_listField) {
      if (!(this_present_listField && that_present_listField))
        return false;
      if (!this.listField.equals(that.listField))
        return false;
    }

    boolean this_present_setField = true && this.isSetSetField();
    boolean that_present_setField = true && that.isSetSetField();
    if (this_present_setField || that_present_setField) {
      if (!(this_present_setField && that_present_setField))
        return false;
      if (!this.setField.equals(that.setField))
        return false;
    }

    boolean this_present_enumField = true && this.isSetEnumField();
    boolean that_present_enumField = true && that.isSetEnumField();
    if (this_present_enumField || that_present_enumField) {
      if (!(this_present_enumField && that_present_enumField))
        return false;
      if (!this.enumField.equals(that.enumField))
        return false;
    }

    boolean this_present_structField = true && this.isSetStructField();
    boolean that_present_structField = true && that.isSetStructField();
    if (this_present_structField || that_present_structField) {
      if (!(this_present_structField && that_present_structField))
        return false;
      if (!this.structField.equals(that.structField))
        return false;
    }

    boolean this_present_fooOrBar = true && this.isSetFooOrBar();
    boolean that_present_fooOrBar = true && that.isSetFooOrBar();
    if (this_present_fooOrBar || that_present_fooOrBar) {
      if (!(this_present_fooOrBar && that_present_fooOrBar))
        return false;
      if (!this.fooOrBar.equals(that.fooOrBar))
        return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    return 0;
  }

  public int compareTo(Test other) {
    if (!getClass().equals(other.getClass())) {
      return getClass().getName().compareTo(other.getClass().getName());
    }

    int lastComparison = 0;
    Test typedOther = (Test)other;

    lastComparison = Boolean.valueOf(isSetBoolField()).compareTo(typedOther.isSetBoolField());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetBoolField()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.boolField, typedOther.boolField);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetByteField()).compareTo(typedOther.isSetByteField());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetByteField()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.byteField, typedOther.byteField);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetI16Field()).compareTo(typedOther.isSetI16Field());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetI16Field()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.i16Field, typedOther.i16Field);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetI16OptionalField()).compareTo(typedOther.isSetI16OptionalField());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetI16OptionalField()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.i16OptionalField, typedOther.i16OptionalField);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetI32Field()).compareTo(typedOther.isSetI32Field());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetI32Field()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.i32Field, typedOther.i32Field);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetI64Field()).compareTo(typedOther.isSetI64Field());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetI64Field()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.i64Field, typedOther.i64Field);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetDoubleField()).compareTo(typedOther.isSetDoubleField());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetDoubleField()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.doubleField, typedOther.doubleField);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetStringField()).compareTo(typedOther.isSetStringField());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetStringField()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.stringField, typedOther.stringField);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetBinaryField()).compareTo(typedOther.isSetBinaryField());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetBinaryField()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.binaryField, typedOther.binaryField);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetMapField()).compareTo(typedOther.isSetMapField());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetMapField()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.mapField, typedOther.mapField);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetListField()).compareTo(typedOther.isSetListField());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetListField()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.listField, typedOther.listField);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetSetField()).compareTo(typedOther.isSetSetField());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetSetField()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.setField, typedOther.setField);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetEnumField()).compareTo(typedOther.isSetEnumField());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetEnumField()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.enumField, typedOther.enumField);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetStructField()).compareTo(typedOther.isSetStructField());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetStructField()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.structField, typedOther.structField);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetFooOrBar()).compareTo(typedOther.isSetFooOrBar());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetFooOrBar()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.fooOrBar, typedOther.fooOrBar);
      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: // BOOL_FIELD
          if (field.type == org.apache.thrift.protocol.TType.BOOL) {
            this.boolField = iprot.readBool();
            setBoolFieldIsSet(true);
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 2: // BYTE_FIELD
          if (field.type == org.apache.thrift.protocol.TType.BYTE) {
            this.byteField = iprot.readByte();
            setByteFieldIsSet(true);
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 3: // I16_FIELD
          if (field.type == org.apache.thrift.protocol.TType.I16) {
            this.i16Field = iprot.readI16();
            setI16FieldIsSet(true);
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 15: // I16_OPTIONAL_FIELD
          if (field.type == org.apache.thrift.protocol.TType.I16) {
            this.i16OptionalField = iprot.readI16();
            setI16OptionalFieldIsSet(true);
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 4: // I32_FIELD
          if (field.type == org.apache.thrift.protocol.TType.I32) {
            this.i32Field = iprot.readI32();
            setI32FieldIsSet(true);
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 5: // I64_FIELD
          if (field.type == org.apache.thrift.protocol.TType.I64) {
            this.i64Field = iprot.readI64();
            setI64FieldIsSet(true);
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 6: // DOUBLE_FIELD
          if (field.type == org.apache.thrift.protocol.TType.DOUBLE) {
            this.doubleField = iprot.readDouble();
            setDoubleFieldIsSet(true);
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 7: // STRING_FIELD
          if (field.type == org.apache.thrift.protocol.TType.STRING) {
            this.stringField = iprot.readString();
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 8: // BINARY_FIELD
          if (field.type == org.apache.thrift.protocol.TType.STRING) {
            this.binaryField = iprot.readBinary();
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 9: // MAP_FIELD
          if (field.type == org.apache.thrift.protocol.TType.MAP) {
            {
              org.apache.thrift.protocol.TMap _map0 = iprot.readMapBegin();
              this.mapField = new HashMap<String,Integer>(2*_map0.size);
              for (int _i1 = 0; _i1 < _map0.size; ++_i1)
              {
                String _key2; // required
                int _val3; // required
                _key2 = iprot.readString();
                _val3 = iprot.readI32();
                this.mapField.put(_key2, _val3);
              }
              iprot.readMapEnd();
            }
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 10: // LIST_FIELD
          if (field.type == org.apache.thrift.protocol.TType.LIST) {
            {
              org.apache.thrift.protocol.TList _list4 = iprot.readListBegin();
              this.listField = new ArrayList<Integer>(_list4.size);
              for (int _i5 = 0; _i5 < _list4.size; ++_i5)
              {
                int _elem6; // required
                _elem6 = iprot.readI32();
                this.listField.add(_elem6);
              }
              iprot.readListEnd();
            }
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 11: // SET_FIELD
          if (field.type == org.apache.thrift.protocol.TType.SET) {
            {
              org.apache.thrift.protocol.TSet _set7 = iprot.readSetBegin();
              this.setField = new HashSet<Integer>(2*_set7.size);
              for (int _i8 = 0; _i8 < _set7.size; ++_i8)
              {
                int _elem9; // required
                _elem9 = iprot.readI32();
                this.setField.add(_elem9);
              }
              iprot.readSetEnd();
            }
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 12: // ENUM_FIELD
          if (field.type == org.apache.thrift.protocol.TType.I32) {
            this.enumField = E.findByValue(iprot.readI32());
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 13: // STRUCT_FIELD
          if (field.type == org.apache.thrift.protocol.TType.STRUCT) {
            this.structField = new Nested();
            this.structField.read(iprot);
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 14: // FOO_OR_BAR
          if (field.type == org.apache.thrift.protocol.TType.STRUCT) {
            this.fooOrBar = new FooOrBar();
            this.fooOrBar.read(iprot);
          } 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();
    validate();
  }

  public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
    validate();

    oprot.writeStructBegin(STRUCT_DESC);
    oprot.writeFieldBegin(BOOL_FIELD_FIELD_DESC);
    oprot.writeBool(this.boolField);
    oprot.writeFieldEnd();
    oprot.writeFieldBegin(BYTE_FIELD_FIELD_DESC);
    oprot.writeByte(this.byteField);
    oprot.writeFieldEnd();
    oprot.writeFieldBegin(I16_FIELD_FIELD_DESC);
    oprot.writeI16(this.i16Field);
    oprot.writeFieldEnd();
    if (isSetI32Field()) {
      oprot.writeFieldBegin(I32_FIELD_FIELD_DESC);
      oprot.writeI32(this.i32Field);
      oprot.writeFieldEnd();
    }
    oprot.writeFieldBegin(I64_FIELD_FIELD_DESC);
    oprot.writeI64(this.i64Field);
    oprot.writeFieldEnd();
    oprot.writeFieldBegin(DOUBLE_FIELD_FIELD_DESC);
    oprot.writeDouble(this.doubleField);
    oprot.writeFieldEnd();
    if (this.stringField != null) {
      oprot.writeFieldBegin(STRING_FIELD_FIELD_DESC);
      oprot.writeString(this.stringField);
      oprot.writeFieldEnd();
    }
    if (this.binaryField != null) {
      if (isSetBinaryField()) {
        oprot.writeFieldBegin(BINARY_FIELD_FIELD_DESC);
        oprot.writeBinary(this.binaryField);
        oprot.writeFieldEnd();
      }
    }
    if (this.mapField != null) {
      oprot.writeFieldBegin(MAP_FIELD_FIELD_DESC);
      {
        oprot.writeMapBegin(new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.I32, this.mapField.size()));
        for (Map.Entry<String, Integer> _iter10 : this.mapField.entrySet())
        {
          oprot.writeString(_iter10.getKey());
          oprot.writeI32(_iter10.getValue());
        }
        oprot.writeMapEnd();
      }
      oprot.writeFieldEnd();
    }
    if (this.listField != null) {
      oprot.writeFieldBegin(LIST_FIELD_FIELD_DESC);
      {
        oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.I32, this.listField.size()));
        for (int _iter11 : this.listField)
        {
          oprot.writeI32(_iter11);
        }
        oprot.writeListEnd();
      }
      oprot.writeFieldEnd();
    }
    if (this.setField != null) {
      oprot.writeFieldBegin(SET_FIELD_FIELD_DESC);
      {
        oprot.writeSetBegin(new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.I32, this.setField.size()));
        for (int _iter12 : this.setField)
        {
          oprot.writeI32(_iter12);
        }
        oprot.writeSetEnd();
      }
      oprot.writeFieldEnd();
    }
    if (this.enumField != null) {
      oprot.writeFieldBegin(ENUM_FIELD_FIELD_DESC);
      oprot.writeI32(this.enumField.getValue());
      oprot.writeFieldEnd();
    }
    if (this.structField != null) {
      oprot.writeFieldBegin(STRUCT_FIELD_FIELD_DESC);
      this.structField.write(oprot);
      oprot.writeFieldEnd();
    }
    if (this.fooOrBar != null) {
      oprot.writeFieldBegin(FOO_OR_BAR_FIELD_DESC);
      this.fooOrBar.write(oprot);
      oprot.writeFieldEnd();
    }
    if (isSetI16OptionalField()) {
      oprot.writeFieldBegin(I16_OPTIONAL_FIELD_FIELD_DESC);
      oprot.writeI16(this.i16OptionalField);
      oprot.writeFieldEnd();
    }
    oprot.writeFieldStop();
    oprot.writeStructEnd();
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder("Test(");
    boolean first = true;

    sb.append("boolField:");
    sb.append(this.boolField);
    first = false;
    if (!first) sb.append(", ");
    sb.append("byteField:");
    sb.append(this.byteField);
    first = false;
    if (!first) sb.append(", ");
    sb.append("i16Field:");
    sb.append(this.i16Field);
    first = false;
    if (isSetI16OptionalField()) {
      if (!first) sb.append(", ");
      sb.append("i16OptionalField:");
      sb.append(this.i16OptionalField);
      first = false;
    }
    if (isSetI32Field()) {
      if (!first) sb.append(", ");
      sb.append("i32Field:");
      sb.append(this.i32Field);
      first = false;
    }
    if (!first) sb.append(", ");
    sb.append("i64Field:");
    sb.append(this.i64Field);
    first = false;
    if (!first) sb.append(", ");
    sb.append("doubleField:");
    sb.append(this.doubleField);
    first = false;
    if (!first) sb.append(", ");
    sb.append("stringField:");
    if (this.stringField == null) {
      sb.append("null");
    } else {
      sb.append(this.stringField);
    }
    first = false;
    if (isSetBinaryField()) {
      if (!first) sb.append(", ");
      sb.append("binaryField:");
      if (this.binaryField == null) {
        sb.append("null");
      } else {
        org.apache.thrift.TBaseHelper.toString(this.binaryField, sb);
      }
      first = false;
    }
    if (!first) sb.append(", ");
    sb.append("mapField:");
    if (this.mapField == null) {
      sb.append("null");
    } else {
      sb.append(this.mapField);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("listField:");
    if (this.listField == null) {
      sb.append("null");
    } else {
      sb.append(this.listField);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("setField:");
    if (this.setField == null) {
      sb.append("null");
    } else {
      sb.append(this.setField);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("enumField:");
    if (this.enumField == null) {
      sb.append("null");
    } else {
      sb.append(this.enumField);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("structField:");
    if (this.structField == null) {
      sb.append("null");
    } else {
      sb.append(this.structField);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("fooOrBar:");
    if (this.fooOrBar == null) {
      sb.append("null");
    } else {
      sb.append(this.fooOrBar);
    }
    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);
    }
  }

  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);
    }
  }

}

