/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package test.fixtures.adapter;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.Collections;
import java.util.BitSet;
import java.util.Arrays;
import com.facebook.thrift.*;
import com.facebook.thrift.annotations.*;
import com.facebook.thrift.async.*;
import com.facebook.thrift.meta_data.*;
import com.facebook.thrift.server.*;
import com.facebook.thrift.transport.*;
import com.facebook.thrift.protocol.*;

@SuppressWarnings({ "unused", "serial" })
public class TerseAdaptedFields implements TBase, java.io.Serializable, Cloneable, Comparable<TerseAdaptedFields> {
  private static final TStruct STRUCT_DESC = new TStruct("TerseAdaptedFields");
  private static final TField INT_FIELD_FIELD_DESC = new TField("int_field", TType.I32, (short)1);
  private static final TField STRING_FIELD_FIELD_DESC = new TField("string_field", TType.STRING, (short)2);
  private static final TField SET_FIELD_FIELD_DESC = new TField("set_field", TType.SET, (short)3);

  public int int_field;
  public String string_field;
  public Set<Integer> set_field;
  public static final int INT_FIELD = 1;
  public static final int STRING_FIELD = 2;
  public static final int SET_FIELD = 3;

  // isset id assignments
  private static final int __INT_FIELD_ISSET_ID = 0;
  private BitSet __isset_bit_vector = new BitSet(1);

  public static final Map<Integer, FieldMetaData> metaDataMap;

