/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */

package test.fixtures.adapter;

import com.facebook.swift.codec.*;
import com.facebook.swift.codec.ThriftField.Requiredness;
import com.facebook.swift.codec.ThriftField.Recursiveness;
import com.google.common.collect.*;
import java.util.*;
import javax.annotation.Nullable;
import org.apache.thrift.*;
import org.apache.thrift.transport.*;
import org.apache.thrift.protocol.*;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.MoreObjects.ToStringHelper;

@SwiftGenerated
@com.facebook.swift.codec.ThriftStruct(value="CountingStruct", builder=CountingStruct.Builder.class)
public final class CountingStruct implements com.facebook.thrift.payload.ThriftSerializable {
    @ThriftConstructor
    public CountingStruct(
        @com.facebook.swift.codec.ThriftField(value=1, name="regularInt", requiredness=Requiredness.OPTIONAL) final Long regularInt,
        @com.facebook.swift.codec.ThriftField(value=2, name="countingInt", requiredness=Requiredness.OPTIONAL) final Long countingInt,
        @com.facebook.swift.codec.ThriftField(value=3, name="regularString", requiredness=Requiredness.OPTIONAL) final String regularString
    ) {
        this.regularInt = regularInt;
        this.countingInt = countingInt;
        this.regularString = regularString;
    }
    
    @ThriftConstructor
    protected CountingStruct() {
      this.regularInt = null;
      this.countingInt = null;
      this.regularString = null;
    }
    
    public static class Builder {
        private Long regularInt = null;
        private Long countingInt = null;
        private String regularString = null;
    
        @com.facebook.swift.codec.ThriftField(value=1, name="regularInt", requiredness=Requiredness.OPTIONAL)
        public Builder setRegularInt(Long regularInt) {
            this.regularInt = regularInt;
            return this;
        }
    
        public Long getRegularInt() { return regularInt; }
    
            @com.facebook.swift.codec.ThriftField(value=2, name="countingInt", requiredness=Requiredness.OPTIONAL)
        public Builder setCountingInt(Long countingInt) {
            this.countingInt = countingInt;
            return this;
        }
    
        public Long getCountingInt() { return countingInt; }
    
            @com.facebook.swift.codec.ThriftField(value=3, name="regularString", requiredness=Requiredness.OPTIONAL)
        public Builder setRegularString(String regularString) {
            this.regularString = regularString;
            return this;
        }
    
        public String getRegularString() { return regularString; }
    
        public Builder() { }
        public Builder(CountingStruct other) {
            this.regularInt = other.regularInt;
            this.countingInt = other.countingInt;
            this.regularString = other.regularString;
        }
    
        @ThriftConstructor
        public CountingStruct build() {
            CountingStruct result = new CountingStruct (
                this.regularInt,
                this.countingInt,
                this.regularString
            );
            return result;
        }
    }
        
    public static final Map<String, Integer> NAMES_TO_IDS = new HashMap();
    public static final Map<String, Integer> THRIFT_NAMES_TO_IDS = new HashMap();
    public static final Map<Integer, TField> FIELD_METADATA = new HashMap<>();
    private static final TStruct STRUCT_DESC = new TStruct("CountingStruct");
    private final Long regularInt;
    public static final int _REGULARINT = 1;
    private static final TField REGULAR_INT_FIELD_DESC = new TField("regularInt", TType.I64, (short)1);
        private final Long countingInt;
    public static final int _COUNTINGINT = 2;
    private static final TField COUNTING_INT_FIELD_DESC = new TField("countingInt", TType.I64, (short)2);
        private final String regularString;
    public static final int _REGULARSTRING = 3;
    private static final TField REGULAR_STRING_FIELD_DESC = new TField("regularString", TType.STRING, (short)3);
    static {
      NAMES_TO_IDS.put("regularInt", 1);
      THRIFT_NAMES_TO_IDS.put("regularInt", 1);
      FIELD_METADATA.put(1, REGULAR_INT_FIELD_DESC);
      NAMES_TO_IDS.put("countingInt", 2);
      THRIFT_NAMES_TO_IDS.put("countingInt", 2);
      FIELD_METADATA.put(2, COUNTING_INT_FIELD_DESC);
      NAMES_TO_IDS.put("regularString", 3);
      THRIFT_NAMES_TO_IDS.put("regularString", 3);
      FIELD_METADATA.put(3, REGULAR_STRING_FIELD_DESC);
      com.facebook.thrift.type.TypeRegistry.add(new com.facebook.thrift.type.Type(
        new com.facebook.thrift.type.UniversalName("facebook.com/thrift/test/CountingStruct"),
        CountingStruct.class, CountingStruct::read0));
    }
    
