Subversion Repositories SmartDukaan

Rev

Rev 103 | Blame | Last modification | View Log | RSS feed

/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 */
package in.shop2020.model.v1.catalog;

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.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

public class Category implements TBase<Category._Fields>, java.io.Serializable, Cloneable, Comparable<Category> {
  private static final TStruct STRUCT_DESC = new TStruct("Category");

  private static final TField ID_FIELD_DESC = new TField("id", TType.I64, (short)1);
  private static final TField NAME_FIELD_DESC = new TField("name", TType.STRING, (short)2);
  private static final TField CHILD_CATEGORIES_FIELD_DESC = new TField("childCategories", TType.LIST, (short)3);
  private static final TField PARENT_ID_FIELD_DESC = new TField("parent_id", TType.I64, (short)4);
  private static final TField IS_TOP_LEVEL_FIELD_DESC = new TField("isTopLevel", TType.BOOL, (short)5);
  private static final TField ADDED_ON_FIELD_DESC = new TField("addedOn", TType.I64, (short)6);
  private static final TField CATEGORY_STATUS_FIELD_DESC = new TField("categoryStatus", TType.I32, (short)7);

  private long id;
  private String name;
  private List<Long> childCategories;
  private long parent_id;
  private boolean isTopLevel;
  private long addedOn;
  private status categoryStatus;

  /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
  public enum _Fields implements TFieldIdEnum {
    ID((short)1, "id"),
    NAME((short)2, "name"),
    CHILD_CATEGORIES((short)3, "childCategories"),
    PARENT_ID((short)4, "parent_id"),
    IS_TOP_LEVEL((short)5, "isTopLevel"),
    ADDED_ON((short)6, "addedOn"),
    /**
     * 
     * @see status
     */
    CATEGORY_STATUS((short)7, "categoryStatus");

    private static final Map<Integer, _Fields> byId = new HashMap<Integer, _Fields>();
    private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();

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

    /**
     * Find the _Fields constant that matches fieldId, or null if its not found.
     */
    public static _Fields findByThriftId(int fieldId) {
      return byId.get(fieldId);
    }

