/**
 * 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 StructWithFieldAdapter implements TBase, java.io.Serializable, Cloneable {
  private static final TStruct STRUCT_DESC = new TStruct("StructWithFieldAdapter");
  private static final TField FIELD_FIELD_DESC = new TField("field", TType.I32, (short)1);
  private static final TField SHARED_FIELD_FIELD_DESC = new TField("shared_field", TType.I32, (short)2);
  private static final TField OPT_SHARED_FIELD_FIELD_DESC = new TField("opt_shared_field", TType.I32, (short)3);
  private static final TField OPT_BOXED_FIELD_FIELD_DESC = new TField("opt_boxed_field", TType.I32, (short)4);

  public final Integer field;
  public final Integer shared_field;
  public final Integer opt_shared_field;
  public final Integer opt_boxed_field;
  public static final int FIELD = 1;
  public static final int SHARED_FIELD = 2;
  public static final int OPT_SHARED_FIELD = 3;
  public static final int OPT_BOXED_FIELD = 4;

  public StructWithFieldAdapter(
      Integer field,
      Integer shared_field,
      Integer opt_shared_field,
      Integer opt_boxed_field) {
    this.field = field;
    this.shared_field = shared_field;
    this.opt_shared_field = opt_shared_field;
    this.opt_boxed_field = opt_boxed_field;
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public StructWithFieldAdapter(StructWithFieldAdapter other) {
    if (other.isSetField()) {
      this.field = TBaseHelper.deepCopy(other.field);
    } else {
      this.field = null;
    }
    if (other.isSetShared_field()) {
      this.shared_field = TBaseHelper.deepCopy(other.shared_field);
    } else {
      this.shared_field = null;
    }
    if (other.isSetOpt_shared_field()) {
      this.opt_shared_field = TBaseHelper.deepCopy(other.opt_shared_field);
    } else {
      this.opt_shared_field = null;
    }
    if (other.isSetOpt_boxed_field()) {
      this.opt_boxed_field = TBaseHelper.deepCopy(other.opt_boxed_field);
    } else {
      this.opt_boxed_field = null;
    }
  }

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

  public Integer getField() {
    return this.field;
  }

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

  public Integer getShared_field() {
    return this.shared_field;
  }

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

  public Integer getOpt_shared_field() {
    return this.opt_shared_field;
  }

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

  public Integer getOpt_boxed_field() {
    return this.opt_boxed_field;
  }

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

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

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

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

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

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

    return true;
  }

  @Override
  public int hashCode() {
    return Arrays.deepHashCode(new Object[] {field, shared_field, opt_shared_field, opt_boxed_field});
  }

  // This is required to satisfy the TBase interface, but can't be implemented on immutable struture.
  public void read(TProtocol iprot) throws TException {
    throw new TException("unimplemented in android immutable structure");
  }

  public static StructWithFieldAdapter deserialize(TProtocol iprot) throws TException {
    Integer tmp_field = null;
    Integer tmp_shared_field = null;
    Integer tmp_opt_shared_field = null;
    Integer tmp_opt_boxed_field = null;
    TField __field;
    iprot.readStructBegin();
    while (true)
    {
      __field = iprot.readFieldBegin();
      if (__field.type == TType.STOP) {
        break;
      }
      switch (__field.id)
      {
        case FIELD:
          if (__field.type == TType.I32) {
            tmp_field = iprot.readI32();
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case SHARED_FIELD:
          if (__field.type == TType.I32) {
            tmp_shared_field = iprot.readI32();
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case OPT_SHARED_FIELD:
          if (__field.type == TType.I32) {
            tmp_opt_shared_field = iprot.readI32();
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case OPT_BOXED_FIELD:
          if (__field.type == TType.I32) {
            tmp_opt_boxed_field = iprot.readI32();
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        default:
          TProtocolUtil.skip(iprot, __field.type);
          break;
      }
      iprot.readFieldEnd();
    }
    iprot.readStructEnd();

    StructWithFieldAdapter _that;
    _that = new StructWithFieldAdapter(
      tmp_field
      ,tmp_shared_field
      ,tmp_opt_shared_field
      ,tmp_opt_boxed_field
    );
    _that.validate();
    return _that;
  }

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

    oprot.writeStructBegin(STRUCT_DESC);
    if (this.field != null) {
      oprot.writeFieldBegin(FIELD_FIELD_DESC);
      oprot.writeI32(this.field);
      oprot.writeFieldEnd();
    }
    if (this.shared_field != null) {
      oprot.writeFieldBegin(SHARED_FIELD_FIELD_DESC);
      oprot.writeI32(this.shared_field);
      oprot.writeFieldEnd();
    }
    if (this.opt_shared_field != null) {
      if (isSetOpt_shared_field()) {
        oprot.writeFieldBegin(OPT_SHARED_FIELD_FIELD_DESC);
        oprot.writeI32(this.opt_shared_field);
        oprot.writeFieldEnd();
      }
    }
    if (this.opt_boxed_field != null) {
      if (isSetOpt_boxed_field()) {
        oprot.writeFieldBegin(OPT_BOXED_FIELD_FIELD_DESC);
        oprot.writeI32(this.opt_boxed_field);
        oprot.writeFieldEnd();
      }
    }
    oprot.writeFieldStop();
    oprot.writeStructEnd();
  }

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

  @Override
  public String toString(int indent, boolean prettyPrint) {
    return TBaseHelper.toStringHelper(this, indent, prettyPrint);
  }

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

}

