/**
 * 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.*;

/**
 * Annotate a thrift structured or enum to indicate if ids or values should not
 * be used.
 * 
 * For example, you may want to mark ids as deprecated, or these ids
 * might be reserved for other use cases or annotations.
 * 
 * The resolved set of disallowed ids is the union of the values in `ids` and
 * the range of values represented in `id_ranges`. Example:
 * 
 *  // These ids are not allowed: 3, 8, half-open ranges [10, 15), [20, 30)
 *  @thrift.ReserveIds{ids = [3, 8], id_ranges = {10: 15, 20: 30}}
 *  struct Foo {
 *    ...
 *    3: i64 f; // Build failure: 3 cannot be used
 *  }
 */
@SuppressWarnings({ "unused", "serial" })
public class ReserveIds implements TBase, java.io.Serializable, Cloneable {
  private static final TStruct STRUCT_DESC = new TStruct("ReserveIds");
  private static final TField IDS_FIELD_DESC = new TField("ids", TType.LIST, (short)1);
  private static final TField ID_RANGES_FIELD_DESC = new TField("id_ranges", TType.MAP, (short)2);

  /**
   * Individual ids that cannot be used.
   */
  public final List<Integer> ids;
  /**
   * Represents ranges of ids that cannot be used.
   * 
   * Each (key: value) pair represents the half-open range `[key, value)`,
   * where `key` is included and `value` is not. For example, the map
   * `{10: 15, 20: 30}` represents the union of id/value ranges `[10, 15)` and
   * `[20, 30)`.
   */
  public final Map<Integer,Integer> id_ranges;
  public static final int IDS = 1;
  public static final int ID_RANGES = 2;

  public ReserveIds(
      List<Integer> ids,
      Map<Integer,Integer> id_ranges) {
    this.ids = ids;
    this.id_ranges = id_ranges;
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public ReserveIds(ReserveIds other) {
    if (other.isSetIds()) {
      this.ids = TBaseHelper.deepCopy(other.ids);
    } else {
      this.ids = null;
    }
    if (other.isSetId_ranges()) {
      this.id_ranges = TBaseHelper.deepCopy(other.id_ranges);
    } else {
      this.id_ranges = null;
    }
  }

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

  /**
   * Individual ids that cannot be used.
   */
  public List<Integer> getIds() {
    return this.ids;
  }

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

  /**
   * Represents ranges of ids that cannot be used.
   * 
   * Each (key: value) pair represents the half-open range `[key, value)`,
   * where `key` is included and `value` is not. For example, the map
   * `{10: 15, 20: 30}` represents the union of id/value ranges `[10, 15)` and
   * `[20, 30)`.
   */
  public Map<Integer,Integer> getId_ranges() {
    return this.id_ranges;
  }

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

  @Override
  public boolean equals(Object _that) {
    if (_that == null)
      return false;
    if (this == _that)
      return true;
    if (!(_that instanceof ReserveIds))
      return false;
    ReserveIds that = (ReserveIds)_that;

    if (!TBaseHelper.equalsNobinary(this.isSetIds(), that.isSetIds(), this.ids, that.ids)) { return false; }

    if (!TBaseHelper.equalsNobinary(this.isSetId_ranges(), that.isSetId_ranges(), this.id_ranges, that.id_ranges)) { return false; }

    return true;
  }

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

  // This is required to satisfy the TBase interface, but can't be implemented on immutable struture.
  public void read(TProtocol iprot) throws TException {
    throw new TException("unimplemented in android immutable structure");
  }

  public static ReserveIds deserialize(TProtocol iprot) throws TException {
    List<Integer> tmp_ids = null;
    Map<Integer,Integer> tmp_id_ranges = null;
    TField __field;
    iprot.readStructBegin();
    while (true)
    {
      __field = iprot.readFieldBegin();
      if (__field.type == TType.STOP) {
        break;
      }
      switch (__field.id)
      {
        case IDS:
          if (__field.type == TType.LIST) {
            {
              TList _list0 = iprot.readListBegin();
              tmp_ids = new ArrayList<Integer>(Math.max(0, _list0.size));
              for (int _i1 = 0; 
                   (_list0.size < 0) ? iprot.peekList() : (_i1 < _list0.size); 
                   ++_i1)
              {
                Integer _elem2;
                _elem2 = iprot.readI32();
                tmp_ids.add(_elem2);
              }
              iprot.readListEnd();
            }
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case ID_RANGES:
          if (__field.type == TType.MAP) {
            {
              TMap _map3 = iprot.readMapBegin();
              tmp_id_ranges = new HashMap<Integer,Integer>(Math.max(0, 2*_map3.size));
              for (int _i4 = 0; 
                   (_map3.size < 0) ? iprot.peekMap() : (_i4 < _map3.size); 
                   ++_i4)
              {
                Integer _key5;
                Integer _val6;
                _key5 = iprot.readI32();
                _val6 = iprot.readI32();
                tmp_id_ranges.put(_key5, _val6);
              }
              iprot.readMapEnd();
            }
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        default:
          TProtocolUtil.skip(iprot, __field.type);
          break;
      }
      iprot.readFieldEnd();
    }
    iprot.readStructEnd();

    ReserveIds _that;
    _that = new ReserveIds(
      tmp_ids
      ,tmp_id_ranges
    );
    _that.validate();
    return _that;
  }

  public void write(TProtocol oprot) throws TException {
    validate();

    oprot.writeStructBegin(STRUCT_DESC);
    if (this.ids != null) {
      oprot.writeFieldBegin(IDS_FIELD_DESC);
      {
        oprot.writeListBegin(new TList(TType.I32, this.ids.size()));
        for (Integer _iter7 : this.ids)        {
          oprot.writeI32(_iter7);
        }
        oprot.writeListEnd();
      }
      oprot.writeFieldEnd();
    }
    if (this.id_ranges != null) {
      oprot.writeFieldBegin(ID_RANGES_FIELD_DESC);
      {
        oprot.writeMapBegin(new TMap(TType.I32, TType.I32, this.id_ranges.size()));
        for (Map.Entry<Integer, Integer> _iter8 : this.id_ranges.entrySet())        {
          oprot.writeI32(_iter8.getKey());
          oprot.writeI32(_iter8.getValue());
        }
        oprot.writeMapEnd();
      }
      oprot.writeFieldEnd();
    }
    oprot.writeFieldStop();
    oprot.writeStructEnd();
  }

  @Override
  public String toString() {
    return toString(1, true);
  }

  @Override
  public String toString(int indent, boolean prettyPrint) {
    return TBaseHelper.toStringHelper(this, indent, prettyPrint);
  }

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

}

