/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package com.facebook.thrift.annotation.cpp_deprecated;

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.*;

/**
 * An annotation that applies a C++ adapter to typedef, field, or struct.
 * 
 * For example:
 * 
 *   @cpp.Adapter{name = "::ns::IdAdapter"}
 *   typedef i64 MyI64;
 * 
 * Here the type `MyI64` has the C++ adapter `IdAdapter`.
 * 
 *   struct User {
 *     @cpp.Adapter{name = "::ns::IdAdapter"}
 *     1: i64 id;
 *   }
 * 
 * Here the field `id` has the C++ adapter `IdAdapter`.
 */
@SuppressWarnings({ "unused", "serial" })
public class Adapter implements TBase, java.io.Serializable, Cloneable, Comparable<Adapter> {
  private static final TStruct STRUCT_DESC = new TStruct("Adapter");
  private static final TField NAME_FIELD_DESC = new TField("name", TType.STRING, (short)1);
  private static final TField ADAPTED_TYPE_FIELD_DESC = new TField("adaptedType", TType.STRING, (short)2);
  private static final TField UNDERLYING_NAME_FIELD_DESC = new TField("underlyingName", TType.STRING, (short)3);
  private static final TField EXTRA_NAMESPACE_FIELD_DESC = new TField("extraNamespace", TType.STRING, (short)4);
  private static final TField MOVE_ONLY_FIELD_DESC = new TField("moveOnly", TType.BOOL, (short)5);

  /**
   * The name of a C++ adapter type used to convert between Thrift and native
   * C++ representation.
   * 
   * The adapter can be either a Type or Field adapter, providing either of the following APIs:
   * 
   *     struct ThriftTypeAdapter {
   *       static AdaptedType fromThrift(ThriftType thrift);
   *       static {const ThriftType& | ThriftType} toThrift(const AdaptedType& native);
   *     };
   * 
   *     struct ThriftFieldAdapter {
   *       // Context is an instantiation of apache::thrift::FieldContext
   *       template <class Context>
   *       static void construct(AdaptedType& field, Context ctx);
   * 
   *       template <class Context>
   *       static AdaptedType fromThriftField(ThriftType value, Context ctx);
   * 
   *       template <class Context>
   *       static {const ThriftType& | ThriftType} toThrift(const AdaptedType& adapted, Context ctx);
   *     };
   */
  public String name;
  /**
   * It is sometimes necessary to specify AdaptedType here (in case the codegen would
   * have a circular depdenceny, which will cause the C++ build to fail).
   */
  public String adaptedType;
  /**
   * The name and/or extra namespace to use when directly adapting a type
   * (as opposed a typedef).
   * 
   * In this case, the IDL name of the type will refer to the adapted type in
   * C++ and the underlying thrift type will be generated in a nested
   * namespace and/or with a different name.
   * 
   * If neither `underlyingName` or `extraNamespace` is provided, the
   * underlying type will be generated in a nested 'detail' namespace with
   * the same name.
   */
  public String underlyingName;
  public String extraNamespace;
  /**
   * Must set to true when adapted type is not copyable.
   */
  public boolean moveOnly;
  public static final int NAME = 1;
  public static final int ADAPTEDTYPE = 2;
  public static final int UNDERLYINGNAME = 3;
  public static final int EXTRANAMESPACE = 4;
  public static final int MOVEONLY = 5;

