/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package test.fixtures.adapter;

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

@SuppressWarnings({ "unused", "serial" })
public class CountingStruct implements TBase, java.io.Serializable, Cloneable, Comparable<CountingStruct> {
  private static final TStruct STRUCT_DESC = new TStruct("CountingStruct");
  private static final TField REGULAR_INT_FIELD_DESC = new TField("regularInt", TType.I64, (short)1);
  private static final TField COUNTING_INT_FIELD_DESC = new TField("countingInt", TType.I64, (short)2);
  private static final TField REGULAR_STRING_FIELD_DESC = new TField("regularString", TType.STRING, (short)3);

  public long regularInt;
  public long countingInt;
  public String regularString;
  public static final int REGULARINT = 1;
  public static final int COUNTINGINT = 2;
  public static final int REGULARSTRING = 3;

  // isset id assignments
  private static final int __REGULARINT_ISSET_ID = 0;
  private static final int __COUNTINGINT_ISSET_ID = 1;
  private BitSet __isset_bit_vector = new BitSet(2);

  public static final Map<Integer, FieldMetaData> metaDataMap;

  static {
    Map<Integer, FieldMetaData> tmpMetaDataMap = new HashMap<Integer, FieldMetaData>();
    tmpMetaDataMap.put(REGULARINT, new FieldMetaData("regularInt", TFieldRequirementType.OPTIONAL, 
        new FieldValueMetaData(TType.I64)));
    tmpMetaDataMap.put(COUNTINGINT, new FieldMetaData("countingInt", TFieldRequirementType.OPTIONAL, 
        new FieldValueMetaData(TType.I64)));
    tmpMetaDataMap.put(REGULARSTRING, new FieldMetaData("regularString", TFieldRequirementType.OPTIONAL, 
        new FieldValueMetaData(TType.STRING)));
    metaDataMap = Collections.unmodifiableMap(tmpMetaDataMap);
  }

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

  public CountingStruct() {
  }

  public CountingStruct(
      long regularInt,
      long countingInt,
      String regularString) {
    this();
    this.regularInt = regularInt;
    setRegularIntIsSet(true);
    this.countingInt = countingInt;
    setCountingIntIsSet(true);
    this.regularString = regularString;
  }

  public static class Builder {
    private long regularInt;
    private long countingInt;
    private String regularString;

    BitSet __optional_isset = new BitSet(2);

    public Builder() {
    }

    public Builder setRegularInt(final long regularInt) {
      this.regularInt = regularInt;
      __optional_isset.set(__REGULARINT_ISSET_ID, true);
      return this;
    }

    public Builder setCountingInt(final long countingInt) {
      this.countingInt = countingInt;
      __optional_isset.set(__COUNTINGINT_ISSET_ID, true);
      return this;
    }

    public Builder setRegularString(final String regularString) {
      this.regularString = regularString;
      return this;
    }

    public CountingStruct build() {
      CountingStruct result = new CountingStruct();
      if (__optional_isset.get(__REGULARINT_ISSET_ID)) {
        result.setRegularInt(this.regularInt);
      }
      if (__optional_isset.get(__COUNTINGINT_ISSET_ID)) {
        result.setCountingInt(this.countingInt);
      }
      result.setRegularString(this.regularString);
      return result;
    }
  }

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

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public CountingStruct(CountingStruct other) {
    __isset_bit_vector.clear();
    __isset_bit_vector.or(other.__isset_bit_vector);
    this.regularInt = TBaseHelper.deepCopy(other.regularInt);
    this.countingInt = TBaseHelper.deepCopy(other.countingInt);
    if (other.isSetRegularString()) {
      this.regularString = TBaseHelper.deepCopy(other.regularString);
    }
  }

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

  public long getRegularInt() {
    return this.regularInt;
  }

  public CountingStruct setRegularInt(long regularInt) {
    this.regularInt = regularInt;
    setRegularIntIsSet(true);
    return this;
  }

  public void unsetRegularInt() {
    __isset_bit_vector.clear(__REGULARINT_ISSET_ID);
  }

  // Returns true if field regularInt is set (has been assigned a value) and false otherwise
  public boolean isSetRegularInt() {
    return __isset_bit_vector.get(__REGULARINT_ISSET_ID);
  }

  public void setRegularIntIsSet(boolean __value) {
    __isset_bit_vector.set(__REGULARINT_ISSET_ID, __value);
  }

  public long getCountingInt() {
    return this.countingInt;
  }

  public CountingStruct setCountingInt(long countingInt) {
    this.countingInt = countingInt;
    setCountingIntIsSet(true);
    return this;
  }

  public void unsetCountingInt() {
    __isset_bit_vector.clear(__COUNTINGINT_ISSET_ID);
  }

