/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
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 AdaptedStructWithTerseInternBox implements TBase, java.io.Serializable, Cloneable, Comparable<AdaptedStructWithTerseInternBox> {
  private static final TStruct STRUCT_DESC = new TStruct("AdaptedStructWithTerseInternBox");
  private static final TField FIELD1_FIELD_DESC = new TField("field1", TType.STRUCT, (short)1);
  private static final TField FIELD2_FIELD_DESC = new TField("field2", TType.STRUCT, (short)2);

  public Empty field1;
  public MyField field2;
  public static final int FIELD1 = 1;
  public static final int FIELD2 = 2;

  // isset id assignments

  public static final Map<Integer, FieldMetaData> metaDataMap;

  static {
    Map<Integer, FieldMetaData> tmpMetaDataMap = new HashMap<Integer, FieldMetaData>();
    tmpMetaDataMap.put(FIELD1, new FieldMetaData("field1", TFieldRequirementType.DEFAULT, 
        new StructMetaData(TType.STRUCT, Empty.class)));
    tmpMetaDataMap.put(FIELD2, new FieldMetaData("field2", TFieldRequirementType.DEFAULT, 
        new StructMetaData(TType.STRUCT, MyField.class)));
    metaDataMap = Collections.unmodifiableMap(tmpMetaDataMap);
  }

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

  public AdaptedStructWithTerseInternBox() {
  }

  public AdaptedStructWithTerseInternBox(
      Empty field1,
      MyField field2) {
    this();
    this.field1 = field1;
    this.field2 = field2;
  }

  public static class Builder {
    private Empty field1;
    private MyField field2;

    public Builder() {
    }

    public Builder setField1(final Empty field1) {
      this.field1 = field1;
      return this;
    }

    public Builder setField2(final MyField field2) {
      this.field2 = field2;
      return this;
    }

    public AdaptedStructWithTerseInternBox build() {
      AdaptedStructWithTerseInternBox result = new AdaptedStructWithTerseInternBox();
      result.setField1(this.field1);
      result.setField2(this.field2);
      return result;
    }
  }

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

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public AdaptedStructWithTerseInternBox(AdaptedStructWithTerseInternBox other) {
    if (other.isSetField1()) {
      this.field1 = TBaseHelper.deepCopy(other.field1);
    }
    if (other.isSetField2()) {
      this.field2 = TBaseHelper.deepCopy(other.field2);
    }
  }

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

  public Empty getField1() {
    return this.field1;
  }

  public AdaptedStructWithTerseInternBox setField1(Empty field1) {
    this.field1 = field1;
    return this;
  }

  public void unsetField1() {
    this.field1 = null;
  }

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

  public void setField1IsSet(boolean __value) {
    if (!__value) {
      this.field1 = null;
    }
  }

  public MyField getField2() {
    return this.field2;
  }

  public AdaptedStructWithTerseInternBox setField2(MyField field2) {
    this.field2 = field2;
    return this;
  }

  public void unsetField2() {
    this.field2 = null;
  }

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

  public void setField2IsSet(boolean __value) {
    if (!__value) {
      this.field2 = null;
    }
  }

  public void setFieldValue(int fieldID, Object __value) {
    switch (fieldID) {
    case FIELD1:
      if (__value == null) {
        unsetField1();
      } else {
        setField1((Empty)__value);
      }
      break;

    case FIELD2:
      if (__value == null) {
        unsetField2();
      } else {
        setField2((MyField)__value);
      }
      break;

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

  public Object getFieldValue(int fieldID) {
    switch (fieldID) {
    case FIELD1:
      return getField1();

    case FIELD2:
      return getField2();

    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 AdaptedStructWithTerseInternBox))
      return false;
    AdaptedStructWithTerseInternBox that = (AdaptedStructWithTerseInternBox)_that;

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

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

    return true;
  }

  @Override
  public int hashCode() {
    return Arrays.deepHashCode(new Object[] {field1, field2});
  }

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

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

    lastComparison = Boolean.valueOf(isSetField1()).compareTo(other.isSetField1());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(field1, other.field1);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetField2()).compareTo(other.isSetField2());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(field2, other.field2);
    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 FIELD1:
          if (__field.type == TType.STRUCT) {
            this.field1 = new Empty();
            this.field1.read(iprot);
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case FIELD2:
          if (__field.type == TType.STRUCT) {
            this.field2 = new MyField();
            this.field2.read(iprot);
          } 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);
    if (this.field1 != null) {
      oprot.writeFieldBegin(FIELD1_FIELD_DESC);
      this.field1.write(oprot);
      oprot.writeFieldEnd();
    }
    if (this.field2 != null) {
      oprot.writeFieldBegin(FIELD2_FIELD_DESC);
      this.field2.write(oprot);
      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("AdaptedStructWithTerseInternBox");
    sb.append(space);
    sb.append("(");
    sb.append(newLine);
    boolean first = true;

    sb.append(indentStr);
    sb.append("field1");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getField1() == null) {
      sb.append("null");
    } else {
      sb.append(TBaseHelper.toString(this.getField1(), indent + 1, prettyPrint));
    }
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("field2");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getField2() == null) {
      sb.append("null");
    } else {
      sb.append(TBaseHelper.toString(this.getField2(), 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
  }

}

