/**
 * Autogenerated by Thrift Compiler (0.7.0)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 */
package org.apache.hadoop.thriftfs.api;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Set;
import java.util.HashSet;
import java.util.EnumSet;
import java.util.Collections;
import java.util.BitSet;
import java.nio.ByteBuffer;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Generic I/O error
 */
public class IOException extends Exception implements org.apache.thrift.TBase<IOException, IOException._Fields>, java.io.Serializable, Cloneable {
  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("IOException");

  private static final org.apache.thrift.protocol.TField MSG_FIELD_DESC = new org.apache.thrift.protocol.TField("msg", org.apache.thrift.protocol.TType.STRING, (short)1);
  private static final org.apache.thrift.protocol.TField STACK_FIELD_DESC = new org.apache.thrift.protocol.TField("stack", org.apache.thrift.protocol.TType.STRING, (short)2);
  private static final org.apache.thrift.protocol.TField CLAZZ_FIELD_DESC = new org.apache.thrift.protocol.TField("clazz", org.apache.thrift.protocol.TType.STRING, (short)3);

  /**
   * Error message.
   */
  public String msg; // required
  /**
   * Textual representation of the call stack.
   */
  public String stack; // required
  /**
   * The Java class of the Exception (may be a subclass)
   */
  public String clazz; // required

  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
  public enum _Fields implements org.apache.thrift.TFieldIdEnum {
    /**
     * Error message.
     */
    MSG((short)1, "msg"),
    /**
     * Textual representation of the call stack.
     */
    STACK((short)2, "stack"),
    /**
     * The Java class of the Exception (may be a subclass)
     */
    CLAZZ((short)3, "clazz");

    private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();

    static {
      for (_Fields field : EnumSet.allOf(_Fields.class)) {
        byName.put(field.getFieldName(), field);
      }
    }

    /**
     * Find the _Fields constant that matches fieldId, or null if its not found.
     */
    public static _Fields findByThriftId(int fieldId) {
      switch(fieldId) {
        case 1: // MSG
          return MSG;
        case 2: // STACK
          return STACK;
        case 3: // CLAZZ
          return CLAZZ;
        default:
          return null;
      }
    }

    /**
     * Find the _Fields constant that matches fieldId, throwing an exception
     * if it is not found.
     */
    public static _Fields findByThriftIdOrThrow(int fieldId) {
      _Fields fields = findByThriftId(fieldId);
      if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
      return fields;
    }

    /**
     * Find the _Fields constant that matches name, or null if its not found.
     */
    public static _Fields findByName(String name) {
      return byName.get(name);
    }

    private final short _thriftId;
    private final String _fieldName;

    _Fields(short thriftId, String fieldName) {
      _thriftId = thriftId;
      _fieldName = fieldName;
    }

    public short getThriftFieldId() {
      return _thriftId;
    }

    public String getFieldName() {
      return _fieldName;
    }
  }

  // isset id assignments