  // Returns true if field countingInt is set (has been assigned a value) and false otherwise
  public boolean isSetCountingInt() {
    return __isset_bit_vector.get(__COUNTINGINT_ISSET_ID);
  }

  public void setCountingIntIsSet(boolean __value) {
    __isset_bit_vector.set(__COUNTINGINT_ISSET_ID, __value);
  }

  public String getRegularString() {
    return this.regularString;
  }

  public CountingStruct setRegularString(String regularString) {
    this.regularString = regularString;
    return this;
  }

  public void unsetRegularString() {
    this.regularString = null;
  }

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

  public void setRegularStringIsSet(boolean __value) {
    if (!__value) {
      this.regularString = null;
    }
  }

  public void setFieldValue(int fieldID, Object __value) {
    switch (fieldID) {
    case REGULARINT:
      if (__value == null) {
        unsetRegularInt();
      } else {
        setRegularInt((Long)__value);
      }
      break;

    case COUNTINGINT:
      if (__value == null) {
        unsetCountingInt();
      } else {
        setCountingInt((Long)__value);
      }
      break;

    case REGULARSTRING:
      if (__value == null) {
        unsetRegularString();
      } else {
        setRegularString((String)__value);
      }
      break;

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

  public Object getFieldValue(int fieldID) {
    switch (fieldID) {
    case REGULARINT:
      return new Long(getRegularInt());

    case COUNTINGINT:
      return new Long(getCountingInt());

    case REGULARSTRING:
      return getRegularString();

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

    if (!TBaseHelper.equalsNobinary(this.isSetRegularInt(), that.isSetRegularInt(), this.regularInt, that.regularInt)) { return false; }

    if (!TBaseHelper.equalsNobinary(this.isSetCountingInt(), that.isSetCountingInt(), this.countingInt, that.countingInt)) { return false; }

    if (!TBaseHelper.equalsNobinary(this.isSetRegularString(), that.isSetRegularString(), this.regularString, that.regularString)) { return false; }

    return true;
  }

  @Override
  public int hashCode() {
    return Arrays.deepHashCode(new Object[] {regularInt, countingInt, regularString});
  }

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

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

    lastComparison = Boolean.valueOf(isSetRegularInt()).compareTo(other.isSetRegularInt());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(regularInt, other.regularInt);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetCountingInt()).compareTo(other.isSetCountingInt());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(countingInt, other.countingInt);
    if (lastComparison != 0) { 
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetRegularString()).compareTo(other.isSetRegularString());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(regularString, other.regularString);
    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 REGULARINT:
          if (__field.type == TType.I64) {
            this.regularInt = iprot.readI64();
            setRegularIntIsSet(true);
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case COUNTINGINT:
          if (__field.type == TType.I64) {
            this.countingInt = iprot.readI64();
            setCountingIntIsSet(true);
          } else {
            TProtocolUtil.skip(iprot, __field.type);
          }
          break;
        case REGULARSTRING:
          if (__field.type == TType.STRING) {
            this.regularString = iprot.readString();
          } 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 (isSetRegularInt()) {
      oprot.writeFieldBegin(REGULAR_INT_FIELD_DESC);
      oprot.writeI64(this.regularInt);
      oprot.writeFieldEnd();
    }
    if (isSetCountingInt()) {
      oprot.writeFieldBegin(COUNTING_INT_FIELD_DESC);
      oprot.writeI64(this.countingInt);
      oprot.writeFieldEnd();
    }
    if (this.regularString != null) {
      if (isSetRegularString()) {
        oprot.writeFieldBegin(REGULAR_STRING_FIELD_DESC);
        oprot.writeString(this.regularString);
        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("CountingStruct");
    sb.append(space);
    sb.append("(");
    sb.append(newLine);
    boolean first = true;

    if (isSetRegularInt())
    {
      sb.append(indentStr);
      sb.append("regularInt");
      sb.append(space);
      sb.append(":").append(space);
      sb.append(TBaseHelper.toString(this.getRegularInt(), indent + 1, prettyPrint));
      first = false;
    }
    if (isSetCountingInt())
    {
      if (!first) sb.append("," + newLine);
      sb.append(indentStr);
      sb.append("countingInt");
      sb.append(space);
      sb.append(":").append(space);
      sb.append(TBaseHelper.toString(this.getCountingInt(), indent + 1, prettyPrint));
      first = false;
    }
    if (isSetRegularString())
    {
      if (!first) sb.append("," + newLine);
      sb.append(indentStr);
      sb.append("regularString");
      sb.append(space);
      sb.append(":").append(space);
      if (this.getRegularString() == null) {
        sb.append("null");
      } else {
        sb.append(TBaseHelper.toString(this.getRegularString(), indent + 1, prettyPrint));
      }
      first = false;
    }
    sb.append(newLine + TBaseHelper.reduceIndent(indentStr));
    sb.append(")");
    return sb.toString();
  }

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

}