    /**
     * 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 __ID_ISSET_ID = 0;
  private static final int __PARENT_ID_ISSET_ID = 1;
  private static final int __ISTOPLEVEL_ISSET_ID = 2;
  private static final int __ADDEDON_ISSET_ID = 3;
  private BitSet __isset_bit_vector = new BitSet(4);

  public static final Map<_Fields, FieldMetaData> metaDataMap = Collections.unmodifiableMap(new EnumMap<_Fields, FieldMetaData>(_Fields.class) {{
    put(_Fields.ID, new FieldMetaData("id", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.I64)));
    put(_Fields.NAME, new FieldMetaData("name", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.STRING)));
    put(_Fields.CHILD_CATEGORIES, new FieldMetaData("childCategories", TFieldRequirementType.DEFAULT, 
        new ListMetaData(TType.LIST, 
            new FieldValueMetaData(TType.I64))));
    put(_Fields.PARENT_ID, new FieldMetaData("parent_id", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.I64)));
    put(_Fields.IS_TOP_LEVEL, new FieldMetaData("isTopLevel", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.BOOL)));
    put(_Fields.ADDED_ON, new FieldMetaData("addedOn", TFieldRequirementType.DEFAULT, 
        new FieldValueMetaData(TType.I64)));
    put(_Fields.CATEGORY_STATUS, new FieldMetaData("categoryStatus", TFieldRequirementType.DEFAULT, 
        new EnumMetaData(TType.ENUM, status.class)));
  }});

  static {
    FieldMetaData.addStructMetaDataMap(Category.class, metaDataMap);
  }

  public Category() {
  }

  public Category(
    long id,
    String name,
    List<Long> childCategories,
    long parent_id,
    boolean isTopLevel,
    long addedOn,
    status categoryStatus)
  {
    this();
    this.id = id;
    setIdIsSet(true);
    this.name = name;
    this.childCategories = childCategories;
    this.parent_id = parent_id;
    setParent_idIsSet(true);
    this.isTopLevel = isTopLevel;
    setIsTopLevelIsSet(true);
    this.addedOn = addedOn;
    setAddedOnIsSet(true);
    this.categoryStatus = categoryStatus;
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public Category(Category other) {
    __isset_bit_vector.clear();
    __isset_bit_vector.or(other.__isset_bit_vector);
    this.id = other.id;
    if (other.isSetName()) {
      this.name = other.name;
    }
    if (other.isSetChildCategories()) {
      List<Long> __this__childCategories = new ArrayList<Long>();
      for (Long other_element : other.childCategories) {
        __this__childCategories.add(other_element);
      }
      this.childCategories = __this__childCategories;
    }
    this.parent_id = other.parent_id;
    this.isTopLevel = other.isTopLevel;
    this.addedOn = other.addedOn;
    if (other.isSetCategoryStatus()) {
      this.categoryStatus = other.categoryStatus;
    }
  }

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

  @Deprecated
  public Category clone() {
    return new Category(this);
  }

  public long getId() {
    return this.id;
  }

  public Category setId(long id) {
    this.id = id;
    setIdIsSet(true);
    return this;
  }

  public void unsetId() {
    __isset_bit_vector.clear(__ID_ISSET_ID);
  }

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

  public void setIdIsSet(boolean value) {
    __isset_bit_vector.set(__ID_ISSET_ID, value);
  }

  public String getName() {
    return this.name;
  }

  public Category setName(String name) {
    this.name = name;
    return this;
  }

  public void unsetName() {
    this.name = null;
  }

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

  public void setNameIsSet(boolean value) {
    if (!value) {
      this.name = null;
    }
  }

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

  public java.util.Iterator<Long> getChildCategoriesIterator() {
    return (this.childCategories == null) ? null : this.childCategories.iterator();
  }

  public void addToChildCategories(long elem) {
    if (this.childCategories == null) {
      this.childCategories = new ArrayList<Long>();
    }
    this.childCategories.add(elem);
  }

  public List<Long> getChildCategories() {
    return this.childCategories;
  }

  public Category setChildCategories(List<Long> childCategories) {
    this.childCategories = childCategories;
    return this;
  }

  public void unsetChildCategories() {
    this.childCategories = null;
  }

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

  public void setChildCategoriesIsSet(boolean value) {
    if (!value) {
      this.childCategories = null;
    }
  }

  public long getParent_id() {
    return this.parent_id;
  }

  public Category setParent_id(long parent_id) {
    this.parent_id = parent_id;
    setParent_idIsSet(true);
    return this;
  }

  public void unsetParent_id() {
    __isset_bit_vector.clear(__PARENT_ID_ISSET_ID);
  }

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

  public void setParent_idIsSet(boolean value) {
    __isset_bit_vector.set(__PARENT_ID_ISSET_ID, value);
  }

  public boolean isIsTopLevel() {
    return this.isTopLevel;
  }

  public Category setIsTopLevel(boolean isTopLevel) {
    this.isTopLevel = isTopLevel;
    setIsTopLevelIsSet(true);
    return this;
  }

  public void unsetIsTopLevel() {
    __isset_bit_vector.clear(__ISTOPLEVEL_ISSET_ID);
  }

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

  public void setIsTopLevelIsSet(boolean value) {
    __isset_bit_vector.set(__ISTOPLEVEL_ISSET_ID, value);
  }

  public long getAddedOn() {
    return this.addedOn;
  }

  public Category setAddedOn(long addedOn) {
    this.addedOn = addedOn;
    setAddedOnIsSet(true);
    return this;
  }

  public void unsetAddedOn() {
    __isset_bit_vector.clear(__ADDEDON_ISSET_ID);
  }

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

  public void setAddedOnIsSet(boolean value) {
    __isset_bit_vector.set(__ADDEDON_ISSET_ID, value);
  }

  /**
   * 
   * @see status
   */
  public status getCategoryStatus() {
    return this.categoryStatus;
  }

  /**
   * 
   * @see status
   */
  public Category setCategoryStatus(status categoryStatus) {
    this.categoryStatus = categoryStatus;
    return this;
  }

  public void unsetCategoryStatus() {
    this.categoryStatus = null;
  }

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

  public void setCategoryStatusIsSet(boolean value) {
    if (!value) {
      this.categoryStatus = null;
    }
  }

  public void setFieldValue(_Fields field, Object value) {
    switch (field) {
    case ID:
      if (value == null) {
        unsetId();
      } else {
        setId((Long)value);
      }
      break;

    case NAME:
      if (value == null) {
        unsetName();
      } else {
        setName((String)value);
      }
      break;

    case CHILD_CATEGORIES:
      if (value == null) {
        unsetChildCategories();
      } else {
        setChildCategories((List<Long>)value);
      }
      break;

    case PARENT_ID:
      if (value == null) {
        unsetParent_id();
      } else {
        setParent_id((Long)value);
      }
      break;

    case IS_TOP_LEVEL:
      if (value == null) {
        unsetIsTopLevel();
      } else {
        setIsTopLevel((Boolean)value);
      }
      break;

    case ADDED_ON:
      if (value == null) {
        unsetAddedOn();
      } else {
        setAddedOn((Long)value);
      }
      break;

    case CATEGORY_STATUS:
      if (value == null) {
        unsetCategoryStatus();
      } else {
        setCategoryStatus((status)value);
      }
      break;

    }
  }

  public void setFieldValue(int fieldID, Object value) {
    setFieldValue(_Fields.findByThriftIdOrThrow(fieldID), value);
  }

