/**
 * Autogenerated by Thrift Compiler (0.7.0)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 */
package com.cloudera.beeswax.api;

import org.apache.commons.lang.builder.HashCodeBuilder;
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;

/**
 * Metadata information about the results.
 * Applicable only for SELECT.
 */
public class ResultsMetadata implements org.apache.thrift.TBase<ResultsMetadata, ResultsMetadata._Fields>, java.io.Serializable, Cloneable {
  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("ResultsMetadata");

  private static final org.apache.thrift.protocol.TField SCHEMA_FIELD_DESC = new org.apache.thrift.protocol.TField("schema", org.apache.thrift.protocol.TType.STRUCT, (short)1);
  private static final org.apache.thrift.protocol.TField TABLE_DIR_FIELD_DESC = new org.apache.thrift.protocol.TField("table_dir", org.apache.thrift.protocol.TType.STRING, (short)2);
  private static final org.apache.thrift.protocol.TField IN_TABLENAME_FIELD_DESC = new org.apache.thrift.protocol.TField("in_tablename", org.apache.thrift.protocol.TType.STRING, (short)3);
  private static final org.apache.thrift.protocol.TField DELIM_FIELD_DESC = new org.apache.thrift.protocol.TField("delim", org.apache.thrift.protocol.TType.STRING, (short)4);