  // isset id assignments
  private static final int __MOVEONLY_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(NAME, new FieldMetaData("name", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.STRING)));
    tmpMetaDataMap.put(ADAPTEDTYPE, new FieldMetaData("adaptedType", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.STRING)));
    tmpMetaDataMap.put(UNDERLYINGNAME, new FieldMetaData("underlyingName", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.STRING)));
    tmpMetaDataMap.put(EXTRANAMESPACE, new FieldMetaData("extraNamespace", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.STRING)));
    tmpMetaDataMap.put(MOVEONLY, new FieldMetaData("moveOnly", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.BOOL)));
    metaDataMap = Collections.unmodifiableMap(tmpMetaDataMap);
  }

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

  public Adapter() {
  }

  public Adapter(
      String name,
      String adaptedType,
      String underlyingName,
      String extraNamespace,
      boolean moveOnly) {
    this();
    this.name = name;
    this.adaptedType = adaptedType;
    this.underlyingName = underlyingName;
    this.extraNamespace = extraNamespace;
    this.moveOnly = moveOnly;
    setMoveOnlyIsSet(true);
  }

  public static class Builder {
    private String name;
    private String adaptedType;
    private String underlyingName;
    private String extraNamespace;
    private boolean moveOnly;

    BitSet __optional_isset = new BitSet(1);

    public Builder() {
    }

    public Builder setName(final String name) {
      this.name = name;
      return this;
    }

    public Builder setAdaptedType(final String adaptedType) {
      this.adaptedType = adaptedType;
      return this;
    }

    public Builder setUnderlyingName(final String underlyingName) {
      this.underlyingName = underlyingName;
      return this;
    }

    public Builder setExtraNamespace(final String extraNamespace) {
      this.extraNamespace = extraNamespace;
      return this;
    }

    public Builder setMoveOnly(final boolean moveOnly) {
      this.moveOnly = moveOnly;
      __optional_isset.set(__MOVEONLY_ISSET_ID, true);
      return this;
    }

    public Adapter build() {
      Adapter result = new Adapter();
      result.setName(this.name);
      result.setAdaptedType(this.adaptedType);
      result.setUnderlyingName(this.underlyingName);
      result.setExtraNamespace(this.extraNamespace);
      if (__optional_isset.get(__MOVEONLY_ISSET_ID)) {
        result.setMoveOnly(this.moveOnly);
      }
      return result;
    }
  }

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

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public Adapter(Adapter other) {
    __isset_bit_vector.clear();
    __isset_bit_vector.or(other.__isset_bit_vector);
    if (other.isSetName()) {
      this.name = TBaseHelper.deepCopy(other.name);
    }
    if (other.isSetAdaptedType()) {
      this.adaptedType = TBaseHelper.deepCopy(other.adaptedType);
    }
    if (other.isSetUnderlyingName()) {
      this.underlyingName = TBaseHelper.deepCopy(other.underlyingName);
    }
    if (other.isSetExtraNamespace()) {
      this.extraNamespace = TBaseHelper.deepCopy(other.extraNamespace);
    }
    this.moveOnly = TBaseHelper.deepCopy(other.moveOnly);
  }

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

  /**
   * The name of a C++ adapter type used to convert between Thrift and native
   * C++ representation.
   * 
   * The adapter can be either a Type or Field adapter, providing either of the following APIs:
   * 
   *     struct ThriftTypeAdapter {
   *       static AdaptedType fromThrift(ThriftType thrift);
   *       static {const ThriftType& | ThriftType} toThrift(const AdaptedType& native);
   *     };
   * 
   *     struct ThriftFieldAdapter {
   *       // Context is an instantiation of apache::thrift::FieldContext
   *       template <class Context>
   *       static void construct(AdaptedType& field, Context ctx);
   * 
   *       template <class Context>
   *       static AdaptedType fromThriftField(ThriftType value, Context ctx);
   * 
   *       template <class Context>
   *       static {const ThriftType& | ThriftType} toThrift(const AdaptedType& adapted, Context ctx);
   *     };
   */
  public String getName() {
    return this.name;
  }

  /**
   * The name of a C++ adapter type used to convert between Thrift and native
   * C++ representation.
   * 
   * The adapter can be either a Type or Field adapter, providing either of the following APIs:
   * 
   *     struct ThriftTypeAdapter {
   *       static AdaptedType fromThrift(ThriftType thrift);
   *       static {const ThriftType& | ThriftType} toThrift(const AdaptedType& native);
   *     };
   * 
   *     struct ThriftFieldAdapter {
   *       // Context is an instantiation of apache::thrift::FieldContext
   *       template <class Context>
   *       static void construct(AdaptedType& field, Context ctx);
   * 
   *       template <class Context>
   *       static AdaptedType fromThriftField(ThriftType value, Context ctx);
   * 
   *       template <class Context>
   *       static {const ThriftType& | ThriftType} toThrift(const AdaptedType& adapted, Context ctx);
   *     };
   */
  public Adapter setName(String name) {
    this.name = name;
    return this;
  }

  public void unsetName() {
    this.name = null;
  }

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

  public void setNameIsSet(boolean __value) {
    if (!__value) {
      this.name = null;
    }
  }

  /**
   * It is sometimes necessary to specify AdaptedType here (in case the codegen would
   * have a circular depdenceny, which will cause the C++ build to fail).
   */
  public String getAdaptedType() {
    return this.adaptedType;
  }

  /**
   * It is sometimes necessary to specify AdaptedType here (in case the codegen would
   * have a circular depdenceny, which will cause the C++ build to fail).
   */
  public Adapter setAdaptedType(String adaptedType) {
    this.adaptedType = adaptedType;
    return this;
  }

  public void unsetAdaptedType() {
    this.adaptedType = null;
  }

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

  public void setAdaptedTypeIsSet(boolean __value) {
    if (!__value) {
      this.adaptedType = null;
    }
  }

  /**
   * The name and/or extra namespace to use when directly adapting a type
   * (as opposed a typedef).
   * 
   * In this case, the IDL name of the type will refer to the adapted type in
   * C++ and the underlying thrift type will be generated in a nested
   * namespace and/or with a different name.
   * 
   * If neither `underlyingName` or `extraNamespace` is provided, the
   * underlying type will be generated in a nested 'detail' namespace with
   * the same name.
   */
  public String getUnderlyingName() {
    return this.underlyingName;
  }

  /**
   * The name and/or extra namespace to use when directly adapting a type
   * (as opposed a typedef).
   * 
   * In this case, the IDL name of the type will refer to the adapted type in
   * C++ and the underlying thrift type will be generated in a nested
   * namespace and/or with a different name.
   * 
   * If neither `underlyingName` or `extraNamespace` is provided, the
   * underlying type will be generated in a nested 'detail' namespace with
   * the same name.
   */
  public Adapter setUnderlyingName(String underlyingName) {
    this.underlyingName = underlyingName;
    return this;
  }

  public void unsetUnderlyingName() {
    this.underlyingName = null;
  }

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

  public void setUnderlyingNameIsSet(boolean __value) {
    if (!__value) {
      this.underlyingName = null;
    }
  }

  public String getExtraNamespace() {
    return this.extraNamespace;
  }

  public Adapter setExtraNamespace(String extraNamespace) {
    this.extraNamespace = extraNamespace;
    return this;
  }

  public void unsetExtraNamespace() {
    this.extraNamespace = null;
  }

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

  public void setExtraNamespaceIsSet(boolean __value) {
    if (!__value) {
      this.extraNamespace = null;
    }
  }

  /**
   * Must set to true when adapted type is not copyable.
   */
  public boolean isMoveOnly() {
    return this.moveOnly;
  }

  /**
   * Must set to true when adapted type is not copyable.
   */
  public Adapter setMoveOnly(boolean moveOnly) {
    this.moveOnly = moveOnly;
    setMoveOnlyIsSet(true);
    return this;
  }

  public void unsetMoveOnly() {
    __isset_bit_vector.clear(__MOVEONLY_ISSET_ID);
  }

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

  public void setMoveOnlyIsSet(boolean __value) {
    __isset_bit_vector.set(__MOVEONLY_ISSET_ID, __value);
  }

  public void setFieldValue(int fieldID, Object __value) {
    switch (fieldID) {
    case NAME:
      if (__value == null) {
        unsetName();
      } else {
        setName((String)__value);
      }
      break;

    case ADAPTEDTYPE:
      if (__value == null) {
        unsetAdaptedType();
      } else {
        setAdaptedType((String)__value);
      }
      break;

    case UNDERLYINGNAME:
      if (__value == null) {
        unsetUnderlyingName();
      } else {
        setUnderlyingName((String)__value);
      }
      break;

    case EXTRANAMESPACE:
      if (__value == null) {
        unsetExtraNamespace();
      } else {
        setExtraNamespace((String)__value);
      }
      break;

    case MOVEONLY:
      if (__value == null) {
        unsetMoveOnly();
      } else {
        setMoveOnly((Boolean)__value);
      }
      break;

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

  public Object getFieldValue(int fieldID) {
    switch (fieldID) {
    case NAME:
      return getName();

    case ADAPTEDTYPE:
      return getAdaptedType();

    case UNDERLYINGNAME:
      return getUnderlyingName();

    case EXTRANAMESPACE:
      return getExtraNamespace();

    case MOVEONLY:
      return new Boolean(isMoveOnly());

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

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

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

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

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

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

    return true;
  }

  @Override
  public int hashCode() {
    return Arrays.deepHashCode(new Object[] {name, adaptedType, underlyingName, extraNamespace, moveOnly});
  }

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

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

    lastComparison = Boolean.valueOf(isSetName()).compareTo(other.isSetName());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(name, other.name);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetAdaptedType()).compareTo(other.isSetAdaptedType());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(adaptedType, other.adaptedType);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetUnderlyingName()).compareTo(other.isSetUnderlyingName());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(underlyingName, other.underlyingName);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetExtraNamespace()).compareTo(other.isSetExtraNamespace());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(extraNamespace, other.extraNamespace);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetMoveOnly()).compareTo(other.isSetMoveOnly());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(moveOnly, other.moveOnly);
    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 NAME:
          if (__field.type == TType.STRING) {
            this.name = iprot.readString();
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case ADAPTEDTYPE:
          if (__field.type == TType.STRING) {
            this.adaptedType = iprot.readString();
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case UNDERLYINGNAME:
          if (__field.type == TType.STRING) {
            this.underlyingName = iprot.readString();
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case EXTRANAMESPACE:
          if (__field.type == TType.STRING) {
            this.extraNamespace = iprot.readString();
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case MOVEONLY:
          if (__field.type == TType.BOOL) {
            this.moveOnly = iprot.readBool();
            setMoveOnlyIsSet(true);
          } 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.name != null) {
      oprot.writeFieldBegin(NAME_FIELD_DESC);
      oprot.writeString(this.name);
      oprot.writeFieldEnd();
    }
    if (this.adaptedType != null) {
      oprot.writeFieldBegin(ADAPTED_TYPE_FIELD_DESC);
      oprot.writeString(this.adaptedType);
      oprot.writeFieldEnd();
    }
    if (this.underlyingName != null) {
      oprot.writeFieldBegin(UNDERLYING_NAME_FIELD_DESC);
      oprot.writeString(this.underlyingName);
      oprot.writeFieldEnd();
    }
    if (this.extraNamespace != null) {
      oprot.writeFieldBegin(EXTRA_NAMESPACE_FIELD_DESC);
      oprot.writeString(this.extraNamespace);
      oprot.writeFieldEnd();
    }
    oprot.writeFieldBegin(MOVE_ONLY_FIELD_DESC);
    oprot.writeBool(this.moveOnly);
    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("Adapter");
    sb.append(space);
    sb.append("(");
    sb.append(newLine);
    boolean first = true;

    sb.append(indentStr);
    sb.append("name");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getName() == null) {
      sb.append("null");
    } else {
      sb.append(TBaseHelper.toString(this.getName(), indent + 1, prettyPrint));
    }
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("adaptedType");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getAdaptedType() == null) {
      sb.append("null");
    } else {
      sb.append(TBaseHelper.toString(this.getAdaptedType(), indent + 1, prettyPrint));
    }
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("underlyingName");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getUnderlyingName() == null) {
      sb.append("null");
    } else {
      sb.append(TBaseHelper.toString(this.getUnderlyingName(), indent + 1, prettyPrint));
    }
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("extraNamespace");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getExtraNamespace() == null) {
      sb.append("null");
    } else {
      sb.append(TBaseHelper.toString(this.getExtraNamespace(), indent + 1, prettyPrint));
    }
    first = false;
    if (!first) sb.append("," + newLine);
    sb.append(indentStr);
    sb.append("moveOnly");
    sb.append(space);
    sb.append(":").append(space);
    sb.append(TBaseHelper.toString(this.isMoveOnly(), 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
  }

}