  public Object getFieldValue(_Fields field) {
    switch (field) {
    case ID:
      return new Long(getId());

    case NAME:
      return getName();

    case CHILD_CATEGORIES:
      return getChildCategories();

    case PARENT_ID:
      return new Long(getParent_id());

    case IS_TOP_LEVEL:
      return new Boolean(isIsTopLevel());

    case ADDED_ON:
      return new Long(getAddedOn());

    case CATEGORY_STATUS:
      return getCategoryStatus();

    }
    throw new IllegalStateException();
  }

  public Object getFieldValue(int fieldId) {
    return getFieldValue(_Fields.findByThriftIdOrThrow(fieldId));
  }

  /** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */
  public boolean isSet(_Fields field) {
    switch (field) {
    case ID:
      return isSetId();
    case NAME:
      return isSetName();
    case CHILD_CATEGORIES:
      return isSetChildCategories();
    case PARENT_ID:
      return isSetParent_id();
    case IS_TOP_LEVEL:
      return isSetIsTopLevel();
    case ADDED_ON:
      return isSetAddedOn();
    case CATEGORY_STATUS:
      return isSetCategoryStatus();
    }
    throw new IllegalStateException();
  }

  public boolean isSet(int fieldID) {
    return isSet(_Fields.findByThriftIdOrThrow(fieldID));
  }

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

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

    boolean this_present_id = true;
    boolean that_present_id = true;
    if (this_present_id || that_present_id) {
      if (!(this_present_id && that_present_id))
        return false;
      if (this.id != that.id)
        return false;
    }

    boolean this_present_name = true && this.isSetName();
    boolean that_present_name = true && that.isSetName();
    if (this_present_name || that_present_name) {
      if (!(this_present_name && that_present_name))
        return false;
      if (!this.name.equals(that.name))
        return false;
    }

    boolean this_present_childCategories = true && this.isSetChildCategories();
    boolean that_present_childCategories = true && that.isSetChildCategories();
    if (this_present_childCategories || that_present_childCategories) {
      if (!(this_present_childCategories && that_present_childCategories))
        return false;
      if (!this.childCategories.equals(that.childCategories))
        return false;
    }

    boolean this_present_parent_id = true;
    boolean that_present_parent_id = true;
    if (this_present_parent_id || that_present_parent_id) {
      if (!(this_present_parent_id && that_present_parent_id))
        return false;
      if (this.parent_id != that.parent_id)
        return false;
    }

    boolean this_present_isTopLevel = true;
    boolean that_present_isTopLevel = true;
    if (this_present_isTopLevel || that_present_isTopLevel) {
      if (!(this_present_isTopLevel && that_present_isTopLevel))
        return false;
      if (this.isTopLevel != that.isTopLevel)
        return false;
    }

    boolean this_present_addedOn = true;
    boolean that_present_addedOn = true;
    if (this_present_addedOn || that_present_addedOn) {
      if (!(this_present_addedOn && that_present_addedOn))
        return false;
      if (this.addedOn != that.addedOn)
        return false;
    }

    boolean this_present_categoryStatus = true && this.isSetCategoryStatus();
    boolean that_present_categoryStatus = true && that.isSetCategoryStatus();
    if (this_present_categoryStatus || that_present_categoryStatus) {
      if (!(this_present_categoryStatus && that_present_categoryStatus))
        return false;
      if (!this.categoryStatus.equals(that.categoryStatus))
        return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    return 0;
  }

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

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

