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

org.apache.distributedlog.thrift.service.WriteContext Maven / Gradle / Ivy

The newest version!
/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 */
package org.apache.distributedlog.thrift.service;

import org.apache.commons.lang.builder.HashCodeBuilder;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.thrift.*;
import org.apache.thrift.async.*;
import org.apache.thrift.meta_data.*;
import org.apache.thrift.transport.*;
import org.apache.thrift.protocol.*;

// No additional import required for struct/union.

public class WriteContext implements TBase, java.io.Serializable, Cloneable {
  private static final TStruct STRUCT_DESC = new TStruct("WriteContext");

  private static final TField TRIED_HOSTS_FIELD_DESC = new TField("triedHosts", TType.SET, (short)1);
  private static final TField CRC32_FIELD_DESC = new TField("crc32", TType.I64, (short)2);
  private static final TField IS_RECORD_SET_FIELD_DESC = new TField("isRecordSet", TType.BOOL, (short)3);


  public Set triedHosts;
  public long crc32;
  public boolean isRecordSet;

  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
  public enum _Fields implements TFieldIdEnum {
    TRIED_HOSTS((short)1, "triedHosts"),
    CRC32((short)2, "crc32"),
    IS_RECORD_SET((short)3, "isRecordSet");
  
    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: // TRIED_HOSTS
  	return TRIED_HOSTS;
        case 2: // CRC32
  	return CRC32;
        case 3: // IS_RECORD_SET
  	return IS_RECORD_SET;
        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 __CRC32_ISSET_ID = 0;
  private static final int __ISRECORDSET_ISSET_ID = 1;
  private BitSet __isset_bit_vector = new BitSet(2);

  public static final Map<_Fields, FieldMetaData> metaDataMap;
  static {
    Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class);
    tmpMap.put(_Fields.TRIED_HOSTS, new FieldMetaData("triedHosts", TFieldRequirementType.OPTIONAL,
      new SetMetaData(TType.SET,
                new FieldValueMetaData(TType.STRING))));
    tmpMap.put(_Fields.CRC32, new FieldMetaData("crc32", TFieldRequirementType.OPTIONAL,
      new FieldValueMetaData(TType.I64)));
    tmpMap.put(_Fields.IS_RECORD_SET, new FieldMetaData("isRecordSet", TFieldRequirementType.OPTIONAL,
      new FieldValueMetaData(TType.BOOL)));
    metaDataMap = Collections.unmodifiableMap(tmpMap);
    FieldMetaData.addStructMetaDataMap(WriteContext.class, metaDataMap);
  }


  public WriteContext() {
  }


  /**
   * Performs a deep copy on other.
   */
  public WriteContext(WriteContext other) {
    __isset_bit_vector.clear();
    __isset_bit_vector.or(other.__isset_bit_vector);
    if (other.isSetTriedHosts()) {
      Set __this__triedHosts = new HashSet();
      for (String other_element : other.triedHosts) {
        __this__triedHosts.add(other_element);
      }
      this.triedHosts = __this__triedHosts;
    }
    this.crc32 = other.crc32;
    this.isRecordSet = other.isRecordSet;
  }

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

  @Override
  public void clear() {
    this.triedHosts = null;
    setCrc32IsSet(false);
    this.crc32 = 0;
    setIsRecordSetIsSet(false);
    this.isRecordSet = false;
  }

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

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

  public void addToTriedHosts(String elem) {
    if (this.triedHosts == null) {
      this.triedHosts = new HashSet();
    }
    this.triedHosts.add(elem);
  }

  public Set getTriedHosts() {
    return this.triedHosts;
  }

  public WriteContext setTriedHosts(Set triedHosts) {
    this.triedHosts = triedHosts;
    
    return this;
  }

  public void unsetTriedHosts() {
    this.triedHosts = null;
  }

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

  public void setTriedHostsIsSet(boolean value) {
    if (!value) {
      this.triedHosts = null;
    }
  }

