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

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 MyStruct implements TBase, java.io.Serializable, Cloneable, Comparable<MyStruct> {
  private static final TStruct STRUCT_DESC = new TStruct("MyStruct");
  private static final TField ME2_3_FIELD_DESC = new TField("me2_3", TType.I32, (short)1);
  private static final TField ME3_N3_FIELD_DESC = new TField("me3_n3", TType.I32, (short)2);
  private static final TField ME1_T1_FIELD_DESC = new TField("me1_t1", TType.I32, (short)4);
  private static final TField ME1_T2_FIELD_DESC = new TField("me1_t2", TType.I32, (short)6);

  /**
   * 
   * @see MyEnum2
   */
  public MyEnum2 me2_3;
  /**
   * 
   * @see MyEnum3
   */
  public MyEnum3 me3_n3;
  /**
   * 
   * @see MyEnum1
   */
  public MyEnum1 me1_t1;
  /**
   * 
   * @see MyEnum1
   */
  public MyEnum1 me1_t2;
  public static final int ME2_3 = 1;
  public static final int ME3_N3 = 2;
  public static final int ME1_T1 = 4;
  public static final int ME1_T2 = 6;

  // isset id assignments

  public static final Map<Integer, FieldMetaData> metaDataMap;

  static {
    Map<Integer, FieldMetaData> tmpMetaDataMap = new HashMap<Integer, FieldMetaData>();
    tmpMetaDataMap.put(ME2_3, new FieldMetaData("me2_3", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.I32)));
    tmpMetaDataMap.put(ME3_N3, new FieldMetaData("me3_n3", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.I32)));
    tmpMetaDataMap.put(ME1_T1, new FieldMetaData("me1_t1", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.I32)));
    tmpMetaDataMap.put(ME1_T2, new FieldMetaData("me1_t2", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.I32)));
    metaDataMap = Collections.unmodifiableMap(tmpMetaDataMap);
  }

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

  public MyStruct() {
    this.me2_3 = test.fixtures.enums.MyEnum2.findByValue(3);

    this.me3_n3 = test.fixtures.enums.MyEnum3.findByValue(-3);

    this.me1_t1 = test.fixtures.enums.MyEnum1.ME1_1;

    this.me1_t2 = test.fixtures.enums.MyEnum1.ME1_1;

  }

  public MyStruct(
      MyEnum2 me2_3,
      MyEnum3 me3_n3,
      MyEnum1 me1_t1,
      MyEnum1 me1_t2) {
    this();
    this.me2_3 = me2_3;
    this.me3_n3 = me3_n3;
    this.me1_t1 = me1_t1;
    this.me1_t2 = me1_t2;
  }

  public static class Builder {
    private MyEnum2 me2_3;
    private MyEnum3 me3_n3;
    private MyEnum1 me1_t1;
    private MyEnum1 me1_t2;

    public Builder() {
    }

    public Builder setMe2_3(final MyEnum2 me2_3) {
      this.me2_3 = me2_3;
      return this;
    }

    public Builder setMe3_n3(final MyEnum3 me3_n3) {
      this.me3_n3 = me3_n3;
      return this;
    }

    public Builder setMe1_t1(final MyEnum1 me1_t1) {
      this.me1_t1 = me1_t1;
      return this;
    }

    public Builder setMe1_t2(final MyEnum1 me1_t2) {
      this.me1_t2 = me1_t2;
      return this;
    }

    public MyStruct build() {
      MyStruct result = new MyStruct();
      result.setMe2_3(this.me2_3);
      result.setMe3_n3(this.me3_n3);
      result.setMe1_t1(this.me1_t1);
      result.setMe1_t2(this.me1_t2);
      return result;
    }
  }

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

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public MyStruct(MyStruct other) {
    if (other.isSetMe2_3()) {
      this.me2_3 = TBaseHelper.deepCopy(other.me2_3);
    }
    if (other.isSetMe3_n3()) {
      this.me3_n3 = TBaseHelper.deepCopy(other.me3_n3);
    }
    if (other.isSetMe1_t1()) {
      this.me1_t1 = TBaseHelper.deepCopy(other.me1_t1);
    }
    if (other.isSetMe1_t2()) {
      this.me1_t2 = TBaseHelper.deepCopy(other.me1_t2);
    }
  }

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

  /**
   * 
   * @see MyEnum2
   */
  public MyEnum2 getMe2_3() {
    return this.me2_3;
  }

  /**
   * 
   * @see MyEnum2
   */
  public MyStruct setMe2_3(MyEnum2 me2_3) {
    this.me2_3 = me2_3;
    return this;
  }

  public void unsetMe2_3() {
    this.me2_3 = null;
  }

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

  public void setMe2_3IsSet(boolean __value) {
    if (!__value) {
      this.me2_3 = null;
    }
  }

  /**
   * 
   * @see MyEnum3
   */
  public MyEnum3 getMe3_n3() {
    return this.me3_n3;
  }

  /**
   * 
   * @see MyEnum3
   */
  public MyStruct setMe3_n3(MyEnum3 me3_n3) {
    this.me3_n3 = me3_n3;
    return this;
  }

  public void unsetMe3_n3() {
    this.me3_n3 = null;
  }

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

  public void setMe3_n3IsSet(boolean __value) {
    if (!__value) {
      this.me3_n3 = null;
    }
  }

  /**
   * 
   * @see MyEnum1
   */
  public MyEnum1 getMe1_t1() {
    return this.me1_t1;
  }

  /**
   * 
   * @see MyEnum1
   */
  public MyStruct setMe1_t1(MyEnum1 me1_t1) {
    this.me1_t1 = me1_t1;
    return this;
  }

  public void unsetMe1_t1() {
    this.me1_t1 = null;
  }

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

  public void setMe1_t1IsSet(boolean __value) {
    if (!__value) {
      this.me1_t1 = null;
    }
  }

  /**
   * 
   * @see MyEnum1
   */
  public MyEnum1 getMe1_t2() {
    return this.me1_t2;
  }

  /**
   * 
   * @see MyEnum1
   */
  public MyStruct setMe1_t2(MyEnum1 me1_t2) {
    this.me1_t2 = me1_t2;
    return this;
  }

  public void unsetMe1_t2() {
    this.me1_t2 = null;
  }

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

  public void setMe1_t2IsSet(boolean __value) {
    if (!__value) {
      this.me1_t2 = null;
    }
  }

  public void setFieldValue(int fieldID, Object __value) {
    switch (fieldID) {
    case ME2_3:
      if (__value == null) {
        unsetMe2_3();
      } else {
        setMe2_3((MyEnum2)__value);
      }
      break;

    case ME3_N3:
      if (__value == null) {
        unsetMe3_n3();
      } else {
        setMe3_n3((MyEnum3)__value);
      }
      break;

    case ME1_T1:
      if (__value == null) {
        unsetMe1_t1();
      } else {
        setMe1_t1((MyEnum1)__value);
      }
      break;

    case ME1_T2:
      if (__value == null) {
        unsetMe1_t2();
      } else {
        setMe1_t2((MyEnum1)__value);
      }
      break;

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

  public Object getFieldValue(int fieldID) {
    switch (fieldID) {
    case ME2_3:
      return getMe2_3();

    case ME3_N3:
      return getMe3_n3();

    case ME1_T1:
      return getMe1_t1();

    case ME1_T2:
      return getMe1_t2();

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

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

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

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

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

    return true;
  }

  @Override
  public int hashCode() {
    return Arrays.deepHashCode(new Object[] {me2_3, me3_n3, me1_t1, me1_t2});
  }

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

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

    lastComparison = Boolean.valueOf(isSetMe2_3()).compareTo(other.isSetMe2_3());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(me2_3, other.me2_3);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetMe3_n3()).compareTo(other.isSetMe3_n3());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(me3_n3, other.me3_n3);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetMe1_t1()).compareTo(other.isSetMe1_t1());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(me1_t1, other.me1_t1);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetMe1_t2()).compareTo(other.isSetMe1_t2());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(me1_t2, other.me1_t2);
    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 ME2_3:
          if (__field.type == TType.I32) {
            this.me2_3 = MyEnum2.findByValue(iprot.readI32());
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case ME3_N3:
          if (__field.type == TType.I32) {
            this.me3_n3 = MyEnum3.findByValue(iprot.readI32());
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case ME1_T1:
          if (__field.type == TType.I32) {
            this.me1_t1 = MyEnum1.findByValue(iprot.readI32());
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case ME1_T2:
          if (__field.type == TType.I32) {
            this.me1_t2 = MyEnum1.findByValue(iprot.readI32());
          } 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.me2_3 != null) {
      oprot.writeFieldBegin(ME2_3_FIELD_DESC);
      oprot.writeI32(this.me2_3 == null ? 0 : this.me2_3.getValue());
      oprot.writeFieldEnd();
    }
    if (this.me3_n3 != null) {
      oprot.writeFieldBegin(ME3_N3_FIELD_DESC);
      oprot.writeI32(this.me3_n3 == null ? 0 : this.me3_n3.getValue());
      oprot.writeFieldEnd();
    }
    if (this.me1_t1 != null) {
      oprot.writeFieldBegin(ME1_T1_FIELD_DESC);
      oprot.writeI32(this.me1_t1 == null ? 0 : this.me1_t1.getValue());
      oprot.writeFieldEnd();
    }
    if (this.me1_t2 != null) {
      oprot.writeFieldBegin(ME1_T2_FIELD_DESC);
      oprot.writeI32(this.me1_t2 == null ? 0 : this.me1_t2.getValue());
      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("MyStruct");
    sb.append(space);
    sb.append("(");
    sb.append(newLine);
    boolean first = true;

    sb.append(indentStr);
    sb.append("me2_3");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getMe2_3() == null) {
      sb.append("null");
    } else {
      String me2_3_name = this.getMe2_3() == null ? "null" : this.getMe2_3().name();
      if (me2_3_name != null) {
        sb.append(me2_3_name);
        sb.append(" (");
      }
      sb.append(this.getMe2_3());
      if (me2_3_name != null) {
        sb.append(")");
      }
    }
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("me3_n3");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getMe3_n3() == null) {
      sb.append("null");
    } else {
      String me3_n3_name = this.getMe3_n3() == null ? "null" : this.getMe3_n3().name();
      if (me3_n3_name != null) {
        sb.append(me3_n3_name);
        sb.append(" (");
      }
      sb.append(this.getMe3_n3());
      if (me3_n3_name != null) {
        sb.append(")");
      }
    }
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("me1_t1");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getMe1_t1() == null) {
      sb.append("null");
    } else {
      String me1_t1_name = this.getMe1_t1() == null ? "null" : this.getMe1_t1().name();
      if (me1_t1_name != null) {
        sb.append(me1_t1_name);
        sb.append(" (");
      }
      sb.append(this.getMe1_t1());
      if (me1_t1_name != null) {
        sb.append(")");
      }
    }
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("me1_t2");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getMe1_t2() == null) {
      sb.append("null");
    } else {
      String me1_t2_name = this.getMe1_t2() == null ? "null" : this.getMe1_t2().name();
      if (me1_t2_name != null) {
        sb.append(me1_t2_name);
        sb.append(" (");
      }
      sb.append(this.getMe1_t2());
      if (me1_t2_name != null) {
        sb.append(")");
      }
    }
    first = false;
    sb.append(newLine + TBaseHelper.reduceIndent(indentStr));
    sb.append(")");
    return sb.toString();
  }

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

}