    lastComparison = Boolean.valueOf(isSetId()).compareTo(isSetId());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(id, typedOther.id);
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetName()).compareTo(isSetName());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(name, typedOther.name);
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetChildCategories()).compareTo(isSetChildCategories());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(childCategories, typedOther.childCategories);
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetParent_id()).compareTo(isSetParent_id());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(parent_id, typedOther.parent_id);
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetIsTopLevel()).compareTo(isSetIsTopLevel());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(isTopLevel, typedOther.isTopLevel);
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetAddedOn()).compareTo(isSetAddedOn());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(addedOn, typedOther.addedOn);
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = Boolean.valueOf(isSetCategoryStatus()).compareTo(isSetCategoryStatus());
    if (lastComparison != 0) {
      return lastComparison;
    }
    lastComparison = TBaseHelper.compareTo(categoryStatus, typedOther.categoryStatus);
    if (lastComparison != 0) {
      return lastComparison;
    }
    return 0;
  }

  public void read(TProtocol iprot) throws TException {
    TField field;
    iprot.readStructBegin();
    while (true)
    {
      field = iprot.readFieldBegin();
      if (field.type == TType.STOP) { 
        break;
      }
      _Fields fieldId = _Fields.findByThriftId(field.id);
      if (fieldId == null) {
        TProtocolUtil.skip(iprot, field.type);
      } else {
        switch (fieldId) {
          case ID:
            if (field.type == TType.I64) {
              this.id = iprot.readI64();
              setIdIsSet(true);
            } else { 
              TProtocolUtil.skip(iprot, field.type);
            }
            break;
          case NAME:
            if (field.type == TType.STRING) {
              this.name = iprot.readString();
            } else { 
              TProtocolUtil.skip(iprot, field.type);
            }
            break;
          case CHILD_CATEGORIES:
            if (field.type == TType.LIST) {
              {
                TList _list0 = iprot.readListBegin();
                this.childCategories = new ArrayList<Long>(_list0.size);
                for (int _i1 = 0; _i1 < _list0.size; ++_i1)
                {
                  long _elem2;
                  _elem2 = iprot.readI64();
                  this.childCategories.add(_elem2);
                }
                iprot.readListEnd();
              }
            } else { 
              TProtocolUtil.skip(iprot, field.type);
            }
            break;
          case PARENT_ID:
            if (field.type == TType.I64) {
              this.parent_id = iprot.readI64();
              setParent_idIsSet(true);
            } else { 
              TProtocolUtil.skip(iprot, field.type);
            }
            break;
          case IS_TOP_LEVEL:
            if (field.type == TType.BOOL) {
              this.isTopLevel = iprot.readBool();
              setIsTopLevelIsSet(true);
            } else { 
              TProtocolUtil.skip(iprot, field.type);
            }
            break;
          case ADDED_ON:
            if (field.type == TType.I64) {
              this.addedOn = iprot.readI64();
              setAddedOnIsSet(true);
            } else { 
              TProtocolUtil.skip(iprot, field.type);
            }
            break;
          case CATEGORY_STATUS:
            if (field.type == TType.I32) {
              this.categoryStatus = status.findByValue(iprot.readI32());
            } else { 
              TProtocolUtil.skip(iprot, field.type);
            }
            break;
        }
        iprot.readFieldEnd();
      }
    }
    iprot.readStructEnd();
    validate();
  }

  public void write(TProtocol oprot) throws TException {
    validate();

    oprot.writeStructBegin(STRUCT_DESC);
    oprot.writeFieldBegin(ID_FIELD_DESC);
    oprot.writeI64(this.id);
    oprot.writeFieldEnd();
    if (this.name != null) {
      oprot.writeFieldBegin(NAME_FIELD_DESC);
      oprot.writeString(this.name);
      oprot.writeFieldEnd();
    }
    if (this.childCategories != null) {
      oprot.writeFieldBegin(CHILD_CATEGORIES_FIELD_DESC);
      {
        oprot.writeListBegin(new TList(TType.I64, this.childCategories.size()));
        for (long _iter3 : this.childCategories)
        {
          oprot.writeI64(_iter3);
        }
        oprot.writeListEnd();
      }
      oprot.writeFieldEnd();
    }
    oprot.writeFieldBegin(PARENT_ID_FIELD_DESC);
    oprot.writeI64(this.parent_id);
    oprot.writeFieldEnd();
    oprot.writeFieldBegin(IS_TOP_LEVEL_FIELD_DESC);
    oprot.writeBool(this.isTopLevel);
    oprot.writeFieldEnd();
    oprot.writeFieldBegin(ADDED_ON_FIELD_DESC);
    oprot.writeI64(this.addedOn);
    oprot.writeFieldEnd();
    if (this.categoryStatus != null) {
      oprot.writeFieldBegin(CATEGORY_STATUS_FIELD_DESC);
      oprot.writeI32(this.categoryStatus.getValue());
      oprot.writeFieldEnd();
    }
    oprot.writeFieldStop();
    oprot.writeStructEnd();
  }

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

    sb.append("id:");
    sb.append(this.id);
    first = false;
    if (!first) sb.append(", ");
    sb.append("name:");
    if (this.name == null) {
      sb.append("null");
    } else {
      sb.append(this.name);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("childCategories:");
    if (this.childCategories == null) {
      sb.append("null");
    } else {
      sb.append(this.childCategories);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("parent_id:");
    sb.append(this.parent_id);
    first = false;
    if (!first) sb.append(", ");
    sb.append("isTopLevel:");
    sb.append(this.isTopLevel);
    first = false;
    if (!first) sb.append(", ");
    sb.append("addedOn:");
    sb.append(this.addedOn);
    first = false;
    if (!first) sb.append(", ");
    sb.append("categoryStatus:");
    if (this.categoryStatus == null) {
      sb.append("null");
    } else {
      String categoryStatus_name = categoryStatus.name();
      if (categoryStatus_name != null) {
        sb.append(categoryStatus_name);
        sb.append(" (");
      }
      sb.append(this.categoryStatus);
      if (categoryStatus_name != null) {
        sb.append(")");
      }
    }
    first = false;
    sb.append(")");
    return sb.toString();
  }

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

}