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

com.twitter.elephantbird.pig.test.thrift.AddressBook Maven / Gradle / Ivy

/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 */
package com.twitter.elephantbird.pig.test.thrift;

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

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

  private static final TField PERSONS_FIELD_DESC = new TField("persons", TType.LIST, (short)1);

  public List persons;

  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
  public enum _Fields implements TFieldIdEnum {
    PERSONS((short)1, "persons");

    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: // PERSONS
          return PERSONS;
        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

  public static final Map<_Fields, FieldMetaData> metaDataMap;
  static {
    Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class);
    tmpMap.put(_Fields.PERSONS, new FieldMetaData("persons", TFieldRequirementType.DEFAULT, 
        new ListMetaData(TType.LIST, 
            new StructMetaData(TType.STRUCT, Person.class))));
    metaDataMap = Collections.unmodifiableMap(tmpMap);
    FieldMetaData.addStructMetaDataMap(AddressBook.class, metaDataMap);
  }

  public AddressBook() {
  }

  public AddressBook(
    List persons)
  {
    this();
    this.persons = persons;
  }

  /**
   * Performs a deep copy on other.
   */
  public AddressBook(AddressBook other) {
    if (other.isSetPersons()) {
      List __this__persons = new ArrayList();
      for (Person other_element : other.persons) {
        __this__persons.add(new Person(other_element));
      }
      this.persons = __this__persons;
    }
  }

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

  @Override
  public void clear() {
    this.persons = null;
  }

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

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

  public void addToPersons(Person elem) {
    if (this.persons == null) {
      this.persons = new ArrayList();
    }
    this.persons.add(elem);
  }

  public List getPersons() {
    return this.persons;
  }

  public AddressBook setPersons(List persons) {
    this.persons = persons;
    return this;
  }

  public void unsetPersons() {
    this.persons = null;
  }

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

  public void setPersonsIsSet(boolean value) {
    if (!value) {
      this.persons = null;
    }
  }

  public void setFieldValue(_Fields field, Object value) {
    switch (field) {
    case PERSONS:
      if (value == null) {
        unsetPersons();
      } else {
        setPersons((List)value);
      }
      break;

    }
  }

  public Object getFieldValue(_Fields field) {
    switch (field) {
    case PERSONS:
      return getPersons();

    }
    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 PERSONS:
      return isSetPersons();
    }
    throw new IllegalStateException();
  }

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

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

    boolean this_present_persons = true && this.isSetPersons();
    boolean that_present_persons = true && that.isSetPersons();
    if (this_present_persons || that_present_persons) {
      if (!(this_present_persons && that_present_persons))
        return false;
      if (!this.persons.equals(that.persons))
        return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    HashCodeBuilder builder = new HashCodeBuilder();

    boolean present_persons = true && (isSetPersons());
    builder.append(present_persons);
    if (present_persons)
      builder.append(persons);

    return builder.toHashCode();
  }

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

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

    lastComparison = Boolean.valueOf(isSetPersons()).compareTo(typedOther.isSetPersons());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetPersons()) {
      lastComparison = TBaseHelper.compareTo(this.persons, typedOther.persons);
      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: // PERSONS
          if (field.type == TType.LIST) {
            {
              TList _list4 = iprot.readListBegin();
              this.persons = new ArrayList(_list4.size);
              for (int _i5 = 0; _i5 < _list4.size; ++_i5)
              {
                Person _elem6;
                _elem6 = new Person();
                _elem6.read(iprot);
                this.persons.add(_elem6);
              }
              iprot.readListEnd();
            }
          } 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.persons != null) {
      oprot.writeFieldBegin(PERSONS_FIELD_DESC);
      {
        oprot.writeListBegin(new TList(TType.STRUCT, this.persons.size()));
        for (Person _iter7 : this.persons)
        {
          _iter7.write(oprot);
        }
        oprot.writeListEnd();
      }
      oprot.writeFieldEnd();
    }
    oprot.writeFieldStop();
    oprot.writeStructEnd();
  }

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

    sb.append("persons:");
    if (this.persons == null) {
      sb.append("null");
    } else {
      sb.append(this.persons);
    }
    first = false;
    sb.append(")");
    return sb.toString();
  }

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

}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy