/**
 * 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 AdaptTemplatedNestedTestStruct implements TBase, java.io.Serializable, Cloneable, Comparable<AdaptTemplatedNestedTestStruct> {
  private static final TStruct STRUCT_DESC = new TStruct("AdaptTemplatedNestedTestStruct");
  private static final TField ADAPTED_STRUCT_FIELD_DESC = new TField("adaptedStruct", TType.STRUCT, (short)1);

  public AdaptTemplatedTestStruct adaptedStruct;
  public static final int ADAPTEDSTRUCT = 1;

  // isset id assignments

  public static final Map<Integer, FieldMetaData> metaDataMap;

  static {
    Map<Integer, FieldMetaData> tmpMetaDataMap = new HashMap<Integer, FieldMetaData>();
    tmpMetaDataMap.put(ADAPTEDSTRUCT, new FieldMetaData("adaptedStruct", TFieldRequirementType.DEFAULT, 
        new StructMetaData(TType.STRUCT, AdaptTemplatedTestStruct.class)));
    metaDataMap = Collections.unmodifiableMap(tmpMetaDataMap);
  }

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

  public AdaptTemplatedNestedTestStruct() {
  }

  public AdaptTemplatedNestedTestStruct(
      AdaptTemplatedTestStruct adaptedStruct) {
    this();
    this.adaptedStruct = adaptedStruct;
  }

  public static class Builder {
    private AdaptTemplatedTestStruct adaptedStruct;

    public Builder() {
    }

    public Builder setAdaptedStruct(final AdaptTemplatedTestStruct adaptedStruct) {
      this.adaptedStruct = adaptedStruct;
      return this;
    }

    public AdaptTemplatedNestedTestStruct build() {
      AdaptTemplatedNestedTestStruct result = new AdaptTemplatedNestedTestStruct();
      result.setAdaptedStruct(this.adaptedStruct);
      return result;
    }
  }

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

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public AdaptTemplatedNestedTestStruct(AdaptTemplatedNestedTestStruct other) {
    if (other.isSetAdaptedStruct()) {
      this.adaptedStruct = TBaseHelper.deepCopy(other.adaptedStruct);
    }
  }

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

  public AdaptTemplatedTestStruct getAdaptedStruct() {
    return this.adaptedStruct;
  }

  public AdaptTemplatedNestedTestStruct setAdaptedStruct(AdaptTemplatedTestStruct adaptedStruct) {
    this.adaptedStruct = adaptedStruct;
    return this;
  }

  public void unsetAdaptedStruct() {
    this.adaptedStruct = null;
  }

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

  public void setAdaptedStructIsSet(boolean __value) {
    if (!__value) {
      this.adaptedStruct = null;
    }
  }

  public void setFieldValue(int fieldID, Object __value) {
    switch (fieldID) {
    case ADAPTEDSTRUCT:
      if (__value == null) {
        unsetAdaptedStruct();
      } else {
        setAdaptedStruct((AdaptTemplatedTestStruct)__value);
      }
      break;

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

  public Object getFieldValue(int fieldID) {
    switch (fieldID) {
    case ADAPTEDSTRUCT:
      return getAdaptedStruct();

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

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

    return true;
  }

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

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

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

    lastComparison = Boolean.valueOf(isSetAdaptedStruct()).compareTo(other.isSetAdaptedStruct());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(adaptedStruct, other.adaptedStruct);
    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 ADAPTEDSTRUCT:
          if (__field.type == TType.STRUCT) {
            this.adaptedStruct = new AdaptTemplatedTestStruct();
            this.adaptedStruct.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.adaptedStruct != null) {
      oprot.writeFieldBegin(ADAPTED_STRUCT_FIELD_DESC);
      this.adaptedStruct.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("AdaptTemplatedNestedTestStruct");
    sb.append(space);
    sb.append("(");
    sb.append(newLine);
    boolean first = true;

    sb.append(indentStr);
    sb.append("adaptedStruct");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getAdaptedStruct() == null) {
      sb.append("null");
    } else {
      sb.append(TBaseHelper.toString(this.getAdaptedStruct(), 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
  }

}

