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

com.adgear.anoa.test.nested.BytesThrift Maven / Gradle / Ivy

There is a newer version: 3.1.2
Show newest version
/**
 * Autogenerated by Thrift Compiler (0.9.2)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package com.adgear.anoa.test.nested;

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.2)", date = "2016-6-3")
public class BytesThrift 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("BytesThrift");

  private static final org.apache.thrift.protocol.TField BYTES_FIELD_FIELD_DESC = new org.apache.thrift.protocol.TField("bytes_field", org.apache.thrift.protocol.TType.STRING, (short)1);
  private static final org.apache.thrift.protocol.TField BYTES_LIST_FIELD_DESC = new org.apache.thrift.protocol.TField("bytes_list", org.apache.thrift.protocol.TType.LIST, (short)2);
  private static final org.apache.thrift.protocol.TField BYTES_MAP_FIELD_DESC = new org.apache.thrift.protocol.TField("bytes_map", org.apache.thrift.protocol.TType.MAP, (short)3);

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

  public ByteBuffer bytes_field; // optional
  public List bytes_list; // optional
  public Map bytes_map; // optional

  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
  public enum _Fields implements org.apache.thrift.TFieldIdEnum {
    BYTES_FIELD((short)1, "bytes_field"),
    BYTES_LIST((short)2, "bytes_list"),
    BYTES_MAP((short)3, "bytes_map");

    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: // BYTES_FIELD
          return BYTES_FIELD;
        case 2: // BYTES_LIST
          return BYTES_LIST;
        case 3: // BYTES_MAP
          return BYTES_MAP;
        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 _Fields optionals[] = {_Fields.BYTES_FIELD,_Fields.BYTES_LIST,_Fields.BYTES_MAP};
  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.BYTES_FIELD, new org.apache.thrift.meta_data.FieldMetaData("bytes_field", org.apache.thrift.TFieldRequirementType.OPTIONAL, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , true)));
    tmpMap.put(_Fields.BYTES_LIST, new org.apache.thrift.meta_data.FieldMetaData("bytes_list", org.apache.thrift.TFieldRequirementType.OPTIONAL, 
        new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, 
            new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING            , true))));
    tmpMap.put(_Fields.BYTES_MAP, new org.apache.thrift.meta_data.FieldMetaData("bytes_map", org.apache.thrift.TFieldRequirementType.OPTIONAL, 
        new org.apache.thrift.meta_data.MapMetaData(org.apache.thrift.protocol.TType.MAP, 
            new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING), 
            new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING            , true))));
    metaDataMap = Collections.unmodifiableMap(tmpMap);
    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(BytesThrift.class, metaDataMap);
  }

  public BytesThrift() {
    this.bytes_field = java.nio.ByteBuffer.wrap(new byte[0]);

  }

  /**
   * Performs a deep copy on other.
   */
  public BytesThrift(BytesThrift other) {
    if (other.isSetBytes_field()) {
      this.bytes_field = org.apache.thrift.TBaseHelper.copyBinary(other.bytes_field);
    }
    if (other.isSetBytes_list()) {
      List __this__bytes_list = new ArrayList(other.bytes_list);
      this.bytes_list = __this__bytes_list;
    }
    if (other.isSetBytes_map()) {
      Map __this__bytes_map = new HashMap(other.bytes_map);
      this.bytes_map = __this__bytes_map;
    }
  }

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

  @Override
  public void clear() {
    this.bytes_field = java.nio.ByteBuffer.wrap(new byte[0]);

    this.bytes_list = null;
    this.bytes_map = null;
  }

  public byte[] getBytes_field() {
    setBytes_field(org.apache.thrift.TBaseHelper.rightSize(bytes_field));
    return bytes_field == null ? null : bytes_field.array();
  }

  public ByteBuffer bufferForBytes_field() {
    return org.apache.thrift.TBaseHelper.copyBinary(bytes_field);
  }

  public BytesThrift setBytes_field(byte[] bytes_field) {
    this.bytes_field = bytes_field == null ? (ByteBuffer)null : ByteBuffer.wrap(Arrays.copyOf(bytes_field, bytes_field.length));
    return this;
  }

  public BytesThrift setBytes_field(ByteBuffer bytes_field) {
    this.bytes_field = org.apache.thrift.TBaseHelper.copyBinary(bytes_field);
    return this;
  }

  public void unsetBytes_field() {
    this.bytes_field = null;
  }

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

  public void setBytes_fieldIsSet(boolean value) {
    if (!value) {
      this.bytes_field = null;
    }
  }

  public int getBytes_listSize() {
    return (this.bytes_list == null) ? 0 : this.bytes_list.size();
  }

  public java.util.Iterator getBytes_listIterator() {
    return (this.bytes_list == null) ? null : this.bytes_list.iterator();
  }

  public void addToBytes_list(ByteBuffer elem) {
    if (this.bytes_list == null) {
      this.bytes_list = new ArrayList();
    }
    this.bytes_list.add(elem);
  }

  public List getBytes_list() {
    return this.bytes_list;
  }

  public BytesThrift setBytes_list(List bytes_list) {
    this.bytes_list = bytes_list;
    return this;
  }

  public void unsetBytes_list() {
    this.bytes_list = null;
  }

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

  public void setBytes_listIsSet(boolean value) {
    if (!value) {
      this.bytes_list = null;
    }
  }

  public int getBytes_mapSize() {
    return (this.bytes_map == null) ? 0 : this.bytes_map.size();
  }

  public void putToBytes_map(String key, ByteBuffer val) {
    if (this.bytes_map == null) {
      this.bytes_map = new HashMap();
    }
    this.bytes_map.put(key, val);
  }

  public Map getBytes_map() {
    return this.bytes_map;
  }

  public BytesThrift setBytes_map(Map bytes_map) {
    this.bytes_map = bytes_map;
    return this;
  }

  public void unsetBytes_map() {
    this.bytes_map = null;
  }

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

  public void setBytes_mapIsSet(boolean value) {
    if (!value) {
      this.bytes_map = null;
    }
  }

  public void setFieldValue(_Fields field, Object value) {
    switch (field) {
    case BYTES_FIELD:
      if (value == null) {
        unsetBytes_field();
      } else {
        setBytes_field((ByteBuffer)value);
      }
      break;

    case BYTES_LIST:
      if (value == null) {
        unsetBytes_list();
      } else {
        setBytes_list((List)value);
      }
      break;

    case BYTES_MAP:
      if (value == null) {
        unsetBytes_map();
      } else {
        setBytes_map((Map)value);
      }
      break;

    }
  }

  public Object getFieldValue(_Fields field) {
    switch (field) {
    case BYTES_FIELD:
      return getBytes_field();

    case BYTES_LIST:
      return getBytes_list();

    case BYTES_MAP:
      return getBytes_map();

    }
    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 BYTES_FIELD:
      return isSetBytes_field();
    case BYTES_LIST:
      return isSetBytes_list();
    case BYTES_MAP:
      return isSetBytes_map();
    }
    throw new IllegalStateException();
  }

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

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

    boolean this_present_bytes_field = true && this.isSetBytes_field();
    boolean that_present_bytes_field = true && that.isSetBytes_field();
    if (this_present_bytes_field || that_present_bytes_field) {
      if (!(this_present_bytes_field && that_present_bytes_field))
        return false;
      if (!this.bytes_field.equals(that.bytes_field))
        return false;
    }

    boolean this_present_bytes_list = true && this.isSetBytes_list();
    boolean that_present_bytes_list = true && that.isSetBytes_list();
    if (this_present_bytes_list || that_present_bytes_list) {
      if (!(this_present_bytes_list && that_present_bytes_list))
        return false;
      if (!this.bytes_list.equals(that.bytes_list))
        return false;
    }

    boolean this_present_bytes_map = true && this.isSetBytes_map();
    boolean that_present_bytes_map = true && that.isSetBytes_map();
    if (this_present_bytes_map || that_present_bytes_map) {
      if (!(this_present_bytes_map && that_present_bytes_map))
        return false;
      if (!this.bytes_map.equals(that.bytes_map))
        return false;
    }

    return true;
  }

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

    boolean present_bytes_field = true && (isSetBytes_field());
    list.add(present_bytes_field);
    if (present_bytes_field)
      list.add(bytes_field);

    boolean present_bytes_list = true && (isSetBytes_list());
    list.add(present_bytes_list);
    if (present_bytes_list)
      list.add(bytes_list);

    boolean present_bytes_map = true && (isSetBytes_map());
    list.add(present_bytes_map);
    if (present_bytes_map)
      list.add(bytes_map);

    return list.hashCode();
  }

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

    int lastComparison = 0;

    lastComparison = Boolean.valueOf(isSetBytes_field()).compareTo(other.isSetBytes_field());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetBytes_field()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.bytes_field, other.bytes_field);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetBytes_list()).compareTo(other.isSetBytes_list());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetBytes_list()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.bytes_list, other.bytes_list);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetBytes_map()).compareTo(other.isSetBytes_map());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetBytes_map()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.bytes_map, other.bytes_map);
      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("BytesThrift(");
    boolean first = true;

    if (isSetBytes_field()) {
      sb.append("bytes_field:");
      if (this.bytes_field == null) {
        sb.append("null");
      } else {
        org.apache.thrift.TBaseHelper.toString(this.bytes_field, sb);
      }
      first = false;
    }
    if (isSetBytes_list()) {
      if (!first) sb.append(", ");
      sb.append("bytes_list:");
      if (this.bytes_list == null) {
        sb.append("null");
      } else {
        sb.append(this.bytes_list);
      }
      first = false;
    }
    if (isSetBytes_map()) {
      if (!first) sb.append(", ");
      sb.append("bytes_map:");
      if (this.bytes_map == null) {
        sb.append("null");
      } else {
        sb.append(this.bytes_map);
      }
      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 {
      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 BytesThriftStandardSchemeFactory implements SchemeFactory {
    public BytesThriftStandardScheme getScheme() {
      return new BytesThriftStandardScheme();
    }
  }

  private static class BytesThriftStandardScheme extends StandardScheme {

    public void read(org.apache.thrift.protocol.TProtocol iprot, BytesThrift 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: // BYTES_FIELD
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.bytes_field = iprot.readBinary();
              struct.setBytes_fieldIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 2: // BYTES_LIST
            if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
              {
                org.apache.thrift.protocol.TList _list0 = iprot.readListBegin();
                struct.bytes_list = new ArrayList(_list0.size);
                ByteBuffer _elem1;
                for (int _i2 = 0; _i2 < _list0.size; ++_i2)
                {
                  _elem1 = iprot.readBinary();
                  struct.bytes_list.add(_elem1);
                }
                iprot.readListEnd();
              }
              struct.setBytes_listIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 3: // BYTES_MAP
            if (schemeField.type == org.apache.thrift.protocol.TType.MAP) {
              {
                org.apache.thrift.protocol.TMap _map3 = iprot.readMapBegin();
                struct.bytes_map = new HashMap(2*_map3.size);
                String _key4;
                ByteBuffer _val5;
                for (int _i6 = 0; _i6 < _map3.size; ++_i6)
                {
                  _key4 = iprot.readString();
                  _val5 = iprot.readBinary();
                  struct.bytes_map.put(_key4, _val5);
                }
                iprot.readMapEnd();
              }
              struct.setBytes_mapIsSet(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, BytesThrift struct) throws org.apache.thrift.TException {
      struct.validate();

      oprot.writeStructBegin(STRUCT_DESC);
      if (struct.bytes_field != null) {
        if (struct.isSetBytes_field()) {
          oprot.writeFieldBegin(BYTES_FIELD_FIELD_DESC);
          oprot.writeBinary(struct.bytes_field);
          oprot.writeFieldEnd();
        }
      }
      if (struct.bytes_list != null) {
        if (struct.isSetBytes_list()) {
          oprot.writeFieldBegin(BYTES_LIST_FIELD_DESC);
          {
            oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRING, struct.bytes_list.size()));
            for (ByteBuffer _iter7 : struct.bytes_list)
            {
              oprot.writeBinary(_iter7);
            }
            oprot.writeListEnd();
          }
          oprot.writeFieldEnd();
        }
      }
      if (struct.bytes_map != null) {
        if (struct.isSetBytes_map()) {
          oprot.writeFieldBegin(BYTES_MAP_FIELD_DESC);
          {
            oprot.writeMapBegin(new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.STRING, struct.bytes_map.size()));
            for (Map.Entry _iter8 : struct.bytes_map.entrySet())
            {
              oprot.writeString(_iter8.getKey());
              oprot.writeBinary(_iter8.getValue());
            }
            oprot.writeMapEnd();
          }
          oprot.writeFieldEnd();
        }
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }

  }

  private static class BytesThriftTupleSchemeFactory implements SchemeFactory {
    public BytesThriftTupleScheme getScheme() {
      return new BytesThriftTupleScheme();
    }
  }

  private static class BytesThriftTupleScheme extends TupleScheme {

    @Override
    public void write(org.apache.thrift.protocol.TProtocol prot, BytesThrift struct) throws org.apache.thrift.TException {
      TTupleProtocol oprot = (TTupleProtocol) prot;
      BitSet optionals = new BitSet();
      if (struct.isSetBytes_field()) {
        optionals.set(0);
      }
      if (struct.isSetBytes_list()) {
        optionals.set(1);
      }
      if (struct.isSetBytes_map()) {
        optionals.set(2);
      }
      oprot.writeBitSet(optionals, 3);
      if (struct.isSetBytes_field()) {
        oprot.writeBinary(struct.bytes_field);
      }
      if (struct.isSetBytes_list()) {
        {
          oprot.writeI32(struct.bytes_list.size());
          for (ByteBuffer _iter9 : struct.bytes_list)
          {
            oprot.writeBinary(_iter9);
          }
        }
      }
      if (struct.isSetBytes_map()) {
        {
          oprot.writeI32(struct.bytes_map.size());
          for (Map.Entry _iter10 : struct.bytes_map.entrySet())
          {
            oprot.writeString(_iter10.getKey());
            oprot.writeBinary(_iter10.getValue());
          }
        }
      }
    }

    @Override
    public void read(org.apache.thrift.protocol.TProtocol prot, BytesThrift struct) throws org.apache.thrift.TException {
      TTupleProtocol iprot = (TTupleProtocol) prot;
      BitSet incoming = iprot.readBitSet(3);
      if (incoming.get(0)) {
        struct.bytes_field = iprot.readBinary();
        struct.setBytes_fieldIsSet(true);
      }
      if (incoming.get(1)) {
        {
          org.apache.thrift.protocol.TList _list11 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRING, iprot.readI32());
          struct.bytes_list = new ArrayList(_list11.size);
          ByteBuffer _elem12;
          for (int _i13 = 0; _i13 < _list11.size; ++_i13)
          {
            _elem12 = iprot.readBinary();
            struct.bytes_list.add(_elem12);
          }
        }
        struct.setBytes_listIsSet(true);
      }
      if (incoming.get(2)) {
        {
          org.apache.thrift.protocol.TMap _map14 = new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.STRING, iprot.readI32());
          struct.bytes_map = new HashMap(2*_map14.size);
          String _key15;
          ByteBuffer _val16;
          for (int _i17 = 0; _i17 < _map14.size; ++_i17)
          {
            _key15 = iprot.readString();
            _val16 = iprot.readBinary();
            struct.bytes_map.put(_key15, _val16);
          }
        }
        struct.setBytes_mapIsSet(true);
      }
    }
  }

}