/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package com.facebook.thrift.annotation_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.*;

/**
 * Changes the priority of this function (default NORMAL).
 */
@SuppressWarnings({ "unused", "serial" })
public class Priority implements TBase, java.io.Serializable, Cloneable, Comparable<Priority> {
  private static final TStruct STRUCT_DESC = new TStruct("Priority");
  private static final TField LEVEL_FIELD_DESC = new TField("level", TType.I32, (short)1);

  /**
   * 
   * @see RpcPriority
   */
  public RpcPriority level;
  public static final int LEVEL = 1;

  // isset id assignments

  public static final Map<Integer, FieldMetaData> metaDataMap;

  static {
    Map<Integer, FieldMetaData> tmpMetaDataMap = new HashMap<Integer, FieldMetaData>();
    tmpMetaDataMap.put(LEVEL, new FieldMetaData("level", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.I32)));
    metaDataMap = Collections.unmodifiableMap(tmpMetaDataMap);
  }

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

  public Priority() {
  }

  public Priority(
      RpcPriority level) {
    this();
    this.level = level;
  }

  public static class Builder {
    private RpcPriority level;

    public Builder() {
    }

    public Builder setLevel(final RpcPriority level) {
      this.level = level;
      return this;
    }

    public Priority build() {
      Priority result = new Priority();
      result.setLevel(this.level);
      return result;
    }
  }

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

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public Priority(Priority other) {
    if (other.isSetLevel()) {
      this.level = TBaseHelper.deepCopy(other.level);
    }
  }

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

  /**
   * 
   * @see RpcPriority
   */
  public RpcPriority getLevel() {
    return this.level;
  }

  /**
   * 
   * @see RpcPriority
   */
  public Priority setLevel(RpcPriority level) {
    this.level = level;
    return this;
  }

  public void unsetLevel() {
    this.level = null;
  }

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

  public void setLevelIsSet(boolean __value) {
    if (!__value) {
      this.level = null;
    }
  }

  public void setFieldValue(int fieldID, Object __value) {
    switch (fieldID) {
    case LEVEL:
      if (__value == null) {
        unsetLevel();
      } else {
        setLevel((RpcPriority)__value);
      }
      break;

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

  public Object getFieldValue(int fieldID) {
    switch (fieldID) {
    case LEVEL:
      return getLevel();

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

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

    return true;
  }

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

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

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

    lastComparison = Boolean.valueOf(isSetLevel()).compareTo(other.isSetLevel());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(level, other.level);
    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 LEVEL:
          if (__field.type == TType.I32) {
            this.level = RpcPriority.findByValue(iprot.readI32());
          } 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.level != null) {
      oprot.writeFieldBegin(LEVEL_FIELD_DESC);
      oprot.writeI32(this.level == null ? 0 : this.level.getValue());
      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("Priority");
    sb.append(space);
    sb.append("(");
    sb.append(newLine);
    boolean first = true;

    sb.append(indentStr);
    sb.append("level");
    sb.append(space);
    sb.append(":").append(space);
    if (this.getLevel() == null) {
      sb.append("null");
    } else {
      String level_name = this.getLevel() == null ? "null" : this.getLevel().name();
      if (level_name != null) {
        sb.append(level_name);
        sb.append(" (");
      }
      sb.append(this.getLevel());
      if (level_name != null) {
        sb.append(")");
      }
    }
    first = false;
    sb.append(newLine + TBaseHelper.reduceIndent(indentStr));
    sb.append(")");
    return sb.toString();
  }

  public void validate() throws TException {
    // check for required fields
  }

}

