All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bendb.thrifty.test.gen.Xtruct Maven / Gradle / Ivy

The newest version!
/**
 * Autogenerated by Thrift Compiler (0.9.3)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package com.bendb.thrifty.test.gen;

import org.apache.thrift.scheme.IScheme;
import org.apache.thrift.scheme.SchemeFactory;
import org.apache.thrift.scheme.StandardScheme;

import org.apache.thrift.scheme.TupleScheme;
import org.apache.thrift.protocol.TTupleProtocol;
import org.apache.thrift.protocol.TProtocolException;
import org.apache.thrift.EncodingUtils;
import org.apache.thrift.TException;
import org.apache.thrift.async.AsyncMethodCallback;
import org.apache.thrift.server.AbstractNonblockingServer.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.EnumMap;
import java.util.Set;
import java.util.HashSet;
import java.util.EnumSet;
import java.util.Collections;
import java.util.BitSet;
import java.nio.ByteBuffer;
import java.util.Arrays;
import javax.annotation.Generated;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-01-04")
public class Xtruct implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable {
  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Xtruct");

  private static final org.apache.thrift.protocol.TField STRING_THING_FIELD_DESC = new org.apache.thrift.protocol.TField("string_thing", org.apache.thrift.protocol.TType.STRING, (short)1);
  private static final org.apache.thrift.protocol.TField BYTE_THING_FIELD_DESC = new org.apache.thrift.protocol.TField("byte_thing", org.apache.thrift.protocol.TType.BYTE, (short)4);
  private static final org.apache.thrift.protocol.TField I32_THING_FIELD_DESC = new org.apache.thrift.protocol.TField("i32_thing", org.apache.thrift.protocol.TType.I32, (short)9);
  private static final org.apache.thrift.protocol.TField I64_THING_FIELD_DESC = new org.apache.thrift.protocol.TField("i64_thing", org.apache.thrift.protocol.TType.I64, (short)11);

  private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>();
  static {
    schemes.put(StandardScheme.class, new XtructStandardSchemeFactory());
    schemes.put(TupleScheme.class, new XtructTupleSchemeFactory());
  }

  public String string_thing; // required
  public byte byte_thing; // required
  public int i32_thing; // required
  public long i64_thing; // required

  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
  public enum _Fields implements org.apache.thrift.TFieldIdEnum {
    STRING_THING((short)1, "string_thing"),
    BYTE_THING((short)4, "byte_thing"),
    I32_THING((short)9, "i32_thing"),
    I64_THING((short)11, "i64_thing");

    private static final Map byName = new HashMap();

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

    /**
     * Find the _Fields constant that matches fieldId, or null if its not found.
     */
    public static _Fields findByThriftId(int fieldId) {
      switch(fieldId) {
        case 1: // STRING_THING
          return STRING_THING;
        case 4: // BYTE_THING
          return BYTE_THING;
        case 9: // I32_THING
          return I32_THING;
        case 11: // I64_THING
          return I64_THING;
        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 IllegalArgumentException("Field " + fieldId + " doesn't exist!");
      return fields;
    }

    /**
     * Find the _Fields constant that matches name, or null if its not found.
     */
    public static _Fields findByName(String name) {
      return byName.get(name);
    }

    private final short _thriftId;
    private final String _fieldName;

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

    public short getThriftFieldId() {
      return _thriftId;
    }

    public String getFieldName() {
      return _fieldName;
    }
  }

  // isset id assignments
  private static final int __BYTE_THING_ISSET_ID = 0;
  private static final int __I32_THING_ISSET_ID = 1;
  private static final int __I64_THING_ISSET_ID = 2;
  private byte __isset_bitfield = 0;
  public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
  static {
    Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
    tmpMap.put(_Fields.STRING_THING, new org.apache.thrift.meta_data.FieldMetaData("string_thing", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
    tmpMap.put(_Fields.BYTE_THING, new org.apache.thrift.meta_data.FieldMetaData("byte_thing", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BYTE)));
    tmpMap.put(_Fields.I32_THING, new org.apache.thrift.meta_data.FieldMetaData("i32_thing", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32)));
    tmpMap.put(_Fields.I64_THING, new org.apache.thrift.meta_data.FieldMetaData("i64_thing", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64)));
    metaDataMap = Collections.unmodifiableMap(tmpMap);
    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Xtruct.class, metaDataMap);
  }

  public Xtruct() {
  }

  public Xtruct(
    String string_thing,
    byte byte_thing,
    int i32_thing,
    long i64_thing)
  {
    this();
    this.string_thing = string_thing;
    this.byte_thing = byte_thing;
    setByte_thingIsSet(true);
    this.i32_thing = i32_thing;
    setI32_thingIsSet(true);
    this.i64_thing = i64_thing;
    setI64_thingIsSet(true);
  }

  /**
   * Performs a deep copy on other.
   */
  public Xtruct(Xtruct other) {
    __isset_bitfield = other.__isset_bitfield;
    if (other.isSetString_thing()) {
      this.string_thing = other.string_thing;
    }
    this.byte_thing = other.byte_thing;
    this.i32_thing = other.i32_thing;
    this.i64_thing = other.i64_thing;
  }

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

  @Override
  public void clear() {
    this.string_thing = null;
    setByte_thingIsSet(false);
    this.byte_thing = 0;
    setI32_thingIsSet(false);
    this.i32_thing = 0;
    setI64_thingIsSet(false);
    this.i64_thing = 0;
  }

  public String getString_thing() {
    return this.string_thing;
  }

  public Xtruct setString_thing(String string_thing) {
    this.string_thing = string_thing;
    return this;
  }

  public void unsetString_thing() {
    this.string_thing = null;
  }

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

  public void setString_thingIsSet(boolean value) {
    if (!value) {
      this.string_thing = null;
    }
  }

  public byte getByte_thing() {
    return this.byte_thing;
  }

  public Xtruct setByte_thing(byte byte_thing) {
    this.byte_thing = byte_thing;
    setByte_thingIsSet(true);
    return this;
  }

  public void unsetByte_thing() {
    __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __BYTE_THING_ISSET_ID);
  }

  /** Returns true if field byte_thing is set (has been assigned a value) and false otherwise */
  public boolean isSetByte_thing() {
    return EncodingUtils.testBit(__isset_bitfield, __BYTE_THING_ISSET_ID);
  }

  public void setByte_thingIsSet(boolean value) {
    __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __BYTE_THING_ISSET_ID, value);
  }

  public int getI32_thing() {
    return this.i32_thing;
  }

  public Xtruct setI32_thing(int i32_thing) {
    this.i32_thing = i32_thing;
    setI32_thingIsSet(true);
    return this;
  }

  public void unsetI32_thing() {
    __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __I32_THING_ISSET_ID);
  }

  /** Returns true if field i32_thing is set (has been assigned a value) and false otherwise */
  public boolean isSetI32_thing() {
    return EncodingUtils.testBit(__isset_bitfield, __I32_THING_ISSET_ID);
  }

  public void setI32_thingIsSet(boolean value) {
    __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __I32_THING_ISSET_ID, value);
  }

  public long getI64_thing() {
    return this.i64_thing;
  }

  public Xtruct setI64_thing(long i64_thing) {
    this.i64_thing = i64_thing;
    setI64_thingIsSet(true);
    return this;
  }

  public void unsetI64_thing() {
    __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __I64_THING_ISSET_ID);
  }

  /** Returns true if field i64_thing is set (has been assigned a value) and false otherwise */
  public boolean isSetI64_thing() {
    return EncodingUtils.testBit(__isset_bitfield, __I64_THING_ISSET_ID);
  }

  public void setI64_thingIsSet(boolean value) {
    __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __I64_THING_ISSET_ID, value);
  }

  public void setFieldValue(_Fields field, Object value) {
    switch (field) {
    case STRING_THING:
      if (value == null) {
        unsetString_thing();
      } else {
        setString_thing((String)value);
      }
      break;

    case BYTE_THING:
      if (value == null) {
        unsetByte_thing();
      } else {
        setByte_thing((Byte)value);
      }
      break;

    case I32_THING:
      if (value == null) {
        unsetI32_thing();
      } else {
        setI32_thing((Integer)value);
      }
      break;

    case I64_THING:
      if (value == null) {
        unsetI64_thing();
      } else {
        setI64_thing((Long)value);
      }
      break;

    }
  }

  public Object getFieldValue(_Fields field) {
    switch (field) {
    case STRING_THING:
      return getString_thing();

    case BYTE_THING:
      return getByte_thing();

    case I32_THING:
      return getI32_thing();

    case I64_THING:
      return getI64_thing();

    }
    throw new IllegalStateException();
  }

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

    switch (field) {
    case STRING_THING:
      return isSetString_thing();
    case BYTE_THING:
      return isSetByte_thing();
    case I32_THING:
      return isSetI32_thing();
    case I64_THING:
      return isSetI64_thing();
    }
    throw new IllegalStateException();
  }

  @Override
  public boolean equals(Object that) {
    if (that == null)
      return false;
    if (that instanceof Xtruct)
      return this.equals((Xtruct)that);
    return false;
  }

  public boolean equals(Xtruct that) {
    if (that == null)
      return false;

    boolean this_present_string_thing = true && this.isSetString_thing();
    boolean that_present_string_thing = true && that.isSetString_thing();
    if (this_present_string_thing || that_present_string_thing) {
      if (!(this_present_string_thing && that_present_string_thing))
        return false;
      if (!this.string_thing.equals(that.string_thing))
        return false;
    }

    boolean this_present_byte_thing = true;
    boolean that_present_byte_thing = true;
    if (this_present_byte_thing || that_present_byte_thing) {
      if (!(this_present_byte_thing && that_present_byte_thing))
        return false;
      if (this.byte_thing != that.byte_thing)
        return false;
    }

    boolean this_present_i32_thing = true;
    boolean that_present_i32_thing = true;
    if (this_present_i32_thing || that_present_i32_thing) {
      if (!(this_present_i32_thing && that_present_i32_thing))
        return false;
      if (this.i32_thing != that.i32_thing)
        return false;
    }

    boolean this_present_i64_thing = true;
    boolean that_present_i64_thing = true;
    if (this_present_i64_thing || that_present_i64_thing) {
      if (!(this_present_i64_thing && that_present_i64_thing))
        return false;
      if (this.i64_thing != that.i64_thing)
        return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    List list = new ArrayList();

    boolean present_string_thing = true && (isSetString_thing());
    list.add(present_string_thing);
    if (present_string_thing)
      list.add(string_thing);

    boolean present_byte_thing = true;
    list.add(present_byte_thing);
    if (present_byte_thing)
      list.add(byte_thing);

    boolean present_i32_thing = true;
    list.add(present_i32_thing);
    if (present_i32_thing)
      list.add(i32_thing);

    boolean present_i64_thing = true;
    list.add(present_i64_thing);
    if (present_i64_thing)
      list.add(i64_thing);

    return list.hashCode();
  }

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

    int lastComparison = 0;

    lastComparison = Boolean.valueOf(isSetString_thing()).compareTo(other.isSetString_thing());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetString_thing()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.string_thing, other.string_thing);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetByte_thing()).compareTo(other.isSetByte_thing());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetByte_thing()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.byte_thing, other.byte_thing);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetI32_thing()).compareTo(other.isSetI32_thing());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetI32_thing()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.i32_thing, other.i32_thing);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetI64_thing()).compareTo(other.isSetI64_thing());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetI64_thing()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.i64_thing, other.i64_thing);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    return 0;
  }

  public _Fields fieldForId(int fieldId) {
    return _Fields.findByThriftId(fieldId);
  }

  public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
    schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
  }

  public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
    schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder("Xtruct(");
    boolean first = true;

    sb.append("string_thing:");
    if (this.string_thing == null) {
      sb.append("null");
    } else {
      sb.append(this.string_thing);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("byte_thing:");
    sb.append(this.byte_thing);
    first = false;
    if (!first) sb.append(", ");
    sb.append("i32_thing:");
    sb.append(this.i32_thing);
    first = false;
    if (!first) sb.append(", ");
    sb.append("i64_thing:");
    sb.append(this.i64_thing);
    first = false;
    sb.append(")");
    return sb.toString();
  }

  public void validate() throws org.apache.thrift.TException {
    // check for required fields
    // check for sub-struct validity
  }

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

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

  private static class XtructStandardSchemeFactory implements SchemeFactory {
    public XtructStandardScheme getScheme() {
      return new XtructStandardScheme();
    }
  }

  private static class XtructStandardScheme extends StandardScheme {

    public void read(org.apache.thrift.protocol.TProtocol iprot, Xtruct struct) throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TField schemeField;
      iprot.readStructBegin();
      while (true)
      {
        schemeField = iprot.readFieldBegin();
        if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { 
          break;
        }
        switch (schemeField.id) {
          case 1: // STRING_THING
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.string_thing = iprot.readString();
              struct.setString_thingIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 4: // BYTE_THING
            if (schemeField.type == org.apache.thrift.protocol.TType.BYTE) {
              struct.byte_thing = iprot.readByte();
              struct.setByte_thingIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 9: // I32_THING
            if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
              struct.i32_thing = iprot.readI32();
              struct.setI32_thingIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 11: // I64_THING
            if (schemeField.type == org.apache.thrift.protocol.TType.I64) {
              struct.i64_thing = iprot.readI64();
              struct.setI64_thingIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          default:
            org.apache.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
      struct.validate();
    }

    public void write(org.apache.thrift.protocol.TProtocol oprot, Xtruct struct) throws org.apache.thrift.TException {
      struct.validate();

      oprot.writeStructBegin(STRUCT_DESC);
      if (struct.string_thing != null) {
        oprot.writeFieldBegin(STRING_THING_FIELD_DESC);
        oprot.writeString(struct.string_thing);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldBegin(BYTE_THING_FIELD_DESC);
      oprot.writeByte(struct.byte_thing);
      oprot.writeFieldEnd();
      oprot.writeFieldBegin(I32_THING_FIELD_DESC);
      oprot.writeI32(struct.i32_thing);
      oprot.writeFieldEnd();
      oprot.writeFieldBegin(I64_THING_FIELD_DESC);
      oprot.writeI64(struct.i64_thing);
      oprot.writeFieldEnd();
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }

  }

  private static class XtructTupleSchemeFactory implements SchemeFactory {
    public XtructTupleScheme getScheme() {
      return new XtructTupleScheme();
    }
  }

  private static class XtructTupleScheme extends TupleScheme {

    @Override
    public void write(org.apache.thrift.protocol.TProtocol prot, Xtruct struct) throws org.apache.thrift.TException {
      TTupleProtocol oprot = (TTupleProtocol) prot;
      BitSet optionals = new BitSet();
      if (struct.isSetString_thing()) {
        optionals.set(0);
      }
      if (struct.isSetByte_thing()) {
        optionals.set(1);
      }
      if (struct.isSetI32_thing()) {
        optionals.set(2);
      }
      if (struct.isSetI64_thing()) {
        optionals.set(3);
      }
      oprot.writeBitSet(optionals, 4);
      if (struct.isSetString_thing()) {
        oprot.writeString(struct.string_thing);
      }
      if (struct.isSetByte_thing()) {
        oprot.writeByte(struct.byte_thing);
      }
      if (struct.isSetI32_thing()) {
        oprot.writeI32(struct.i32_thing);
      }
      if (struct.isSetI64_thing()) {
        oprot.writeI64(struct.i64_thing);
      }
    }

    @Override
    public void read(org.apache.thrift.protocol.TProtocol prot, Xtruct struct) throws org.apache.thrift.TException {
      TTupleProtocol iprot = (TTupleProtocol) prot;
      BitSet incoming = iprot.readBitSet(4);
      if (incoming.get(0)) {
        struct.string_thing = iprot.readString();
        struct.setString_thingIsSet(true);
      }
      if (incoming.get(1)) {
        struct.byte_thing = iprot.readByte();
        struct.setByte_thingIsSet(true);
      }
      if (incoming.get(2)) {
        struct.i32_thing = iprot.readI32();
        struct.setI32_thingIsSet(true);
      }
      if (incoming.get(3)) {
        struct.i64_thing = iprot.readI64();
        struct.setI64_thingIsSet(true);
      }
    }
  }

}