  public long getCrc32() {
    return this.crc32;
  }

  public WriteContext setCrc32(long crc32) {
    this.crc32 = crc32;
    setCrc32IsSet(true);

    return this;
  }

  public void unsetCrc32() {
  __isset_bit_vector.clear(__CRC32_ISSET_ID);
  }

  /** Returns true if field crc32 is set (has been asigned a value) and false otherwise */
  public boolean isSetCrc32() {
    return __isset_bit_vector.get(__CRC32_ISSET_ID);
  }

  public void setCrc32IsSet(boolean value) {
    __isset_bit_vector.set(__CRC32_ISSET_ID, value);
  }

  public boolean isIsRecordSet() {
    return this.isRecordSet;
  }

  public WriteContext setIsRecordSet(boolean isRecordSet) {
    this.isRecordSet = isRecordSet;
    setIsRecordSetIsSet(true);

    return this;
  }

  public void unsetIsRecordSet() {
  __isset_bit_vector.clear(__ISRECORDSET_ISSET_ID);
  }

  /** Returns true if field isRecordSet is set (has been asigned a value) and false otherwise */
  public boolean isSetIsRecordSet() {
    return __isset_bit_vector.get(__ISRECORDSET_ISSET_ID);
  }

  public void setIsRecordSetIsSet(boolean value) {
    __isset_bit_vector.set(__ISRECORDSET_ISSET_ID, value);
  }

  public void setFieldValue(_Fields field, Object value) {
    switch (field) {
    case TRIED_HOSTS:
      if (value == null) {
        unsetTriedHosts();
      } else {
        setTriedHosts((Set)value);
      }
      break;
    case CRC32:
      if (value == null) {
        unsetCrc32();
      } else {
        setCrc32((Long)value);
      }
      break;
    case IS_RECORD_SET:
      if (value == null) {
        unsetIsRecordSet();
      } else {
        setIsRecordSet((Boolean)value);
      }
      break;
    }
  }

  public Object getFieldValue(_Fields field) {
    switch (field) {
    case TRIED_HOSTS:
      return getTriedHosts();
    case CRC32:
      return new Long(getCrc32());
    case IS_RECORD_SET:
      return new Boolean(isIsRecordSet());
    }
    throw new IllegalStateException();
  }

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

