/**
 * Autogenerated by Thrift Compiler (0.20.0)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package com.jetbrains.cef.remote.thrift_codegen;

@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})
public class Range implements com.jetbrains.cef.remote.thrift.TBase<Range, Range._Fields>, java.io.Serializable, Cloneable, Comparable<Range> {
  private static final com.jetbrains.cef.remote.thrift.protocol.TStruct STRUCT_DESC = new com.jetbrains.cef.remote.thrift.protocol.TStruct("Range");

  private static final com.jetbrains.cef.remote.thrift.protocol.TField FROM_FIELD_DESC = new com.jetbrains.cef.remote.thrift.protocol.TField("from", com.jetbrains.cef.remote.thrift.protocol.TType.I64, (short)1);
  private static final com.jetbrains.cef.remote.thrift.protocol.TField TO_FIELD_DESC = new com.jetbrains.cef.remote.thrift.protocol.TField("to", com.jetbrains.cef.remote.thrift.protocol.TType.I64, (short)2);

  private static final com.jetbrains.cef.remote.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new RangeStandardSchemeFactory();
  private static final com.jetbrains.cef.remote.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new RangeTupleSchemeFactory();

  public long from; // required
  public long to; // required

  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
  public enum _Fields implements com.jetbrains.cef.remote.thrift.TFieldIdEnum {
    FROM((short)1, "from"),
    TO((short)2, "to");

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

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

    /**
     * Find the _Fields constant that matches fieldId, or null if its not found.
     */
    @com.jetbrains.cef.remote.thrift.annotation.Nullable
    public static _Fields findByThriftId(int fieldId) {
      switch(fieldId) {
        case 1: // FROM
          return FROM;
        case 2: // TO
          return TO;
        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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!");
      return fields;
    }

    /**
     * Find the _Fields constant that matches name, or null if its not found.
     */
    @com.jetbrains.cef.remote.thrift.annotation.Nullable
    public static _Fields findByName(java.lang.String name) {
      return byName.get(name);
    }

    private final short _thriftId;
    private final java.lang.String _fieldName;

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

    @Override
    public short getThriftFieldId() {
      return _thriftId;
    }

    @Override
    public java.lang.String getFieldName() {
      return _fieldName;
    }
  }

  // isset id assignments
  private static final int __FROM_ISSET_ID = 0;
  private static final int __TO_ISSET_ID = 1;
  private byte __isset_bitfield = 0;
  public static final java.util.Map<_Fields, com.jetbrains.cef.remote.thrift.meta_data.FieldMetaData> metaDataMap;
  static {
    java.util.Map<_Fields, com.jetbrains.cef.remote.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, com.jetbrains.cef.remote.thrift.meta_data.FieldMetaData>(_Fields.class);
    tmpMap.put(_Fields.FROM, new com.jetbrains.cef.remote.thrift.meta_data.FieldMetaData("from", com.jetbrains.cef.remote.thrift.TFieldRequirementType.REQUIRED, 
        new com.jetbrains.cef.remote.thrift.meta_data.FieldValueMetaData(com.jetbrains.cef.remote.thrift.protocol.TType.I64)));
    tmpMap.put(_Fields.TO, new com.jetbrains.cef.remote.thrift.meta_data.FieldMetaData("to", com.jetbrains.cef.remote.thrift.TFieldRequirementType.REQUIRED, 
        new com.jetbrains.cef.remote.thrift.meta_data.FieldValueMetaData(com.jetbrains.cef.remote.thrift.protocol.TType.I64)));
    metaDataMap = java.util.Collections.unmodifiableMap(tmpMap);
    com.jetbrains.cef.remote.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Range.class, metaDataMap);
  }

  public Range() {
  }

  public Range(
    long from,
    long to)
  {
    this();
    this.from = from;
    setFromIsSet(true);
    this.to = to;
    setToIsSet(true);
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public Range(Range other) {
    __isset_bitfield = other.__isset_bitfield;
    this.from = other.from;
    this.to = other.to;
  }

  @Override
  public Range deepCopy() {
    return new Range(this);
  }

  @Override
  public void clear() {
    setFromIsSet(false);
    this.from = 0;
    setToIsSet(false);
    this.to = 0;
  }

  public long getFrom() {
    return this.from;
  }

  public Range setFrom(long from) {
    this.from = from;
    setFromIsSet(true);
    return this;
  }

  public void unsetFrom() {
    __isset_bitfield = com.jetbrains.cef.remote.thrift.EncodingUtils.clearBit(__isset_bitfield, __FROM_ISSET_ID);
  }

  /** Returns true if field from is set (has been assigned a value) and false otherwise */
  public boolean isSetFrom() {
    return com.jetbrains.cef.remote.thrift.EncodingUtils.testBit(__isset_bitfield, __FROM_ISSET_ID);
  }

  public void setFromIsSet(boolean value) {
    __isset_bitfield = com.jetbrains.cef.remote.thrift.EncodingUtils.setBit(__isset_bitfield, __FROM_ISSET_ID, value);
  }

  public long getTo() {
    return this.to;
  }

  public Range setTo(long to) {
    this.to = to;
    setToIsSet(true);
    return this;
  }

  public void unsetTo() {
    __isset_bitfield = com.jetbrains.cef.remote.thrift.EncodingUtils.clearBit(__isset_bitfield, __TO_ISSET_ID);
  }

  /** Returns true if field to is set (has been assigned a value) and false otherwise */
  public boolean isSetTo() {
    return com.jetbrains.cef.remote.thrift.EncodingUtils.testBit(__isset_bitfield, __TO_ISSET_ID);
  }

  public void setToIsSet(boolean value) {
    __isset_bitfield = com.jetbrains.cef.remote.thrift.EncodingUtils.setBit(__isset_bitfield, __TO_ISSET_ID, value);
  }

  @Override
  public void setFieldValue(_Fields field, @com.jetbrains.cef.remote.thrift.annotation.Nullable java.lang.Object value) {
    switch (field) {
    case FROM:
      if (value == null) {
        unsetFrom();
      } else {
        setFrom((java.lang.Long)value);
      }
      break;

    case TO:
      if (value == null) {
        unsetTo();
      } else {
        setTo((java.lang.Long)value);
      }
      break;

    }
  }

  @com.jetbrains.cef.remote.thrift.annotation.Nullable
  @Override
  public java.lang.Object getFieldValue(_Fields field) {
    switch (field) {
    case FROM:
      return getFrom();

    case TO:
      return getTo();

    }
    throw new java.lang.IllegalStateException();
  }

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

    switch (field) {
    case FROM:
      return isSetFrom();
    case TO:
      return isSetTo();
    }
    throw new java.lang.IllegalStateException();
  }

  @Override
  public boolean equals(java.lang.Object that) {
    if (that instanceof Range)
      return this.equals((Range)that);
    return false;
  }

  public boolean equals(Range that) {
    if (that == null)
      return false;
    if (this == that)
      return true;

    boolean this_present_from = true;
    boolean that_present_from = true;
    if (this_present_from || that_present_from) {
      if (!(this_present_from && that_present_from))
        return false;
      if (this.from != that.from)
        return false;
    }

    boolean this_present_to = true;
    boolean that_present_to = true;
    if (this_present_to || that_present_to) {
      if (!(this_present_to && that_present_to))
        return false;
      if (this.to != that.to)
        return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    int hashCode = 1;

    hashCode = hashCode * 8191 + com.jetbrains.cef.remote.thrift.TBaseHelper.hashCode(from);

    hashCode = hashCode * 8191 + com.jetbrains.cef.remote.thrift.TBaseHelper.hashCode(to);

    return hashCode;
  }

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

    int lastComparison = 0;

    lastComparison = java.lang.Boolean.compare(isSetFrom(), other.isSetFrom());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetFrom()) {
      lastComparison = com.jetbrains.cef.remote.thrift.TBaseHelper.compareTo(this.from, other.from);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = java.lang.Boolean.compare(isSetTo(), other.isSetTo());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetTo()) {
      lastComparison = com.jetbrains.cef.remote.thrift.TBaseHelper.compareTo(this.to, other.to);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    return 0;
  }

  @com.jetbrains.cef.remote.thrift.annotation.Nullable
  @Override
  public _Fields fieldForId(int fieldId) {
    return _Fields.findByThriftId(fieldId);
  }

  @Override
  public void read(com.jetbrains.cef.remote.thrift.protocol.TProtocol iprot) throws com.jetbrains.cef.remote.thrift.TException {
    scheme(iprot).read(iprot, this);
  }

  @Override
  public void write(com.jetbrains.cef.remote.thrift.protocol.TProtocol oprot) throws com.jetbrains.cef.remote.thrift.TException {
    scheme(oprot).write(oprot, this);
  }

  @Override
  public java.lang.String toString() {
    java.lang.StringBuilder sb = new java.lang.StringBuilder("Range(");
    boolean first = true;

    sb.append("from:");
    sb.append(this.from);
    first = false;
    if (!first) sb.append(", ");
    sb.append("to:");
    sb.append(this.to);
    first = false;
    sb.append(")");
    return sb.toString();
  }

  public void validate() throws com.jetbrains.cef.remote.thrift.TException {
    // check for required fields
    // alas, we cannot check 'from' because it's a primitive and you chose the non-beans generator.
    // alas, we cannot check 'to' because it's a primitive and you chose the non-beans generator.
    // check for sub-struct validity
  }

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

  private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.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 com.jetbrains.cef.remote.thrift.protocol.TCompactProtocol(new com.jetbrains.cef.remote.thrift.transport.TIOStreamTransport(in)));
    } catch (com.jetbrains.cef.remote.thrift.TException te) {
      throw new java.io.IOException(te);
    }
  }

  private static class RangeStandardSchemeFactory implements com.jetbrains.cef.remote.thrift.scheme.SchemeFactory {
    @Override
    public RangeStandardScheme getScheme() {
      return new RangeStandardScheme();
    }
  }

  private static class RangeStandardScheme extends com.jetbrains.cef.remote.thrift.scheme.StandardScheme<Range> {

    @Override
    public void read(com.jetbrains.cef.remote.thrift.protocol.TProtocol iprot, Range struct) throws com.jetbrains.cef.remote.thrift.TException {
      com.jetbrains.cef.remote.thrift.protocol.TField schemeField;
      iprot.readStructBegin();
      while (true)
      {
        schemeField = iprot.readFieldBegin();
        if (schemeField.type == com.jetbrains.cef.remote.thrift.protocol.TType.STOP) { 
          break;
        }
        switch (schemeField.id) {
          case 1: // FROM
            if (schemeField.type == com.jetbrains.cef.remote.thrift.protocol.TType.I64) {
              struct.from = iprot.readI64();
              struct.setFromIsSet(true);
            } else { 
              com.jetbrains.cef.remote.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 2: // TO
            if (schemeField.type == com.jetbrains.cef.remote.thrift.protocol.TType.I64) {
              struct.to = iprot.readI64();
              struct.setToIsSet(true);
            } else { 
              com.jetbrains.cef.remote.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          default:
            com.jetbrains.cef.remote.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();

      // check for required fields of primitive type, which can't be checked in the validate method
      if (!struct.isSetFrom()) {
        throw new com.jetbrains.cef.remote.thrift.protocol.TProtocolException("Required field 'from' was not found in serialized data! Struct: " + toString());
      }
      if (!struct.isSetTo()) {
        throw new com.jetbrains.cef.remote.thrift.protocol.TProtocolException("Required field 'to' was not found in serialized data! Struct: " + toString());
      }
      struct.validate();
    }

    @Override
    public void write(com.jetbrains.cef.remote.thrift.protocol.TProtocol oprot, Range struct) throws com.jetbrains.cef.remote.thrift.TException {
      struct.validate();

      oprot.writeStructBegin(STRUCT_DESC);
      oprot.writeFieldBegin(FROM_FIELD_DESC);
      oprot.writeI64(struct.from);
      oprot.writeFieldEnd();
      oprot.writeFieldBegin(TO_FIELD_DESC);
      oprot.writeI64(struct.to);
      oprot.writeFieldEnd();
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }

  }

  private static class RangeTupleSchemeFactory implements com.jetbrains.cef.remote.thrift.scheme.SchemeFactory {
    @Override
    public RangeTupleScheme getScheme() {
      return new RangeTupleScheme();
    }
  }

  private static class RangeTupleScheme extends com.jetbrains.cef.remote.thrift.scheme.TupleScheme<Range> {

    @Override
    public void write(com.jetbrains.cef.remote.thrift.protocol.TProtocol prot, Range struct) throws com.jetbrains.cef.remote.thrift.TException {
      com.jetbrains.cef.remote.thrift.protocol.TTupleProtocol oprot = (com.jetbrains.cef.remote.thrift.protocol.TTupleProtocol) prot;
      oprot.writeI64(struct.from);
      oprot.writeI64(struct.to);
    }

    @Override
    public void read(com.jetbrains.cef.remote.thrift.protocol.TProtocol prot, Range struct) throws com.jetbrains.cef.remote.thrift.TException {
      com.jetbrains.cef.remote.thrift.protocol.TTupleProtocol iprot = (com.jetbrains.cef.remote.thrift.protocol.TTupleProtocol) prot;
      struct.from = iprot.readI64();
      struct.setFromIsSet(true);
      struct.to = iprot.readI64();
      struct.setToIsSet(true);
    }
  }

  private static <S extends com.jetbrains.cef.remote.thrift.scheme.IScheme> S scheme(com.jetbrains.cef.remote.thrift.protocol.TProtocol proto) {
    return (com.jetbrains.cef.remote.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme();
  }
}