  public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
  static {
    Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
    tmpMap.put(_Fields.MSG, new org.apache.thrift.meta_data.FieldMetaData("msg", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    tmpMap.put(_Fields.STACK, new org.apache.thrift.meta_data.FieldMetaData("stack", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    tmpMap.put(_Fields.CLAZZ, new org.apache.thrift.meta_data.FieldMetaData("clazz", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    metaDataMap = Collections.unmodifiableMap(tmpMap);
    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(IOException.class, metaDataMap);
  }

  public IOException() {
  }

  public IOException(
    String msg,
    String stack,
    String clazz)
  {
    this();
    this.msg = msg;
    this.stack = stack;
    this.clazz = clazz;
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public IOException(IOException other) {
    if (other.isSetMsg()) {
      this.msg = other.msg;
    }
    if (other.isSetStack()) {
      this.stack = other.stack;
    }
    if (other.isSetClazz()) {
      this.clazz = other.clazz;
    }
  }

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

  @Override
  public void clear() {
    this.msg = null;
    this.stack = null;
    this.clazz = null;
  }

  /**
   * Error message.
   */
  public String getMsg() {
    return this.msg;
  }

  /**
   * Error message.
   */
  public IOException setMsg(String msg) {
    this.msg = msg;
    return this;
  }

  public void unsetMsg() {
    this.msg = null;
  }

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

  public void setMsgIsSet(boolean value) {
    if (!value) {
      this.msg = null;
    }
  }

  /**
   * Textual representation of the call stack.
   */
  public String getStack() {
    return this.stack;
  }

  /**
   * Textual representation of the call stack.
   */
  public IOException setStack(String stack) {
    this.stack = stack;
    return this;
  }

  public void unsetStack() {
    this.stack = null;
  }

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

  public void setStackIsSet(boolean value) {
    if (!value) {
      this.stack = null;
    }
  }

  /**
   * The Java class of the Exception (may be a subclass)
   */
  public String getClazz() {
    return this.clazz;
  }

  /**
   * The Java class of the Exception (may be a subclass)
   */
  public IOException setClazz(String clazz) {
    this.clazz = clazz;
    return this;
  }

  public void unsetClazz() {
    this.clazz = null;
  }

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

  public void setClazzIsSet(boolean value) {
    if (!value) {
      this.clazz = null;
    }
  }

  public void setFieldValue(_Fields field, Object value) {
    switch (field) {
    case MSG:
      if (value == null) {
        unsetMsg();
      } else {
        setMsg((String)value);
      }
      break;

    case STACK:
      if (value == null) {
        unsetStack();
      } else {
        setStack((String)value);
      }
      break;

    case CLAZZ:
      if (value == null) {
        unsetClazz();
      } else {
        setClazz((String)value);
      }
      break;

    }
  }

  public Object getFieldValue(_Fields field) {
    switch (field) {
    case MSG:
      return getMsg();

    case STACK:
      return getStack();

    case CLAZZ:
      return getClazz();

    }
    throw new IllegalStateException();
  }

  /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
  public boolean isSet(_Fields field) {
    if (field == null) {
      throw new IllegalArgumentException();
    }

    switch (field) {
    case MSG:
      return isSetMsg();
    case STACK:
      return isSetStack();
    case CLAZZ:
      return isSetClazz();
    }
    throw new IllegalStateException();
  }

  @Override
  public boolean equals(Object that) {
    if (that == null)
      return false;
    if (that instanceof IOException)
      return this.equals((IOException)that);
    return false;
  }

  public boolean equals(IOException that) {
    if (that == null)
      return false;

    boolean this_present_msg = true && this.isSetMsg();
    boolean that_present_msg = true && that.isSetMsg();
    if (this_present_msg || that_present_msg) {
      if (!(this_present_msg && that_present_msg))
        return false;
      if (!this.msg.equals(that.msg))
        return false;
    }

    boolean this_present_stack = true && this.isSetStack();
    boolean that_present_stack = true && that.isSetStack();
    if (this_present_stack || that_present_stack) {
      if (!(this_present_stack && that_present_stack))
        return false;
      if (!this.stack.equals(that.stack))
        return false;
    }

    boolean this_present_clazz = true && this.isSetClazz();
    boolean that_present_clazz = true && that.isSetClazz();
    if (this_present_clazz || that_present_clazz) {
      if (!(this_present_clazz && that_present_clazz))
        return false;
      if (!this.clazz.equals(that.clazz))
        return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    return 0;
  }

  public int compareTo(IOException other) {
    if (!getClass().equals(other.getClass())) {
      return getClass().getName().compareTo(other.getClass().getName());
    }

    int lastComparison = 0;
    IOException typedOther = (IOException)other;

    lastComparison = Boolean.valueOf(isSetMsg()).compareTo(typedOther.isSetMsg());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetMsg()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.msg, typedOther.msg);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetStack()).compareTo(typedOther.isSetStack());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetStack()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.stack, typedOther.stack);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetClazz()).compareTo(typedOther.isSetClazz());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetClazz()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.clazz, typedOther.clazz);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    return 0;
  }

  public _Fields fieldForId(int fieldId) {
    return _Fields.findByThriftId(fieldId);
  }

  public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
    org.apache.thrift.protocol.TField field;
    iprot.readStructBegin();
    while (true)
    {
      field = iprot.readFieldBegin();
      if (field.type == org.apache.thrift.protocol.TType.STOP) { 
        break;
      }
      switch (field.id) {
        case 1: // MSG
          if (field.type == org.apache.thrift.protocol.TType.STRING) {
            this.msg = iprot.readString();
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 2: // STACK
          if (field.type == org.apache.thrift.protocol.TType.STRING) {
            this.stack = iprot.readString();
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 3: // CLAZZ
          if (field.type == org.apache.thrift.protocol.TType.STRING) {
            this.clazz = iprot.readString();
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        default:
          org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
      }
      iprot.readFieldEnd();
    }
    iprot.readStructEnd();

    // check for required fields of primitive type, which can't be checked in the validate method
    validate();
  }

  public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
    validate();

    oprot.writeStructBegin(STRUCT_DESC);
    if (this.msg != null) {
      oprot.writeFieldBegin(MSG_FIELD_DESC);
      oprot.writeString(this.msg);
      oprot.writeFieldEnd();
    }
    if (this.stack != null) {
      oprot.writeFieldBegin(STACK_FIELD_DESC);
      oprot.writeString(this.stack);
      oprot.writeFieldEnd();
    }
    if (this.clazz != null) {
      oprot.writeFieldBegin(CLAZZ_FIELD_DESC);
      oprot.writeString(this.clazz);
      oprot.writeFieldEnd();
    }
    oprot.writeFieldStop();
    oprot.writeStructEnd();
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder("IOException(");
    boolean first = true;

    sb.append("msg:");
    if (this.msg == null) {
      sb.append("null");
    } else {
      sb.append(this.msg);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("stack:");
    if (this.stack == null) {
      sb.append("null");
    } else {
      sb.append(this.stack);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("clazz:");
    if (this.clazz == null) {
      sb.append("null");
    } else {
      sb.append(this.clazz);
    }
    first = false;
    sb.append(")");
    return sb.toString();
  }

  public void validate() throws org.apache.thrift.TException {
    // check for required fields
  }

  private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
    try {
      write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
    } catch (org.apache.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

  private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
    try {
      read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
    } catch (org.apache.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

}