    switch (field) {
    case TRIED_HOSTS:
      return isSetTriedHosts();
    case CRC32:
      return isSetCrc32();
    case IS_RECORD_SET:
      return isSetIsRecordSet();
    }
    throw new IllegalStateException();
  }

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

  public boolean equals(WriteContext that) {
    if (that == null)
      return false;
    boolean this_present_triedHosts = true && this.isSetTriedHosts();
    boolean that_present_triedHosts = true && that.isSetTriedHosts();
    if (this_present_triedHosts || that_present_triedHosts) {
      if (!(this_present_triedHosts && that_present_triedHosts))
        return false;
      if (!this.triedHosts.equals(that.triedHosts))
        return false;
    }
    boolean this_present_crc32 = true && this.isSetCrc32();
    boolean that_present_crc32 = true && that.isSetCrc32();
    if (this_present_crc32 || that_present_crc32) {
      if (!(this_present_crc32 && that_present_crc32))
        return false;
      if (this.crc32 != that.crc32)
        return false;
    }
    boolean this_present_isRecordSet = true && this.isSetIsRecordSet();
    boolean that_present_isRecordSet = true && that.isSetIsRecordSet();
    if (this_present_isRecordSet || that_present_isRecordSet) {
      if (!(this_present_isRecordSet && that_present_isRecordSet))
        return false;
      if (this.isRecordSet != that.isRecordSet)
        return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    HashCodeBuilder builder = new HashCodeBuilder();
    boolean present_triedHosts = true && (isSetTriedHosts());
    builder.append(present_triedHosts);
    if (present_triedHosts)
      builder.append(triedHosts);
    boolean present_crc32 = true && (isSetCrc32());
    builder.append(present_crc32);
    if (present_crc32)
      builder.append(crc32);
    boolean present_isRecordSet = true && (isSetIsRecordSet());
    builder.append(present_isRecordSet);
    if (present_isRecordSet)
      builder.append(isRecordSet);
    return builder.toHashCode();
  }

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

    int lastComparison = 0;
    WriteContext typedOther = (WriteContext)other;

    lastComparison = Boolean.valueOf(isSetTriedHosts()).compareTo(typedOther.isSetTriedHosts());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetTriedHosts()) {
      lastComparison = TBaseHelper.compareTo(this.triedHosts, typedOther.triedHosts);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetCrc32()).compareTo(typedOther.isSetCrc32());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetCrc32()) {
      lastComparison = TBaseHelper.compareTo(this.crc32, typedOther.crc32);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = Boolean.valueOf(isSetIsRecordSet()).compareTo(typedOther.isSetIsRecordSet());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetIsRecordSet()) {
      lastComparison = TBaseHelper.compareTo(this.isRecordSet, typedOther.isRecordSet);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    return 0;
  }

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


  public void read(TProtocol iprot) throws TException {
    TField field;
    iprot.readStructBegin();
    while (true)
    {
      field = iprot.readFieldBegin();
      if (field.type == TType.STOP) {
        break;
      }
      switch (field.id) {
        case 1: // TRIED_HOSTS
          if (field.type == TType.SET) {
            {
            TSet _set4 = iprot.readSetBegin();
            this.triedHosts = new HashSet(2*_set4.size);
            for (int _i5 = 0; _i5 < _set4.size; ++_i5)
            {
              String _elem6;
              _elem6 = iprot.readString();
              this.triedHosts.add(_elem6);
            }
            iprot.readSetEnd();
            }
          } else {
            TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 2: // CRC32
          if (field.type == TType.I64) {
            this.crc32 = iprot.readI64();
            setCrc32IsSet(true);
          } else {
            TProtocolUtil.skip(iprot, field.type);
          }
          break;
        case 3: // IS_RECORD_SET
          if (field.type == TType.BOOL) {
            this.isRecordSet = iprot.readBool();
            setIsRecordSetIsSet(true);
          } else {
            TProtocolUtil.skip(iprot, field.type);
          }
          break;
        default:
          TProtocolUtil.skip(iprot, field.type);
      }
      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 (this.triedHosts != null) {
      if (isSetTriedHosts()) {
        oprot.writeFieldBegin(TRIED_HOSTS_FIELD_DESC);
        {
          oprot.writeSetBegin(new TSet(TType.STRING, this.triedHosts.size()));
          for (String _iter7 : this.triedHosts)
          {
            oprot.writeString(_iter7);
          }
          oprot.writeSetEnd();
        }
        oprot.writeFieldEnd();
      }
    }
    if (isSetCrc32()) {
      oprot.writeFieldBegin(CRC32_FIELD_DESC);
      oprot.writeI64(this.crc32);
      oprot.writeFieldEnd();
    }
    if (isSetIsRecordSet()) {
      oprot.writeFieldBegin(IS_RECORD_SET_FIELD_DESC);
      oprot.writeBool(this.isRecordSet);
      oprot.writeFieldEnd();
    }
    oprot.writeFieldStop();
    oprot.writeStructEnd();
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder("WriteContext(");
    boolean first = true;
    if (isSetTriedHosts()) {
      sb.append("triedHosts:");
      if (this.triedHosts == null) {
        sb.append("null");
      } else {
        sb.append(this.triedHosts);
      }
      first = false;
      }
    if (isSetCrc32()) {
      if (!first) sb.append(", ");
      sb.append("crc32:");
      sb.append(this.crc32);
      first = false;
      }
    if (isSetIsRecordSet()) {
      if (!first) sb.append(", ");
      sb.append("isRecordSet:");
      sb.append(this.isRecordSet);
      first = false;
      }
    sb.append(")");
    return sb.toString();
  }

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy