/**
 * Autogenerated by Thrift Compiler (0.19.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 CustomScheme implements com.jetbrains.cef.remote.thrift.TBase<CustomScheme, CustomScheme._Fields>, java.io.Serializable, Cloneable, Comparable<CustomScheme> {
  private static final com.jetbrains.cef.remote.thrift.protocol.TStruct STRUCT_DESC = new com.jetbrains.cef.remote.thrift.protocol.TStruct("CustomScheme");

  private static final com.jetbrains.cef.remote.thrift.protocol.TField SCHEME_NAME_FIELD_DESC = new com.jetbrains.cef.remote.thrift.protocol.TField("schemeName", com.jetbrains.cef.remote.thrift.protocol.TType.STRING, (short)1);
  private static final com.jetbrains.cef.remote.thrift.protocol.TField OPTIONS_FIELD_DESC = new com.jetbrains.cef.remote.thrift.protocol.TField("options", com.jetbrains.cef.remote.thrift.protocol.TType.I32, (short)2);

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

  public @com.jetbrains.cef.remote.thrift.annotation.Nullable java.lang.String schemeName; // required
  public int options; // 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 {
    SCHEME_NAME((short)1, "schemeName"),
    OPTIONS((short)2, "options");

    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: // SCHEME_NAME
          return SCHEME_NAME;
        case 2: // OPTIONS
          return OPTIONS;
        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 __OPTIONS_ISSET_ID = 0;
  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.SCHEME_NAME, new com.jetbrains.cef.remote.thrift.meta_data.FieldMetaData("schemeName", com.jetbrains.cef.remote.thrift.TFieldRequirementType.REQUIRED,
        new com.jetbrains.cef.remote.thrift.meta_data.FieldValueMetaData(com.jetbrains.cef.remote.thrift.protocol.TType.STRING)));
    tmpMap.put(_Fields.OPTIONS, new com.jetbrains.cef.remote.thrift.meta_data.FieldMetaData("options", com.jetbrains.cef.remote.thrift.TFieldRequirementType.REQUIRED,
        new com.jetbrains.cef.remote.thrift.meta_data.FieldValueMetaData(com.jetbrains.cef.remote.thrift.protocol.TType.I32)));
    metaDataMap = java.util.Collections.unmodifiableMap(tmpMap);
    com.jetbrains.cef.remote.thrift.meta_data.FieldMetaData.addStructMetaDataMap(CustomScheme.class, metaDataMap);
  }

  public CustomScheme() {
  }

  public CustomScheme(
    java.lang.String schemeName,
    int options)
  {
    this();
    this.schemeName = schemeName;
    this.options = options;
    setOptionsIsSet(true);
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public CustomScheme(CustomScheme other) {
    __isset_bitfield = other.__isset_bitfield;
    if (other.isSetSchemeName()) {
      this.schemeName = other.schemeName;
    }
    this.options = other.options;
  }

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

  @Override
  public void clear() {
    this.schemeName = null;
    setOptionsIsSet(false);
    this.options = 0;
  }

  @com.jetbrains.cef.remote.thrift.annotation.Nullable
  public java.lang.String getSchemeName() {
    return this.schemeName;
  }

  public CustomScheme setSchemeName(@com.jetbrains.cef.remote.thrift.annotation.Nullable java.lang.String schemeName) {
    this.schemeName = schemeName;
    return this;
  }

  public void unsetSchemeName() {
    this.schemeName = null;
  }

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

  public void setSchemeNameIsSet(boolean value) {
    if (!value) {
      this.schemeName = null;
    }
  }

  public int getOptions() {
    return this.options;
  }

  public CustomScheme setOptions(int options) {
    this.options = options;
    setOptionsIsSet(true);
    return this;
  }

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

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

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

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

    case OPTIONS:
      if (value == null) {
        unsetOptions();
      } else {
        setOptions((java.lang.Integer)value);
      }
      break;

    }
  }

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

    case OPTIONS:
      return getOptions();

    }
    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 SCHEME_NAME:
      return isSetSchemeName();
    case OPTIONS:
      return isSetOptions();
    }
    throw new java.lang.IllegalStateException();
  }

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

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

    boolean this_present_schemeName = true && this.isSetSchemeName();
    boolean that_present_schemeName = true && that.isSetSchemeName();
    if (this_present_schemeName || that_present_schemeName) {
      if (!(this_present_schemeName && that_present_schemeName))
        return false;
      if (!this.schemeName.equals(that.schemeName))
        return false;
    }

    boolean this_present_options = true;
    boolean that_present_options = true;
    if (this_present_options || that_present_options) {
      if (!(this_present_options && that_present_options))
        return false;
      if (this.options != that.options)
        return false;
    }

    return true;
  }

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

    hashCode = hashCode * 8191 + ((isSetSchemeName()) ? 131071 : 524287);
    if (isSetSchemeName())
      hashCode = hashCode * 8191 + schemeName.hashCode();

    hashCode = hashCode * 8191 + options;

    return hashCode;
  }

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

    int lastComparison = 0;

    lastComparison = java.lang.Boolean.compare(isSetSchemeName(), other.isSetSchemeName());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetSchemeName()) {
      lastComparison = com.jetbrains.cef.remote.thrift.TBaseHelper.compareTo(this.schemeName, other.schemeName);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = java.lang.Boolean.compare(isSetOptions(), other.isSetOptions());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetOptions()) {
      lastComparison = com.jetbrains.cef.remote.thrift.TBaseHelper.compareTo(this.options, other.options);
      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("CustomScheme(");
    boolean first = true;

    sb.append("schemeName:");
    if (this.schemeName == null) {
      sb.append("null");
    } else {
      sb.append(this.schemeName);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("options:");
    sb.append(this.options);
    first = false;
    sb.append(")");
    return sb.toString();
  }

  public void validate() throws com.jetbrains.cef.remote.thrift.TException {
    // check for required fields
    if (schemeName == null) {
      throw new com.jetbrains.cef.remote.thrift.protocol.TProtocolException("Required field 'schemeName' was not present! Struct: " + toString());
    }
    // alas, we cannot check 'options' 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 CustomSchemeStandardSchemeFactory implements com.jetbrains.cef.remote.thrift.scheme.SchemeFactory {
    @Override
    public CustomSchemeStandardScheme getScheme() {
      return new CustomSchemeStandardScheme();
    }
  }

  private static class CustomSchemeStandardScheme extends com.jetbrains.cef.remote.thrift.scheme.StandardScheme<CustomScheme> {

    @Override
    public void read(com.jetbrains.cef.remote.thrift.protocol.TProtocol iprot, CustomScheme 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: // SCHEME_NAME
            if (schemeField.type == com.jetbrains.cef.remote.thrift.protocol.TType.STRING) {
              struct.schemeName = iprot.readString();
              struct.setSchemeNameIsSet(true);
            } else { 
              com.jetbrains.cef.remote.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 2: // OPTIONS
            if (schemeField.type == com.jetbrains.cef.remote.thrift.protocol.TType.I32) {
              struct.options = iprot.readI32();
              struct.setOptionsIsSet(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.isSetOptions()) {
        throw new com.jetbrains.cef.remote.thrift.protocol.TProtocolException("Required field 'options' was not found in serialized data! Struct: " + toString());
      }
      struct.validate();
    }

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

      oprot.writeStructBegin(STRUCT_DESC);
      if (struct.schemeName != null) {
        oprot.writeFieldBegin(SCHEME_NAME_FIELD_DESC);
        oprot.writeString(struct.schemeName);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldBegin(OPTIONS_FIELD_DESC);
      oprot.writeI32(struct.options);
      oprot.writeFieldEnd();
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }

  }

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

  private static class CustomSchemeTupleScheme extends com.jetbrains.cef.remote.thrift.scheme.TupleScheme<CustomScheme> {

    @Override
    public void write(com.jetbrains.cef.remote.thrift.protocol.TProtocol prot, CustomScheme 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.writeString(struct.schemeName);
      oprot.writeI32(struct.options);
    }

    @Override
    public void read(com.jetbrains.cef.remote.thrift.protocol.TProtocol prot, CustomScheme 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.schemeName = iprot.readString();
      struct.setSchemeNameIsSet(true);
      struct.options = iprot.readI32();
      struct.setOptionsIsSet(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();
  }
}

