/**
 * Autogenerated by Thrift Compiler (0.9.3)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package org.apache.hadoop.hive.ql.plan.api;

import org.apache.thrift.scheme.IScheme;
import org.apache.thrift.scheme.SchemeFactory;
import org.apache.thrift.scheme.StandardScheme;

import org.apache.thrift.scheme.TupleScheme;
import org.apache.thrift.protocol.TTupleProtocol;
import org.apache.thrift.protocol.TProtocolException;
import org.apache.thrift.EncodingUtils;
import org.apache.thrift.TException;
import org.apache.thrift.async.AsyncMethodCallback;
import org.apache.thrift.server.AbstractNonblockingServer.*;
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 javax.annotation.Generated;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)")
public class Task implements org.apache.thrift.TBase<Task, Task._Fields>, java.io.Serializable, Cloneable, Comparable<Task> {
  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Task");

  private static final org.apache.thrift.protocol.TField TASK_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("taskId", org.apache.thrift.protocol.TType.STRING, (short)1);
  private static final org.apache.thrift.protocol.TField TASK_TYPE_FIELD_DESC = new org.apache.thrift.protocol.TField("taskType", org.apache.thrift.protocol.TType.I32, (short)2);
  private static final org.apache.thrift.protocol.TField TASK_ATTRIBUTES_FIELD_DESC = new org.apache.thrift.protocol.TField("taskAttributes", org.apache.thrift.protocol.TType.MAP, (short)3);
  private static final org.apache.thrift.protocol.TField TASK_COUNTERS_FIELD_DESC = new org.apache.thrift.protocol.TField("taskCounters", org.apache.thrift.protocol.TType.MAP, (short)4);
  private static final org.apache.thrift.protocol.TField OPERATOR_GRAPH_FIELD_DESC = new org.apache.thrift.protocol.TField("operatorGraph", org.apache.thrift.protocol.TType.STRUCT, (short)5);
  private static final org.apache.thrift.protocol.TField OPERATOR_LIST_FIELD_DESC = new org.apache.thrift.protocol.TField("operatorList", org.apache.thrift.protocol.TType.LIST, (short)6);
  private static final org.apache.thrift.protocol.TField DONE_FIELD_DESC = new org.apache.thrift.protocol.TField("done", org.apache.thrift.protocol.TType.BOOL, (short)7);
  private static final org.apache.thrift.protocol.TField STARTED_FIELD_DESC = new org.apache.thrift.protocol.TField("started", org.apache.thrift.protocol.TType.BOOL, (short)8);

  private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
  static {
    schemes.put(StandardScheme.class, new TaskStandardSchemeFactory());
    schemes.put(TupleScheme.class, new TaskTupleSchemeFactory());
  }

  private String taskId; // required
  private TaskType taskType; // required
  private Map<String,String> taskAttributes; // required
  private Map<String,Long> taskCounters; // required
  private Graph operatorGraph; // optional
  private List<Operator> operatorList; // optional
  private boolean done; // required
  private boolean started; // 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 {
    TASK_ID((short)1, "taskId"),
    /**
     * 
     * @see TaskType
     */
    TASK_TYPE((short)2, "taskType"),
    TASK_ATTRIBUTES((short)3, "taskAttributes"),
    TASK_COUNTERS((short)4, "taskCounters"),
    OPERATOR_GRAPH((short)5, "operatorGraph"),
    OPERATOR_LIST((short)6, "operatorList"),
    DONE((short)7, "done"),
    STARTED((short)8, "started");

    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: // TASK_ID
          return TASK_ID;
        case 2: // TASK_TYPE
          return TASK_TYPE;
        case 3: // TASK_ATTRIBUTES
          return TASK_ATTRIBUTES;
        case 4: // TASK_COUNTERS
          return TASK_COUNTERS;
        case 5: // OPERATOR_GRAPH
          return OPERATOR_GRAPH;
        case 6: // OPERATOR_LIST
          return OPERATOR_LIST;
        case 7: // DONE
          return DONE;
        case 8: // STARTED
          return STARTED;
        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
  private static final int __DONE_ISSET_ID = 0;
  private static final int __STARTED_ISSET_ID = 1;
  private byte __isset_bitfield = 0;
  private static final _Fields optionals[] = {_Fields.OPERATOR_GRAPH,_Fields.OPERATOR_LIST};
  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.TASK_ID, new org.apache.thrift.meta_data.FieldMetaData("taskId", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    tmpMap.put(_Fields.TASK_TYPE, new org.apache.thrift.meta_data.FieldMetaData("taskType", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.EnumMetaData(org.apache.thrift.protocol.TType.ENUM, TaskType.class)));
    tmpMap.put(_Fields.TASK_ATTRIBUTES, new org.apache.thrift.meta_data.FieldMetaData("taskAttributes", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.MapMetaData(org.apache.thrift.protocol.TType.MAP, 
            new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING), 
            new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))));
    tmpMap.put(_Fields.TASK_COUNTERS, new org.apache.thrift.meta_data.FieldMetaData("taskCounters", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.MapMetaData(org.apache.thrift.protocol.TType.MAP, 
            new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING), 
            new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))));
    tmpMap.put(_Fields.OPERATOR_GRAPH, new org.apache.thrift.meta_data.FieldMetaData("operatorGraph", org.apache.thrift.TFieldRequirementType.OPTIONAL, 
        new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, Graph.class)));
    tmpMap.put(_Fields.OPERATOR_LIST, new org.apache.thrift.meta_data.FieldMetaData("operatorList", org.apache.thrift.TFieldRequirementType.OPTIONAL, 
        new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, 
            new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, Operator.class))));
    tmpMap.put(_Fields.DONE, new org.apache.thrift.meta_data.FieldMetaData("done", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BOOL)));
    tmpMap.put(_Fields.STARTED, new org.apache.thrift.meta_data.FieldMetaData("started", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BOOL)));
    metaDataMap = Collections.unmodifiableMap(tmpMap);
    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Task.class, metaDataMap);
  }

  public Task() {
  }

  public Task(
    String taskId,
    TaskType taskType,
    Map<String,String> taskAttributes,
    Map<String,Long> taskCounters,
    boolean done,
    boolean started)
  {
    this();
    this.taskId = taskId;
    this.taskType = taskType;
    this.taskAttributes = taskAttributes;
    this.taskCounters = taskCounters;
    this.done = done;
    setDoneIsSet(true);
    this.started = started;
    setStartedIsSet(true);
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public Task(Task other) {
    __isset_bitfield = other.__isset_bitfield;
    if (other.isSetTaskId()) {
      this.taskId = other.taskId;
    }
    if (other.isSetTaskType()) {
      this.taskType = other.taskType;
    }
    if (other.isSetTaskAttributes()) {
      Map<String,String> __this__taskAttributes = new HashMap<String,String>(other.taskAttributes);
      this.taskAttributes = __this__taskAttributes;
    }
    if (other.isSetTaskCounters()) {
      Map<String,Long> __this__taskCounters = new HashMap<String,Long>(other.taskCounters);
      this.taskCounters = __this__taskCounters;
    }
    if (other.isSetOperatorGraph()) {
      this.operatorGraph = new Graph(other.operatorGraph);
    }
    if (other.isSetOperatorList()) {
      List<Operator> __this__operatorList = new ArrayList<Operator>(other.operatorList.size());
      for (Operator other_element : other.operatorList) {
        __this__operatorList.add(new Operator(other_element));
      }
      this.operatorList = __this__operatorList;
    }
    this.done = other.done;
    this.started = other.started;
  }

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

  @Override
  public void clear() {
    this.taskId = null;
    this.taskType = null;
    this.taskAttributes = null;
    this.taskCounters = null;
    this.operatorGraph = null;
    this.operatorList = null;
    setDoneIsSet(false);
    this.done = false;
    setStartedIsSet(false);
    this.started = false;
  }

  public String getTaskId() {
    return this.taskId;
  }

  public void setTaskId(String taskId) {
    this.taskId = taskId;
  }

  public void unsetTaskId() {
    this.taskId = null;
  }

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

  public void setTaskIdIsSet(boolean value) {
    if (!value) {
      this.taskId = null;
    }
  }

  /**
   * 
   * @see TaskType
   */
  public TaskType getTaskType() {
    return this.taskType;
  }

  /**
   * 
   * @see TaskType
   */
  public void setTaskType(TaskType taskType) {
    this.taskType = taskType;
  }

  public void unsetTaskType() {
    this.taskType = null;
  }

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

  public void setTaskTypeIsSet(boolean value) {
    if (!value) {
      this.taskType = null;
    }
  }

  public int getTaskAttributesSize() {
    return (this.taskAttributes == null) ? 0 : this.taskAttributes.size();
  }

  public void putToTaskAttributes(String key, String val) {
    if (this.taskAttributes == null) {
      this.taskAttributes = new HashMap<String,String>();
    }
    this.taskAttributes.put(key, val);
  }

  public Map<String,String> getTaskAttributes() {
    return this.taskAttributes;
  }

  public void setTaskAttributes(Map<String,String> taskAttributes) {
    this.taskAttributes = taskAttributes;
  }

  public void unsetTaskAttributes() {
    this.taskAttributes = null;
  }

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

  public void setTaskAttributesIsSet(boolean value) {
    if (!value) {
      this.taskAttributes = null;
    }
  }

  public int getTaskCountersSize() {
    return (this.taskCounters == null) ? 0 : this.taskCounters.size();
  }

  public void putToTaskCounters(String key, long val) {
    if (this.taskCounters == null) {
      this.taskCounters = new HashMap<String,Long>();
    }
    this.taskCounters.put(key, val);
  }

  public Map<String,Long> getTaskCounters() {
    return this.taskCounters;
  }

  public void setTaskCounters(Map<String,Long> taskCounters) {
    this.taskCounters = taskCounters;
  }

  public void unsetTaskCounters() {
    this.taskCounters = null;
  }

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

  public void setTaskCountersIsSet(boolean value) {
    if (!value) {
      this.taskCounters = null;
    }
  }

  public Graph getOperatorGraph() {
    return this.operatorGraph;
  }

  public void setOperatorGraph(Graph operatorGraph) {
    this.operatorGraph = operatorGraph;
  }

  public void unsetOperatorGraph() {
    this.operatorGraph = null;
  }

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

  public void setOperatorGraphIsSet(boolean value) {
    if (!value) {
      this.operatorGraph = null;
    }
  }

  public int getOperatorListSize() {
    return (this.operatorList == null) ? 0 : this.operatorList.size();
  }

  public java.util.Iterator<Operator> getOperatorListIterator() {
    return (this.operatorList == null) ? null : this.operatorList.iterator();
  }

  public void addToOperatorList(Operator elem) {
    if (this.operatorList == null) {
      this.operatorList = new ArrayList<Operator>();
    }
    this.operatorList.add(elem);
  }

  public List<Operator> getOperatorList() {
    return this.operatorList;
  }

  public void setOperatorList(List<Operator> operatorList) {
    this.operatorList = operatorList;
  }

  public void unsetOperatorList() {
    this.operatorList = null;
  }

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

  public void setOperatorListIsSet(boolean value) {
    if (!value) {
      this.operatorList = null;
    }
  }

  public boolean isDone() {
    return this.done;
  }

  public void setDone(boolean done) {
    this.done = done;
    setDoneIsSet(true);
  }

  public void unsetDone() {
    __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __DONE_ISSET_ID);
  }

  /** Returns true if field done is set (has been assigned a value) and false otherwise */
  public boolean isSetDone() {
    return EncodingUtils.testBit(__isset_bitfield, __DONE_ISSET_ID);
  }

  public void setDoneIsSet(boolean value) {
    __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __DONE_ISSET_ID, value);
  }

  public boolean isStarted() {
    return this.started;
  }

  public void setStarted(boolean started) {
    this.started = started;
    setStartedIsSet(true);
  }

  public void unsetStarted() {
    __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __STARTED_ISSET_ID);
  }

  /** Returns true if field started is set (has been assigned a value) and false otherwise */
  public boolean isSetStarted() {
    return EncodingUtils.testBit(__isset_bitfield, __STARTED_ISSET_ID);
  }

  public void setStartedIsSet(boolean value) {
    __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __STARTED_ISSET_ID, value);
  }

  public void setFieldValue(_Fields field, Object value) {
    switch (field) {
    case TASK_ID:
      if (value == null) {
        unsetTaskId();
      } else {
        setTaskId((String)value);
      }
      break;

    case TASK_TYPE:
      if (value == null) {
        unsetTaskType();
      } else {
        setTaskType((TaskType)value);
      }
      break;

    case TASK_ATTRIBUTES:
      if (value == null) {
        unsetTaskAttributes();
      } else {
        setTaskAttributes((Map<String,String>)value);
      }
      break;

    case TASK_COUNTERS:
      if (value == null) {
        unsetTaskCounters();
      } else {
        setTaskCounters((Map<String,Long>)value);
      }
      break;

    case OPERATOR_GRAPH:
      if (value == null) {
        unsetOperatorGraph();
      } else {
        setOperatorGraph((Graph)value);
      }
      break;

    case OPERATOR_LIST:
      if (value == null) {
        unsetOperatorList();
      } else {
        setOperatorList((List<Operator>)value);
      }
      break;

    case DONE:
      if (value == null) {
        unsetDone();
      } else {
        setDone((Boolean)value);
      }
      break;

    case STARTED:
      if (value == null) {
        unsetStarted();
      } else {
        setStarted((Boolean)value);
      }
      break;

    }
  }

  public Object getFieldValue(_Fields field) {
    switch (field) {
    case TASK_ID:
      return getTaskId();

    case TASK_TYPE:
      return getTaskType();

    case TASK_ATTRIBUTES:
      return getTaskAttributes();

    case TASK_COUNTERS:
      return getTaskCounters();

    case OPERATOR_GRAPH:
      return getOperatorGraph();

    case OPERATOR_LIST:
      return getOperatorList();

    case DONE:
      return isDone();

    case STARTED:
      return isStarted();

    }
    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 TASK_ID:
      return isSetTaskId();
    case TASK_TYPE:
      return isSetTaskType();
    case TASK_ATTRIBUTES:
      return isSetTaskAttributes();
    case TASK_COUNTERS:
      return isSetTaskCounters();
    case OPERATOR_GRAPH:
      return isSetOperatorGraph();
    case OPERATOR_LIST:
      return isSetOperatorList();
    case DONE:
      return isSetDone();
    case STARTED:
      return isSetStarted();
    }
    throw new IllegalStateException();
  }

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

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

    boolean this_present_taskId = true && this.isSetTaskId();
    boolean that_present_taskId = true && that.isSetTaskId();
    if (this_present_taskId || that_present_taskId) {
      if (!(this_present_taskId && that_present_taskId))
        return false;
      if (!this.taskId.equals(that.taskId))
        return false;
    }

    boolean this_present_taskType = true && this.isSetTaskType();
    boolean that_present_taskType = true && that.isSetTaskType();
    if (this_present_taskType || that_present_taskType) {
      if (!(this_present_taskType && that_present_taskType))
        return false;
      if (!this.taskType.equals(that.taskType))
        return false;
    }

    boolean this_present_taskAttributes = true && this.isSetTaskAttributes();
    boolean that_present_taskAttributes = true && that.isSetTaskAttributes();
    if (this_present_taskAttributes || that_present_taskAttributes) {
      if (!(this_present_taskAttributes && that_present_taskAttributes))
        return false;
      if (!this.taskAttributes.equals(that.taskAttributes))
        return false;
    }

    boolean this_present_taskCounters = true && this.isSetTaskCounters();
    boolean that_present_taskCounters = true && that.isSetTaskCounters();
    if (this_present_taskCounters || that_present_taskCounters) {
      if (!(this_present_taskCounters && that_present_taskCounters))
        return false;
      if (!this.taskCounters.equals(that.taskCounters))
        return false;
    }

    boolean this_present_operatorGraph = true && this.isSetOperatorGraph();
    boolean that_present_operatorGraph = true && that.isSetOperatorGraph();
    if (this_present_operatorGraph || that_present_operatorGraph) {
      if (!(this_present_operatorGraph && that_present_operatorGraph))
        return false;
      if (!this.operatorGraph.equals(that.operatorGraph))
        return false;
    }

    boolean this_present_operatorList = true && this.isSetOperatorList();
    boolean that_present_operatorList = true && that.isSetOperatorList();
    if (this_present_operatorList || that_present_operatorList) {
      if (!(this_present_operatorList && that_present_operatorList))
        return false;
      if (!this.operatorList.equals(that.operatorList))
        return false;
    }

    boolean this_present_done = true;
    boolean that_present_done = true;
    if (this_present_done || that_present_done) {
      if (!(this_present_done && that_present_done))
        return false;
      if (this.done != that.done)
        return false;
    }

    boolean this_present_started = true;
    boolean that_present_started = true;
    if (this_present_started || that_present_started) {
      if (!(this_present_started && that_present_started))
        return false;
      if (this.started != that.started)
        return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    List<Object> list = new ArrayList<Object>();

    boolean present_taskId = true && (isSetTaskId());
    list.add(present_taskId);
    if (present_taskId)
      list.add(taskId);

    boolean present_taskType = true && (isSetTaskType());
    list.add(present_taskType);
    if (present_taskType)
      list.add(taskType.getValue());

    boolean present_taskAttributes = true && (isSetTaskAttributes());
    list.add(present_taskAttributes);
    if (present_taskAttributes)
      list.add(taskAttributes);

    boolean present_taskCounters = true && (isSetTaskCounters());
    list.add(present_taskCounters);
    if (present_taskCounters)
      list.add(taskCounters);

    boolean present_operatorGraph = true && (isSetOperatorGraph());
    list.add(present_operatorGraph);
    if (present_operatorGraph)
      list.add(operatorGraph);

    boolean present_operatorList = true && (isSetOperatorList());
    list.add(present_operatorList);
    if (present_operatorList)
      list.add(operatorList);

    boolean present_done = true;
    list.add(present_done);
    if (present_done)
      list.add(done);

    boolean present_started = true;
    list.add(present_started);
    if (present_started)
      list.add(started);

    return list.hashCode();
  }

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

    int lastComparison = 0;

    lastComparison = Boolean.valueOf(isSetTaskId()).compareTo(other.isSetTaskId());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetTaskId()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.taskId, other.taskId);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetTaskType()).compareTo(other.isSetTaskType());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetTaskType()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.taskType, other.taskType);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetTaskAttributes()).compareTo(other.isSetTaskAttributes());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetTaskAttributes()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.taskAttributes, other.taskAttributes);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetTaskCounters()).compareTo(other.isSetTaskCounters());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetTaskCounters()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.taskCounters, other.taskCounters);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetOperatorGraph()).compareTo(other.isSetOperatorGraph());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetOperatorGraph()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.operatorGraph, other.operatorGraph);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetOperatorList()).compareTo(other.isSetOperatorList());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetOperatorList()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.operatorList, other.operatorList);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetDone()).compareTo(other.isSetDone());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetDone()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.done, other.done);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetStarted()).compareTo(other.isSetStarted());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetStarted()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.started, other.started);
      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 {
    schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
  }

  public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
    schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
  }

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

    sb.append("taskId:");
    if (this.taskId == null) {
      sb.append("null");
    } else {
      sb.append(this.taskId);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("taskType:");
    if (this.taskType == null) {
      sb.append("null");
    } else {
      sb.append(this.taskType);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("taskAttributes:");
    if (this.taskAttributes == null) {
      sb.append("null");
    } else {
      sb.append(this.taskAttributes);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("taskCounters:");
    if (this.taskCounters == null) {
      sb.append("null");
    } else {
      sb.append(this.taskCounters);
    }
    first = false;
    if (isSetOperatorGraph()) {
      if (!first) sb.append(", ");
      sb.append("operatorGraph:");
      if (this.operatorGraph == null) {
        sb.append("null");
      } else {
        sb.append(this.operatorGraph);
      }
      first = false;
    }
    if (isSetOperatorList()) {
      if (!first) sb.append(", ");
      sb.append("operatorList:");
      if (this.operatorList == null) {
        sb.append("null");
      } else {
        sb.append(this.operatorList);
      }
      first = false;
    }
    if (!first) sb.append(", ");
    sb.append("done:");
    sb.append(this.done);
    first = false;
    if (!first) sb.append(", ");
    sb.append("started:");
    sb.append(this.started);
    first = false;
    sb.append(")");
    return sb.toString();
  }

  public void validate() throws org.apache.thrift.TException {
    // check for required fields
    // check for sub-struct validity
    if (operatorGraph != null) {
      operatorGraph.validate();
    }
  }

  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 {
      // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor.
      __isset_bitfield = 0;
      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);
    }
  }

  private static class TaskStandardSchemeFactory implements SchemeFactory {
    public TaskStandardScheme getScheme() {
      return new TaskStandardScheme();
    }
  }

  private static class TaskStandardScheme extends StandardScheme<Task> {

    public void read(org.apache.thrift.protocol.TProtocol iprot, Task struct) throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TField schemeField;
      iprot.readStructBegin();
      while (true)
      {
        schemeField = iprot.readFieldBegin();
        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
          break;
        }
        switch (schemeField.id) {
          case 1: // TASK_ID
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.taskId = iprot.readString();
              struct.setTaskIdIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 2: // TASK_TYPE
            if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
              struct.taskType = org.apache.hadoop.hive.ql.plan.api.TaskType.findByValue(iprot.readI32());
              struct.setTaskTypeIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 3: // TASK_ATTRIBUTES
            if (schemeField.type == org.apache.thrift.protocol.TType.MAP) {
              {
                org.apache.thrift.protocol.TMap _map44 = iprot.readMapBegin();
                struct.taskAttributes = new HashMap<String,String>(2*_map44.size);
                String _key45;
                String _val46;
                for (int _i47 = 0; _i47 < _map44.size; ++_i47)
                {
                  _key45 = iprot.readString();
                  _val46 = iprot.readString();
                  struct.taskAttributes.put(_key45, _val46);
                }
                iprot.readMapEnd();
              }
              struct.setTaskAttributesIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 4: // TASK_COUNTERS
            if (schemeField.type == org.apache.thrift.protocol.TType.MAP) {
              {
                org.apache.thrift.protocol.TMap _map48 = iprot.readMapBegin();
                struct.taskCounters = new HashMap<String,Long>(2*_map48.size);
                String _key49;
                long _val50;
                for (int _i51 = 0; _i51 < _map48.size; ++_i51)
                {
                  _key49 = iprot.readString();
                  _val50 = iprot.readI64();
                  struct.taskCounters.put(_key49, _val50);
                }
                iprot.readMapEnd();
              }
              struct.setTaskCountersIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 5: // OPERATOR_GRAPH
            if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
              struct.operatorGraph = new Graph();
              struct.operatorGraph.read(iprot);
              struct.setOperatorGraphIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 6: // OPERATOR_LIST
            if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
              {
                org.apache.thrift.protocol.TList _list52 = iprot.readListBegin();
                struct.operatorList = new ArrayList<Operator>(_list52.size);
                Operator _elem53;
                for (int _i54 = 0; _i54 < _list52.size; ++_i54)
                {
                  _elem53 = new Operator();
                  _elem53.read(iprot);
                  struct.operatorList.add(_elem53);
                }
                iprot.readListEnd();
              }
              struct.setOperatorListIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 7: // DONE
            if (schemeField.type == org.apache.thrift.protocol.TType.BOOL) {
              struct.done = iprot.readBool();
              struct.setDoneIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 8: // STARTED
            if (schemeField.type == org.apache.thrift.protocol.TType.BOOL) {
              struct.started = iprot.readBool();
              struct.setStartedIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          default:
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();
      struct.validate();
    }

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

      oprot.writeStructBegin(STRUCT_DESC);
      if (struct.taskId != null) {
        oprot.writeFieldBegin(TASK_ID_FIELD_DESC);
        oprot.writeString(struct.taskId);
        oprot.writeFieldEnd();
      }
      if (struct.taskType != null) {
        oprot.writeFieldBegin(TASK_TYPE_FIELD_DESC);
        oprot.writeI32(struct.taskType.getValue());
        oprot.writeFieldEnd();
      }
      if (struct.taskAttributes != null) {
        oprot.writeFieldBegin(TASK_ATTRIBUTES_FIELD_DESC);
        {
          oprot.writeMapBegin(new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.STRING, struct.taskAttributes.size()));
          for (Map.Entry<String, String> _iter55 : struct.taskAttributes.entrySet())
          {
            oprot.writeString(_iter55.getKey());
            oprot.writeString(_iter55.getValue());
          }
          oprot.writeMapEnd();
        }
        oprot.writeFieldEnd();
      }
      if (struct.taskCounters != null) {
        oprot.writeFieldBegin(TASK_COUNTERS_FIELD_DESC);
        {
          oprot.writeMapBegin(new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.I64, struct.taskCounters.size()));
          for (Map.Entry<String, Long> _iter56 : struct.taskCounters.entrySet())
          {
            oprot.writeString(_iter56.getKey());
            oprot.writeI64(_iter56.getValue());
          }
          oprot.writeMapEnd();
        }
        oprot.writeFieldEnd();
      }
      if (struct.operatorGraph != null) {
        if (struct.isSetOperatorGraph()) {
          oprot.writeFieldBegin(OPERATOR_GRAPH_FIELD_DESC);
          struct.operatorGraph.write(oprot);
          oprot.writeFieldEnd();
        }
      }
      if (struct.operatorList != null) {
        if (struct.isSetOperatorList()) {
          oprot.writeFieldBegin(OPERATOR_LIST_FIELD_DESC);
          {
            oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.operatorList.size()));
            for (Operator _iter57 : struct.operatorList)
            {
              _iter57.write(oprot);
            }
            oprot.writeListEnd();
          }
          oprot.writeFieldEnd();
        }
      }
      oprot.writeFieldBegin(DONE_FIELD_DESC);
      oprot.writeBool(struct.done);
      oprot.writeFieldEnd();
      oprot.writeFieldBegin(STARTED_FIELD_DESC);
      oprot.writeBool(struct.started);
      oprot.writeFieldEnd();
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }

  }

  private static class TaskTupleSchemeFactory implements SchemeFactory {
    public TaskTupleScheme getScheme() {
      return new TaskTupleScheme();
    }
  }

  private static class TaskTupleScheme extends TupleScheme<Task> {

    @Override
    public void write(org.apache.thrift.protocol.TProtocol prot, Task struct) throws org.apache.thrift.TException {
      TTupleProtocol oprot = (TTupleProtocol) prot;
      BitSet optionals = new BitSet();
      if (struct.isSetTaskId()) {
        optionals.set(0);
      }
      if (struct.isSetTaskType()) {
        optionals.set(1);
      }
      if (struct.isSetTaskAttributes()) {
        optionals.set(2);
      }
      if (struct.isSetTaskCounters()) {
        optionals.set(3);
      }
      if (struct.isSetOperatorGraph()) {
        optionals.set(4);
      }
      if (struct.isSetOperatorList()) {
        optionals.set(5);
      }
      if (struct.isSetDone()) {
        optionals.set(6);
      }
      if (struct.isSetStarted()) {
        optionals.set(7);
      }
      oprot.writeBitSet(optionals, 8);
      if (struct.isSetTaskId()) {
        oprot.writeString(struct.taskId);
      }
      if (struct.isSetTaskType()) {
        oprot.writeI32(struct.taskType.getValue());
      }
      if (struct.isSetTaskAttributes()) {
        {
          oprot.writeI32(struct.taskAttributes.size());
          for (Map.Entry<String, String> _iter58 : struct.taskAttributes.entrySet())
          {
            oprot.writeString(_iter58.getKey());
            oprot.writeString(_iter58.getValue());
          }
        }
      }
      if (struct.isSetTaskCounters()) {
        {
          oprot.writeI32(struct.taskCounters.size());
          for (Map.Entry<String, Long> _iter59 : struct.taskCounters.entrySet())
          {
            oprot.writeString(_iter59.getKey());
            oprot.writeI64(_iter59.getValue());
          }
        }
      }
      if (struct.isSetOperatorGraph()) {
        struct.operatorGraph.write(oprot);
      }
      if (struct.isSetOperatorList()) {
        {
          oprot.writeI32(struct.operatorList.size());
          for (Operator _iter60 : struct.operatorList)
          {
            _iter60.write(oprot);
          }
        }
      }
      if (struct.isSetDone()) {
        oprot.writeBool(struct.done);
      }
      if (struct.isSetStarted()) {
        oprot.writeBool(struct.started);
      }
    }

    @Override
    public void read(org.apache.thrift.protocol.TProtocol prot, Task struct) throws org.apache.thrift.TException {
      TTupleProtocol iprot = (TTupleProtocol) prot;
      BitSet incoming = iprot.readBitSet(8);
      if (incoming.get(0)) {
        struct.taskId = iprot.readString();
        struct.setTaskIdIsSet(true);
      }
      if (incoming.get(1)) {
        struct.taskType = org.apache.hadoop.hive.ql.plan.api.TaskType.findByValue(iprot.readI32());
        struct.setTaskTypeIsSet(true);
      }
      if (incoming.get(2)) {
        {
          org.apache.thrift.protocol.TMap _map61 = new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.STRING, iprot.readI32());
          struct.taskAttributes = new HashMap<String,String>(2*_map61.size);
          String _key62;
          String _val63;
          for (int _i64 = 0; _i64 < _map61.size; ++_i64)
          {
            _key62 = iprot.readString();
            _val63 = iprot.readString();
            struct.taskAttributes.put(_key62, _val63);
          }
        }
        struct.setTaskAttributesIsSet(true);
      }
      if (incoming.get(3)) {
        {
          org.apache.thrift.protocol.TMap _map65 = new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.I64, iprot.readI32());
          struct.taskCounters = new HashMap<String,Long>(2*_map65.size);
          String _key66;
          long _val67;
          for (int _i68 = 0; _i68 < _map65.size; ++_i68)
          {
            _key66 = iprot.readString();
            _val67 = iprot.readI64();
            struct.taskCounters.put(_key66, _val67);
          }
        }
        struct.setTaskCountersIsSet(true);
      }
      if (incoming.get(4)) {
        struct.operatorGraph = new Graph();
        struct.operatorGraph.read(iprot);
        struct.setOperatorGraphIsSet(true);
      }
      if (incoming.get(5)) {
        {
          org.apache.thrift.protocol.TList _list69 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
          struct.operatorList = new ArrayList<Operator>(_list69.size);
          Operator _elem70;
          for (int _i71 = 0; _i71 < _list69.size; ++_i71)
          {
            _elem70 = new Operator();
            _elem70.read(iprot);
            struct.operatorList.add(_elem70);
          }
        }
        struct.setOperatorListIsSet(true);
      }
      if (incoming.get(6)) {
        struct.done = iprot.readBool();
        struct.setDoneIsSet(true);
      }
      if (incoming.get(7)) {
        struct.started = iprot.readBool();
        struct.setStartedIsSet(true);
      }
    }
  }

}