  /**
   * The schema of the results
   */
  public org.apache.hadoop.hive.metastore.api.Schema schema; // required
  /**
   * The directory containing the results. Not applicable for partition table.
   */
  public String table_dir; // required
  /**
   * If the results are straight from an existing table, the table name.
   */
  public String in_tablename; // required
  /**
   * Field delimiter
   */
  public String delim; // 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 {
    /**
     * The schema of the results
     */
    SCHEMA((short)1, "schema"),
    /**
     * The directory containing the results. Not applicable for partition table.
     */
    TABLE_DIR((short)2, "table_dir"),
    /**
     * If the results are straight from an existing table, the table name.
     */
    IN_TABLENAME((short)3, "in_tablename"),
    /**
     * Field delimiter
     */
    DELIM((short)4, "delim");

    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: // SCHEMA
          return SCHEMA;
        case 2: // TABLE_DIR
          return TABLE_DIR;
        case 3: // IN_TABLENAME
          return IN_TABLENAME;
        case 4: // DELIM
          return DELIM;
        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.SCHEMA, new org.apache.thrift.meta_data.FieldMetaData("schema", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, org.apache.hadoop.hive.metastore.api.Schema.class)));
    tmpMap.put(_Fields.TABLE_DIR, new org.apache.thrift.meta_data.FieldMetaData("table_dir", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    tmpMap.put(_Fields.IN_TABLENAME, new org.apache.thrift.meta_data.FieldMetaData("in_tablename", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    tmpMap.put(_Fields.DELIM, new org.apache.thrift.meta_data.FieldMetaData("delim", 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(ResultsMetadata.class, metaDataMap);
  }

  public ResultsMetadata() {
  }

  public ResultsMetadata(
    org.apache.hadoop.hive.metastore.api.Schema schema,
    String table_dir,
    String in_tablename,
    String delim)
  {
    this();
    this.schema = schema;
    this.table_dir = table_dir;
    this.in_tablename = in_tablename;
    this.delim = delim;
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public ResultsMetadata(ResultsMetadata other) {
    if (other.isSetSchema()) {
      this.schema = new org.apache.hadoop.hive.metastore.api.Schema(other.schema);
    }
    if (other.isSetTable_dir()) {
      this.table_dir = other.table_dir;
    }
    if (other.isSetIn_tablename()) {
      this.in_tablename = other.in_tablename;
    }
    if (other.isSetDelim()) {
      this.delim = other.delim;
    }
  }

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

  @Override
  public void clear() {
    this.schema = null;
    this.table_dir = null;
    this.in_tablename = null;
    this.delim = null;
  }

  /**
   * The schema of the results
   */
  public org.apache.hadoop.hive.metastore.api.Schema getSchema() {
    return this.schema;
  }

  /**
   * The schema of the results
   */
  public ResultsMetadata setSchema(org.apache.hadoop.hive.metastore.api.Schema schema) {
    this.schema = schema;
    return this;
  }

  public void unsetSchema() {
    this.schema = null;
  }

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

  public void setSchemaIsSet(boolean value) {
    if (!value) {
      this.schema = null;
    }
  }

  /**
   * The directory containing the results. Not applicable for partition table.
   */
  public String getTable_dir() {
    return this.table_dir;
  }

  /**
   * The directory containing the results. Not applicable for partition table.
   */
  public ResultsMetadata setTable_dir(String table_dir) {
    this.table_dir = table_dir;
    return this;
  }

  public void unsetTable_dir() {
    this.table_dir = null;
  }

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

  public void setTable_dirIsSet(boolean value) {
    if (!value) {
      this.table_dir = null;
    }
  }

  /**
   * If the results are straight from an existing table, the table name.
   */
  public String getIn_tablename() {
    return this.in_tablename;
  }

  /**
   * If the results are straight from an existing table, the table name.
   */
  public ResultsMetadata setIn_tablename(String in_tablename) {
    this.in_tablename = in_tablename;
    return this;
  }

  public void unsetIn_tablename() {
    this.in_tablename = null;
  }

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

  public void setIn_tablenameIsSet(boolean value) {
    if (!value) {
      this.in_tablename = null;
    }
  }

  /**
   * Field delimiter
   */
  public String getDelim() {
    return this.delim;
  }

  /**
   * Field delimiter
   */
  public ResultsMetadata setDelim(String delim) {
    this.delim = delim;
    return this;
  }

  public void unsetDelim() {
    this.delim = null;
  }

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

  public void setDelimIsSet(boolean value) {
    if (!value) {
      this.delim = null;
    }
  }

  public void setFieldValue(_Fields field, Object value) {
    switch (field) {
    case SCHEMA:
      if (value == null) {
        unsetSchema();
      } else {
        setSchema((org.apache.hadoop.hive.metastore.api.Schema)value);
      }
      break;

    case TABLE_DIR:
      if (value == null) {
        unsetTable_dir();
      } else {
        setTable_dir((String)value);
      }
      break;

    case IN_TABLENAME:
      if (value == null) {
        unsetIn_tablename();
      } else {
        setIn_tablename((String)value);
      }
      break;

    case DELIM:
      if (value == null) {
        unsetDelim();
      } else {
        setDelim((String)value);
      }
      break;

    }
  }

  public Object getFieldValue(_Fields field) {
    switch (field) {
    case SCHEMA:
      return getSchema();

    case TABLE_DIR:
      return getTable_dir();

    case IN_TABLENAME:
      return getIn_tablename();

    case DELIM:
      return getDelim();

    }
    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 SCHEMA:
      return isSetSchema();
    case TABLE_DIR:
      return isSetTable_dir();
    case IN_TABLENAME:
      return isSetIn_tablename();
    case DELIM:
      return isSetDelim();
    }
    throw new IllegalStateException();
  }

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

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

    boolean this_present_schema = true && this.isSetSchema();
    boolean that_present_schema = true && that.isSetSchema();
    if (this_present_schema || that_present_schema) {
      if (!(this_present_schema && that_present_schema))
        return false;
      if (!this.schema.equals(that.schema))
        return false;
    }

    boolean this_present_table_dir = true && this.isSetTable_dir();
    boolean that_present_table_dir = true && that.isSetTable_dir();
    if (this_present_table_dir || that_present_table_dir) {
      if (!(this_present_table_dir && that_present_table_dir))
        return false;
      if (!this.table_dir.equals(that.table_dir))
        return false;
    }

    boolean this_present_in_tablename = true && this.isSetIn_tablename();
    boolean that_present_in_tablename = true && that.isSetIn_tablename();
    if (this_present_in_tablename || that_present_in_tablename) {
      if (!(this_present_in_tablename && that_present_in_tablename))
        return false;
      if (!this.in_tablename.equals(that.in_tablename))
        return false;
    }

    boolean this_present_delim = true && this.isSetDelim();
    boolean that_present_delim = true && that.isSetDelim();
    if (this_present_delim || that_present_delim) {
      if (!(this_present_delim && that_present_delim))
        return false;
      if (!this.delim.equals(that.delim))
        return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    HashCodeBuilder builder = new HashCodeBuilder();

    boolean present_schema = true && (isSetSchema());
    builder.append(present_schema);
    if (present_schema)
      builder.append(schema);

    boolean present_table_dir = true && (isSetTable_dir());
    builder.append(present_table_dir);
    if (present_table_dir)
      builder.append(table_dir);

    boolean present_in_tablename = true && (isSetIn_tablename());
    builder.append(present_in_tablename);
    if (present_in_tablename)
      builder.append(in_tablename);

    boolean present_delim = true && (isSetDelim());
    builder.append(present_delim);
    if (present_delim)
      builder.append(delim);

    return builder.toHashCode();
  }

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

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

    lastComparison = Boolean.valueOf(isSetSchema()).compareTo(typedOther.isSetSchema());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetSchema()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.schema, typedOther.schema);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetTable_dir()).compareTo(typedOther.isSetTable_dir());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetTable_dir()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.table_dir, typedOther.table_dir);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetIn_tablename()).compareTo(typedOther.isSetIn_tablename());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetIn_tablename()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.in_tablename, typedOther.in_tablename);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetDelim()).compareTo(typedOther.isSetDelim());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetDelim()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.delim, typedOther.delim);
      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: // SCHEMA
          if (field.type == org.apache.thrift.protocol.TType.STRUCT) {
            this.schema = new org.apache.hadoop.hive.metastore.api.Schema();
            this.schema.read(iprot);
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 2: // TABLE_DIR
          if (field.type == org.apache.thrift.protocol.TType.STRING) {
            this.table_dir = iprot.readString();
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 3: // IN_TABLENAME
          if (field.type == org.apache.thrift.protocol.TType.STRING) {
            this.in_tablename = iprot.readString();
          } else { 
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 4: // DELIM
          if (field.type == org.apache.thrift.protocol.TType.STRING) {
            this.delim = 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.schema != null) {
      oprot.writeFieldBegin(SCHEMA_FIELD_DESC);
      this.schema.write(oprot);
      oprot.writeFieldEnd();
    }
    if (this.table_dir != null) {
      oprot.writeFieldBegin(TABLE_DIR_FIELD_DESC);
      oprot.writeString(this.table_dir);
      oprot.writeFieldEnd();
    }
    if (this.in_tablename != null) {
      oprot.writeFieldBegin(IN_TABLENAME_FIELD_DESC);
      oprot.writeString(this.in_tablename);
      oprot.writeFieldEnd();
    }
    if (this.delim != null) {
      oprot.writeFieldBegin(DELIM_FIELD_DESC);
      oprot.writeString(this.delim);
      oprot.writeFieldEnd();
    }
    oprot.writeFieldStop();
    oprot.writeStructEnd();
  }

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

    sb.append("schema:");
    if (this.schema == null) {
      sb.append("null");
    } else {
      sb.append(this.schema);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("table_dir:");
    if (this.table_dir == null) {
      sb.append("null");
    } else {
      sb.append(this.table_dir);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("in_tablename:");
    if (this.in_tablename == null) {
      sb.append("null");
    } else {
      sb.append(this.in_tablename);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("delim:");
    if (this.delim == null) {
      sb.append("null");
    } else {
      sb.append(this.delim);
    }
    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);
    }
  }

}