  static {
    Map<Integer, FieldMetaData> tmpMetaDataMap = new HashMap<Integer, FieldMetaData>();
    tmpMetaDataMap.put(INT_FIELD, new FieldMetaData("int_field", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.I32)));
    tmpMetaDataMap.put(STRING_FIELD, new FieldMetaData("string_field", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.STRING)));
    tmpMetaDataMap.put(SET_FIELD, new FieldMetaData("set_field", TFieldRequirementType.DEFAULT, 
        new SetMetaData(TType.SET, 
            new FieldValueMetaData(TType.I32))));
    metaDataMap = Collections.unmodifiableMap(tmpMetaDataMap);
  }

  static {
    FieldMetaData.addStructMetaDataMap(TerseAdaptedFields.class, metaDataMap);
  }

  public TerseAdaptedFields() {
  }

  public TerseAdaptedFields(
      int int_field,
      String string_field,
      Set<Integer> set_field) {
    this();
    this.int_field = int_field;
    setInt_fieldIsSet(true);
    this.string_field = string_field;
    this.set_field = set_field;
  }

  public static class Builder {
    private int int_field;
    private String string_field;
    private Set<Integer> set_field;

    BitSet __optional_isset = new BitSet(1);

    public Builder() {
    }

    public Builder setInt_field(final int int_field) {
      this.int_field = int_field;
      __optional_isset.set(__INT_FIELD_ISSET_ID, true);
      return this;
    }

    public Builder setString_field(final String string_field) {
      this.string_field = string_field;
      return this;
    }

    public Builder setSet_field(final Set<Integer> set_field) {
      this.set_field = set_field;
      return this;
    }

    public TerseAdaptedFields build() {
      TerseAdaptedFields result = new TerseAdaptedFields();
      if (__optional_isset.get(__INT_FIELD_ISSET_ID)) {
        result.setInt_field(this.int_field);
      }
      result.setString_field(this.string_field);
      result.setSet_field(this.set_field);
      return result;
    }
  }

  public static Builder builder() {
    return new Builder();
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public TerseAdaptedFields(TerseAdaptedFields other) {
    __isset_bit_vector.clear();
    __isset_bit_vector.or(other.__isset_bit_vector);
    this.int_field = TBaseHelper.deepCopy(other.int_field);
    if (other.isSetString_field()) {
      this.string_field = TBaseHelper.deepCopy(other.string_field);
    }
    if (other.isSetSet_field()) {
      this.set_field = TBaseHelper.deepCopy(other.set_field);
    }
  }

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

  public int getInt_field() {
    return this.int_field;
  }

  public TerseAdaptedFields setInt_field(int int_field) {
    this.int_field = int_field;
    setInt_fieldIsSet(true);
    return this;
  }

  public void unsetInt_field() {
    __isset_bit_vector.clear(__INT_FIELD_ISSET_ID);
  }

  // Returns true if field int_field is set (has been assigned a value) and false otherwise
  public boolean isSetInt_field() {
    return __isset_bit_vector.get(__INT_FIELD_ISSET_ID);
  }

  public void setInt_fieldIsSet(boolean __value) {
    __isset_bit_vector.set(__INT_FIELD_ISSET_ID, __value);
  }

  public String getString_field() {
    return this.string_field;
  }

  public TerseAdaptedFields setString_field(String string_field) {
    this.string_field = string_field;
    return this;
  }

  public void unsetString_field() {
    this.string_field = null;
  }

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

  public void setString_fieldIsSet(boolean __value) {
    if (!__value) {
      this.string_field = null;
    }
  }

  public Set<Integer> getSet_field() {
    return this.set_field;
  }

  public TerseAdaptedFields setSet_field(Set<Integer> set_field) {
    this.set_field = set_field;
    return this;
  }

  public void unsetSet_field() {
    this.set_field = null;
  }

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

  public void setSet_fieldIsSet(boolean __value) {
    if (!__value) {
      this.set_field = null;
    }
  }

  @SuppressWarnings("unchecked")
  public void setFieldValue(int fieldID, Object __value) {
    switch (fieldID) {
    case INT_FIELD:
      if (__value == null) {
        unsetInt_field();
      } else {
        setInt_field((Integer)__value);
      }
      break;

    case STRING_FIELD:
      if (__value == null) {
        unsetString_field();
      } else {
        setString_field((String)__value);
      }
      break;

    case SET_FIELD:
      if (__value == null) {
        unsetSet_field();
      } else {
        setSet_field((Set<Integer>)__value);
      }
      break;

    default:
      throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!");
    }
  }

  public Object getFieldValue(int fieldID) {
    switch (fieldID) {
    case INT_FIELD:
      return new Integer(getInt_field());

    case STRING_FIELD:
      return getString_field();

    case SET_FIELD:
      return getSet_field();

    default:
      throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!");
    }
  }

  @Override
  public boolean equals(Object _that) {
    if (_that == null)
      return false;
    if (this == _that)
      return true;
    if (!(_that instanceof TerseAdaptedFields))
      return false;
    TerseAdaptedFields that = (TerseAdaptedFields)_that;

    if (!TBaseHelper.equalsNobinary(this.int_field, that.int_field)) { return false; }

    if (!TBaseHelper.equalsNobinary(this.isSetString_field(), that.isSetString_field(), this.string_field, that.string_field)) { return false; }

    if (!TBaseHelper.equalsNobinary(this.isSetSet_field(), that.isSetSet_field(), this.set_field, that.set_field)) { return false; }

    return true;
  }

  @Override
  public int hashCode() {
    return Arrays.deepHashCode(new Object[] {int_field, string_field, set_field});
  }

  @Override
  public int compareTo(TerseAdaptedFields other) {
    if (other == null) {
      // See java.lang.Comparable docs
      throw new NullPointerException();
    }

    if (other == this) {
      return 0;
    }
    int lastComparison = 0;

    lastComparison = Boolean.valueOf(isSetInt_field()).compareTo(other.isSetInt_field());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(int_field, other.int_field);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetString_field()).compareTo(other.isSetString_field());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(string_field, other.string_field);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetSet_field()).compareTo(other.isSetSet_field());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(set_field, other.set_field);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    return 0;
  }

  public void read(TProtocol iprot) throws TException {
    TField __field;
    iprot.readStructBegin(metaDataMap);
    while (true)
    {
      __field = iprot.readFieldBegin();
      if (__field.type == TType.STOP) {
        break;
      }
      switch (__field.id)
      {
        case INT_FIELD:
          if (__field.type == TType.I32) {
            this.int_field = iprot.readI32();
            setInt_fieldIsSet(true);
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case STRING_FIELD:
          if (__field.type == TType.STRING) {
            this.string_field = iprot.readString();
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case SET_FIELD:
          if (__field.type == TType.SET) {
            {
              TSet _set50 = iprot.readSetBegin();
              this.set_field = new HashSet<Integer>(Math.max(0, 2*_set50.size));
              for (int _i51 = 0; 
                   (_set50.size < 0) ? iprot.peekSet() : (_i51 < _set50.size); 
                   ++_i51)
              {
                int _elem52;
                _elem52 = iprot.readI32();
                this.set_field.add(_elem52);
              }
              iprot.readSetEnd();
            }
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        default:
          TProtocolUtil.skip(iprot, __field.type);
          break;
      }
      iprot.readFieldEnd();
    }
    iprot.readStructEnd();


    // check for required fields of primitive type, which can't be checked in the validate method
    validate();
  }

  public void write(TProtocol oprot) throws TException {
    validate();

    oprot.writeStructBegin(STRUCT_DESC);
    oprot.writeFieldBegin(INT_FIELD_FIELD_DESC);
    oprot.writeI32(this.int_field);
    oprot.writeFieldEnd();
    if (this.string_field != null) {
      oprot.writeFieldBegin(STRING_FIELD_FIELD_DESC);
      oprot.writeString(this.string_field);
      oprot.writeFieldEnd();
    }
    if (this.set_field != null) {
      oprot.writeFieldBegin(SET_FIELD_FIELD_DESC);
      {
        oprot.writeSetBegin(new TSet(TType.I32, this.set_field.size()));
        for (int _iter53 : this.set_field)        {
          oprot.writeI32(_iter53);
        }
        oprot.writeSetEnd();
      }
      oprot.writeFieldEnd();
    }
    oprot.writeFieldStop();
    oprot.writeStructEnd();
  }

  @Override
  public String toString() {
    return toString(1, true);
  }

  @Override
  public String toString(int indent, boolean prettyPrint) {
    String indentStr = prettyPrint ? TBaseHelper.getIndentedString(indent) : "";
    String newLine = prettyPrint ? "\n" : "";
    String space = prettyPrint ? " " : "";
    StringBuilder sb = new StringBuilder("TerseAdaptedFields");
    sb.append(space);
    sb.append("(");
    sb.append(newLine);
    boolean first = true;

    sb.append(indentStr);
    sb.append("int_field");
    sb.append(space);
    sb.append(":").append(space);
    sb.append(TBaseHelper.toString(this.getInt_field(), indent + 1, prettyPrint));
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("string_field");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getString_field() == null) {
      sb.append("null");
    } else {
      sb.append(TBaseHelper.toString(this.getString_field(), indent + 1, prettyPrint));
    }
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("set_field");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getSet_field() == null) {
      sb.append("null");
    } else {
      sb.append(TBaseHelper.toString(this.getSet_field(), indent + 1, prettyPrint));
    }
    first = false;
    sb.append(newLine + TBaseHelper.reduceIndent(indentStr));
    sb.append(")");
    return sb.toString();
  }

  public void validate() throws TException {
    // check for required fields
  }

}

