/**
 * 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 optXcep extends Exception implements TBase, java.io.Serializable, Cloneable {
  private static final TStruct STRUCT_DESC = new TStruct("optXcep");
  private static final TField MESSAGE_FIELD_DESC = new TField("message", TType.STRING, (short)1);
  private static final TField ERROR_CODE_FIELD_DESC = new TField("errorCode", TType.I32, (short)2);

  public String message;
  public int errorCode;
  public static final int MESSAGE = 1;
  public static final int ERRORCODE = 2;

  // isset id assignments
  private static final int __ERRORCODE_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(MESSAGE, new FieldMetaData("message", TFieldRequirementType.OPTIONAL, 
        new FieldValueMetaData(TType.STRING)));
    tmpMetaDataMap.put(ERRORCODE, new FieldMetaData("errorCode", TFieldRequirementType.OPTIONAL, 
        new FieldValueMetaData(TType.I32)));
    metaDataMap = Collections.unmodifiableMap(tmpMetaDataMap);
  }

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

  public optXcep() {
  }

  public optXcep(
      String message,
      int errorCode) {
    this();
    this.message = message;
    this.errorCode = errorCode;
    setErrorCodeIsSet(true);
  }

  public static class Builder {
    private String message;
    private int errorCode;

    BitSet __optional_isset = new BitSet(1);

    public Builder() {
    }

    public Builder setMessage(final String message) {
      this.message = message;
      return this;
    }

    public Builder setErrorCode(final int errorCode) {
      this.errorCode = errorCode;
      __optional_isset.set(__ERRORCODE_ISSET_ID, true);
      return this;
    }

    public optXcep build() {
      optXcep result = new optXcep();
      result.setMessage(this.message);
      if (__optional_isset.get(__ERRORCODE_ISSET_ID)) {
        result.setErrorCode(this.errorCode);
      }
      return result;
    }
  }

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

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public optXcep(optXcep other) {
    __isset_bit_vector.clear();
    __isset_bit_vector.or(other.__isset_bit_vector);
    if (other.isSetMessage()) {
      this.message = TBaseHelper.deepCopy(other.message);
    }
    this.errorCode = TBaseHelper.deepCopy(other.errorCode);
  }

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

  public String getMessage() {
    return this.message;
  }

  public optXcep setMessage(String message) {
    this.message = message;
    return this;
  }

  public void unsetMessage() {
    this.message = null;
  }

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

  public void setMessageIsSet(boolean __value) {
    if (!__value) {
      this.message = null;
    }
  }

  public int getErrorCode() {
    return this.errorCode;
  }

  public optXcep setErrorCode(int errorCode) {
    this.errorCode = errorCode;
    setErrorCodeIsSet(true);
    return this;
  }

  public void unsetErrorCode() {
    __isset_bit_vector.clear(__ERRORCODE_ISSET_ID);
  }

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

  public void setErrorCodeIsSet(boolean __value) {
    __isset_bit_vector.set(__ERRORCODE_ISSET_ID, __value);
  }

  public void setFieldValue(int fieldID, Object __value) {
    switch (fieldID) {
    case MESSAGE:
      if (__value == null) {
        unsetMessage();
      } else {
        setMessage((String)__value);
      }
      break;

    case ERRORCODE:
      if (__value == null) {
        unsetErrorCode();
      } else {
        setErrorCode((Integer)__value);
      }
      break;

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

  public Object getFieldValue(int fieldID) {
    switch (fieldID) {
    case MESSAGE:
      return getMessage();

    case ERRORCODE:
      return new Integer(getErrorCode());

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

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

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

    return true;
  }

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

  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 MESSAGE:
          if (__field.type == TType.STRING) {
            this.message = iprot.readString();
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case ERRORCODE:
          if (__field.type == TType.I32) {
            this.errorCode = iprot.readI32();
            setErrorCodeIsSet(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.message != null) {
      if (isSetMessage()) {
        oprot.writeFieldBegin(MESSAGE_FIELD_DESC);
        oprot.writeString(this.message);
        oprot.writeFieldEnd();
      }
    }
    if (isSetErrorCode()) {
      oprot.writeFieldBegin(ERROR_CODE_FIELD_DESC);
      oprot.writeI32(this.errorCode);
      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("optXcep");
    sb.append(space);
    sb.append("(");
    sb.append(newLine);
    boolean first = true;

    if (isSetMessage())
    {
      sb.append(indentStr);
      sb.append("message");
      sb.append(space);
      sb.append(":").append(space);
      if (this.getMessage() == null) {
        sb.append("null");
      } else {
        sb.append(TBaseHelper.toString(this.getMessage(), indent + 1, prettyPrint));
      }
      first = false;
    }
    if (isSetErrorCode())
    {
      if (!first) sb.append("," + newLine);
      sb.append(indentStr);
      sb.append("errorCode");
      sb.append(space);
      sb.append(":").append(space);
      sb.append(TBaseHelper.toString(this.getErrorCode(), 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
  }

}