    @Nullable
    @com.facebook.swift.codec.ThriftField(value=1, name="regularInt", requiredness=Requiredness.OPTIONAL)
    public Long getRegularInt() { return regularInt; }
    
    
    @Nullable
    @com.facebook.swift.codec.ThriftField(value=2, name="countingInt", requiredness=Requiredness.OPTIONAL)
    public Long getCountingInt() { return countingInt; }
    
    
    @Nullable
    @com.facebook.swift.codec.ThriftField(value=3, name="regularString", requiredness=Requiredness.OPTIONAL)
    public String getRegularString() { return regularString; }
    
    @java.lang.Override
    public String toString() {
        ToStringHelper helper = toStringHelper(this);
        helper.add("regularInt", regularInt);
        helper.add("countingInt", countingInt);
        helper.add("regularString", regularString);
        return helper.toString();
    }
    
    @java.lang.Override
    public boolean equals(java.lang.Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
    
        CountingStruct other = (CountingStruct)o;
    
        return
            Objects.equals(regularInt, other.regularInt) &&
            Objects.equals(countingInt, other.countingInt) &&
            Objects.equals(regularString, other.regularString) &&
            true;
    }
    
    @java.lang.Override
    public int hashCode() {
        return Arrays.deepHashCode(new java.lang.Object[] {
            regularInt,
            countingInt,
            regularString
        });
    }
    
    
    public static com.facebook.thrift.payload.Reader<CountingStruct> asReader() {
      return CountingStruct::read0;
    }
    
    public static CountingStruct read0(TProtocol oprot) throws TException {
      TField __field;
      oprot.readStructBegin(CountingStruct.NAMES_TO_IDS, CountingStruct.THRIFT_NAMES_TO_IDS, CountingStruct.FIELD_METADATA);
      CountingStruct.Builder builder = new CountingStruct.Builder();
      while (true) {
        __field = oprot.readFieldBegin();
        if (__field.type == TType.STOP) { break; }
        switch (__field.id) {
        case _REGULARINT:
          if (__field.type == TType.I64) {
            Long regularInt = oprot.readI64();
            builder.setRegularInt(regularInt);
          } else {
            TProtocolUtil.skip(oprot, __field.type);
          }
          break;
        case _COUNTINGINT:
          if (__field.type == TType.I64) {
            Long countingInt = oprot.readI64();
            builder.setCountingInt(countingInt);
          } else {
            TProtocolUtil.skip(oprot, __field.type);
          }
          break;
        case _REGULARSTRING:
          if (__field.type == TType.STRING) {
            String regularString = oprot.readString();
            builder.setRegularString(regularString);
          } else {
            TProtocolUtil.skip(oprot, __field.type);
          }
          break;
        default:
          TProtocolUtil.skip(oprot, __field.type);
          break;
        }
        oprot.readFieldEnd();
      }
      oprot.readStructEnd();
      return builder.build();
    }
    
    public void write0(TProtocol oprot) throws TException {
      oprot.writeStructBegin(STRUCT_DESC);
      if (regularInt != null) {
        oprot.writeFieldBegin(REGULAR_INT_FIELD_DESC);
        oprot.writeI64(this.regularInt);
        oprot.writeFieldEnd();
      }
      if (countingInt != null) {
        oprot.writeFieldBegin(COUNTING_INT_FIELD_DESC);
        oprot.writeI64(this.countingInt);
        oprot.writeFieldEnd();
      }
      if (regularString != null) {
        oprot.writeFieldBegin(REGULAR_STRING_FIELD_DESC);
        oprot.writeString(this.regularString);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }
    
    private static class _CountingStructLazy {
        private static final CountingStruct _DEFAULT = new CountingStruct.Builder().build();
    }
    
    public static CountingStruct defaultInstance() {
        return  _CountingStructLazy._DEFAULT;
    }
}
