/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
/*
 * Autogenerated by Thrift Compiler (0.17.0)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
package org.apache.accumulo.core.dataImpl.thrift;

@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"})
public class TKeyExtent implements org.apache.thrift.TBase<TKeyExtent, TKeyExtent._Fields>, java.io.Serializable, Cloneable, Comparable<TKeyExtent> {
  private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TKeyExtent");

  private static final org.apache.thrift.protocol.TField TABLE_FIELD_DESC = new org.apache.thrift.protocol.TField("table", org.apache.thrift.protocol.TType.STRING, (short)1);
  private static final org.apache.thrift.protocol.TField END_ROW_FIELD_DESC = new org.apache.thrift.protocol.TField("endRow", org.apache.thrift.protocol.TType.STRING, (short)2);
  private static final org.apache.thrift.protocol.TField PREV_END_ROW_FIELD_DESC = new org.apache.thrift.protocol.TField("prevEndRow", org.apache.thrift.protocol.TType.STRING, (short)3);

  private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new TKeyExtentStandardSchemeFactory();
  private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new TKeyExtentTupleSchemeFactory();

  public @org.apache.thrift.annotation.Nullable java.nio.ByteBuffer table; // required
  public @org.apache.thrift.annotation.Nullable java.nio.ByteBuffer endRow; // required
  public @org.apache.thrift.annotation.Nullable java.nio.ByteBuffer prevEndRow; // 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 {
    TABLE((short)1, "table"),
    END_ROW((short)2, "endRow"),
    PREV_END_ROW((short)3, "prevEndRow");

    private static final java.util.Map<java.lang.String, _Fields> byName = new java.util.HashMap<java.lang.String, _Fields>();

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

    /**
     * Find the _Fields constant that matches fieldId, or null if its not found.
     */
    @org.apache.thrift.annotation.Nullable
    public static _Fields findByThriftId(int fieldId) {
      switch(fieldId) {
        case 1: // TABLE
          return TABLE;
        case 2: // END_ROW
          return END_ROW;
        case 3: // PREV_END_ROW
          return PREV_END_ROW;
        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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!");
      return fields;
    }

    /**
     * Find the _Fields constant that matches name, or null if its not found.
     */
    @org.apache.thrift.annotation.Nullable
    public static _Fields findByName(java.lang.String name) {
      return byName.get(name);
    }

    private final short _thriftId;
    private final java.lang.String _fieldName;

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

    @Override
    public short getThriftFieldId() {
      return _thriftId;
    }

    @Override
    public java.lang.String getFieldName() {
      return _fieldName;
    }
  }

  // isset id assignments
  public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
  static {
    java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
    tmpMap.put(_Fields.TABLE, new org.apache.thrift.meta_data.FieldMetaData("table", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , true)));
    tmpMap.put(_Fields.END_ROW, new org.apache.thrift.meta_data.FieldMetaData("endRow", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , true)));
    tmpMap.put(_Fields.PREV_END_ROW, new org.apache.thrift.meta_data.FieldMetaData("prevEndRow", org.apache.thrift.TFieldRequirementType.DEFAULT, 
        new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING        , true)));
    metaDataMap = java.util.Collections.unmodifiableMap(tmpMap);
    org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TKeyExtent.class, metaDataMap);
  }

  public TKeyExtent() {
  }

  public TKeyExtent(
    java.nio.ByteBuffer table,
    java.nio.ByteBuffer endRow,
    java.nio.ByteBuffer prevEndRow)
  {
    this();
    this.table = org.apache.thrift.TBaseHelper.copyBinary(table);
    this.endRow = org.apache.thrift.TBaseHelper.copyBinary(endRow);
    this.prevEndRow = org.apache.thrift.TBaseHelper.copyBinary(prevEndRow);
  }

  /**
   * Performs a deep copy on <i>other</i>.
   */
  public TKeyExtent(TKeyExtent other) {
    if (other.isSetTable()) {
      this.table = org.apache.thrift.TBaseHelper.copyBinary(other.table);
    }
    if (other.isSetEndRow()) {
      this.endRow = org.apache.thrift.TBaseHelper.copyBinary(other.endRow);
    }
    if (other.isSetPrevEndRow()) {
      this.prevEndRow = org.apache.thrift.TBaseHelper.copyBinary(other.prevEndRow);
    }
  }

  @Override
  public TKeyExtent deepCopy() {
    return new TKeyExtent(this);
  }

  @Override
  public void clear() {
    this.table = null;
    this.endRow = null;
    this.prevEndRow = null;
  }

  public byte[] getTable() {
    setTable(org.apache.thrift.TBaseHelper.rightSize(table));
    return table == null ? null : table.array();
  }

  public java.nio.ByteBuffer bufferForTable() {
    return org.apache.thrift.TBaseHelper.copyBinary(table);
  }

  public TKeyExtent setTable(byte[] table) {
    this.table = table == null ? (java.nio.ByteBuffer)null   : java.nio.ByteBuffer.wrap(table.clone());
    return this;
  }

  public TKeyExtent setTable(@org.apache.thrift.annotation.Nullable java.nio.ByteBuffer table) {
    this.table = org.apache.thrift.TBaseHelper.copyBinary(table);
    return this;
  }

  public void unsetTable() {
    this.table = null;
  }

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

  public void setTableIsSet(boolean value) {
    if (!value) {
      this.table = null;
    }
  }

  public byte[] getEndRow() {
    setEndRow(org.apache.thrift.TBaseHelper.rightSize(endRow));
    return endRow == null ? null : endRow.array();
  }

  public java.nio.ByteBuffer bufferForEndRow() {
    return org.apache.thrift.TBaseHelper.copyBinary(endRow);
  }

  public TKeyExtent setEndRow(byte[] endRow) {
    this.endRow = endRow == null ? (java.nio.ByteBuffer)null   : java.nio.ByteBuffer.wrap(endRow.clone());
    return this;
  }

  public TKeyExtent setEndRow(@org.apache.thrift.annotation.Nullable java.nio.ByteBuffer endRow) {
    this.endRow = org.apache.thrift.TBaseHelper.copyBinary(endRow);
    return this;
  }

  public void unsetEndRow() {
    this.endRow = null;
  }

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

  public void setEndRowIsSet(boolean value) {
    if (!value) {
      this.endRow = null;
    }
  }

  public byte[] getPrevEndRow() {
    setPrevEndRow(org.apache.thrift.TBaseHelper.rightSize(prevEndRow));
    return prevEndRow == null ? null : prevEndRow.array();
  }

  public java.nio.ByteBuffer bufferForPrevEndRow() {
    return org.apache.thrift.TBaseHelper.copyBinary(prevEndRow);
  }

  public TKeyExtent setPrevEndRow(byte[] prevEndRow) {
    this.prevEndRow = prevEndRow == null ? (java.nio.ByteBuffer)null   : java.nio.ByteBuffer.wrap(prevEndRow.clone());
    return this;
  }

  public TKeyExtent setPrevEndRow(@org.apache.thrift.annotation.Nullable java.nio.ByteBuffer prevEndRow) {
    this.prevEndRow = org.apache.thrift.TBaseHelper.copyBinary(prevEndRow);
    return this;
  }

  public void unsetPrevEndRow() {
    this.prevEndRow = null;
  }

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

  public void setPrevEndRowIsSet(boolean value) {
    if (!value) {
      this.prevEndRow = null;
    }
  }

  @Override
  public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) {
    switch (field) {
    case TABLE:
      if (value == null) {
        unsetTable();
      } else {
        if (value instanceof byte[]) {
          setTable((byte[])value);
        } else {
          setTable((java.nio.ByteBuffer)value);
        }
      }
      break;

    case END_ROW:
      if (value == null) {
        unsetEndRow();
      } else {
        if (value instanceof byte[]) {
          setEndRow((byte[])value);
        } else {
          setEndRow((java.nio.ByteBuffer)value);
        }
      }
      break;

    case PREV_END_ROW:
      if (value == null) {
        unsetPrevEndRow();
      } else {
        if (value instanceof byte[]) {
          setPrevEndRow((byte[])value);
        } else {
          setPrevEndRow((java.nio.ByteBuffer)value);
        }
      }
      break;

    }
  }

  @org.apache.thrift.annotation.Nullable
  @Override
  public java.lang.Object getFieldValue(_Fields field) {
    switch (field) {
    case TABLE:
      return getTable();

    case END_ROW:
      return getEndRow();

    case PREV_END_ROW:
      return getPrevEndRow();

    }
    throw new java.lang.IllegalStateException();
  }

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

    switch (field) {
    case TABLE:
      return isSetTable();
    case END_ROW:
      return isSetEndRow();
    case PREV_END_ROW:
      return isSetPrevEndRow();
    }
    throw new java.lang.IllegalStateException();
  }

  @Override
  public boolean equals(java.lang.Object that) {
    if (that instanceof TKeyExtent)
      return this.equals((TKeyExtent)that);
    return false;
  }

  public boolean equals(TKeyExtent that) {
    if (that == null)
      return false;
    if (this == that)
      return true;

    boolean this_present_table = true && this.isSetTable();
    boolean that_present_table = true && that.isSetTable();
    if (this_present_table || that_present_table) {
      if (!(this_present_table && that_present_table))
        return false;
      if (!this.table.equals(that.table))
        return false;
    }

    boolean this_present_endRow = true && this.isSetEndRow();
    boolean that_present_endRow = true && that.isSetEndRow();
    if (this_present_endRow || that_present_endRow) {
      if (!(this_present_endRow && that_present_endRow))
        return false;
      if (!this.endRow.equals(that.endRow))
        return false;
    }

    boolean this_present_prevEndRow = true && this.isSetPrevEndRow();
    boolean that_present_prevEndRow = true && that.isSetPrevEndRow();
    if (this_present_prevEndRow || that_present_prevEndRow) {
      if (!(this_present_prevEndRow && that_present_prevEndRow))
        return false;
      if (!this.prevEndRow.equals(that.prevEndRow))
        return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    int hashCode = 1;

    hashCode = hashCode * 8191 + ((isSetTable()) ? 131071 : 524287);
    if (isSetTable())
      hashCode = hashCode * 8191 + table.hashCode();

    hashCode = hashCode * 8191 + ((isSetEndRow()) ? 131071 : 524287);
    if (isSetEndRow())
      hashCode = hashCode * 8191 + endRow.hashCode();

    hashCode = hashCode * 8191 + ((isSetPrevEndRow()) ? 131071 : 524287);
    if (isSetPrevEndRow())
      hashCode = hashCode * 8191 + prevEndRow.hashCode();

    return hashCode;
  }

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

    int lastComparison = 0;

    lastComparison = java.lang.Boolean.compare(isSetTable(), other.isSetTable());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetTable()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.table, other.table);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = java.lang.Boolean.compare(isSetEndRow(), other.isSetEndRow());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetEndRow()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.endRow, other.endRow);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    lastComparison = java.lang.Boolean.compare(isSetPrevEndRow(), other.isSetPrevEndRow());
    if (lastComparison != 0) {
      return lastComparison;
    }
    if (isSetPrevEndRow()) {
      lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.prevEndRow, other.prevEndRow);
      if (lastComparison != 0) {
        return lastComparison;
      }
    }
    return 0;
  }

  @org.apache.thrift.annotation.Nullable
  @Override
  public _Fields fieldForId(int fieldId) {
    return _Fields.findByThriftId(fieldId);
  }

  @Override
  public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
    scheme(iprot).read(iprot, this);
  }

  @Override
  public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
    scheme(oprot).write(oprot, this);
  }

  @Override
  public java.lang.String toString() {
    java.lang.StringBuilder sb = new java.lang.StringBuilder("TKeyExtent(");
    boolean first = true;

    sb.append("table:");
    if (this.table == null) {
      sb.append("null");
    } else {
      org.apache.thrift.TBaseHelper.toString(this.table, sb);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("endRow:");
    if (this.endRow == null) {
      sb.append("null");
    } else {
      org.apache.thrift.TBaseHelper.toString(this.endRow, sb);
    }
    first = false;
    if (!first) sb.append(", ");
    sb.append("prevEndRow:");
    if (this.prevEndRow == null) {
      sb.append("null");
    } else {
      org.apache.thrift.TBaseHelper.toString(this.prevEndRow, sb);
    }
    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, java.lang.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 TKeyExtentStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
    @Override
    public TKeyExtentStandardScheme getScheme() {
      return new TKeyExtentStandardScheme();
    }
  }

  private static class TKeyExtentStandardScheme extends org.apache.thrift.scheme.StandardScheme<TKeyExtent> {

    @Override
    public void read(org.apache.thrift.protocol.TProtocol iprot, TKeyExtent 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: // TABLE
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.table = iprot.readBinary();
              struct.setTableIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 2: // END_ROW
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.endRow = iprot.readBinary();
              struct.setEndRowIsSet(true);
            } else { 
              org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
            }
            break;
          case 3: // PREV_END_ROW
            if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
              struct.prevEndRow = iprot.readBinary();
              struct.setPrevEndRowIsSet(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();
    }

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

      oprot.writeStructBegin(STRUCT_DESC);
      if (struct.table != null) {
        oprot.writeFieldBegin(TABLE_FIELD_DESC);
        oprot.writeBinary(struct.table);
        oprot.writeFieldEnd();
      }
      if (struct.endRow != null) {
        oprot.writeFieldBegin(END_ROW_FIELD_DESC);
        oprot.writeBinary(struct.endRow);
        oprot.writeFieldEnd();
      }
      if (struct.prevEndRow != null) {
        oprot.writeFieldBegin(PREV_END_ROW_FIELD_DESC);
        oprot.writeBinary(struct.prevEndRow);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }

  }

  private static class TKeyExtentTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory {
    @Override
    public TKeyExtentTupleScheme getScheme() {
      return new TKeyExtentTupleScheme();
    }
  }

  private static class TKeyExtentTupleScheme extends org.apache.thrift.scheme.TupleScheme<TKeyExtent> {

    @Override
    public void write(org.apache.thrift.protocol.TProtocol prot, TKeyExtent struct) throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
      java.util.BitSet optionals = new java.util.BitSet();
      if (struct.isSetTable()) {
        optionals.set(0);
      }
      if (struct.isSetEndRow()) {
        optionals.set(1);
      }
      if (struct.isSetPrevEndRow()) {
        optionals.set(2);
      }
      oprot.writeBitSet(optionals, 3);
      if (struct.isSetTable()) {
        oprot.writeBinary(struct.table);
      }
      if (struct.isSetEndRow()) {
        oprot.writeBinary(struct.endRow);
      }
      if (struct.isSetPrevEndRow()) {
        oprot.writeBinary(struct.prevEndRow);
      }
    }

    @Override
    public void read(org.apache.thrift.protocol.TProtocol prot, TKeyExtent struct) throws org.apache.thrift.TException {
      org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot;
      java.util.BitSet incoming = iprot.readBitSet(3);
      if (incoming.get(0)) {
        struct.table = iprot.readBinary();
        struct.setTableIsSet(true);
      }
      if (incoming.get(1)) {
        struct.endRow = iprot.readBinary();
        struct.setEndRowIsSet(true);
      }
      if (incoming.get(2)) {
        struct.prevEndRow = iprot.readBinary();
        struct.setPrevEndRowIsSet(true);
      }
    }
  }

  private static <S extends org.apache.thrift.scheme.IScheme> S scheme(org.apache.thrift.protocol.TProtocol proto) {
    return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme();
  }
  private static void unusedMethod() {}
}

