// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: google/datastore/v1/query.proto

package com.google.datastore.v1;

/**
 * <pre>
 * A query for entities.
 * </pre>
 *
 * Protobuf type {@code google.datastore.v1.Query}
 */
public  final class Query extends
    com.google.protobuf.GeneratedMessageV3 implements
    // @@protoc_insertion_point(message_implements:google.datastore.v1.Query)
    QueryOrBuilder {
private static final long serialVersionUID = 0L;
  // Use Query.newBuilder() to construct.
  private Query(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
    super(builder);
  }
  private Query() {
    projection_ = java.util.Collections.emptyList();
    kind_ = java.util.Collections.emptyList();
    order_ = java.util.Collections.emptyList();
    distinctOn_ = java.util.Collections.emptyList();
    startCursor_ = com.google.protobuf.ByteString.EMPTY;
    endCursor_ = com.google.protobuf.ByteString.EMPTY;
    offset_ = 0;
  }

  @java.lang.Override
  public final com.google.protobuf.UnknownFieldSet
  getUnknownFields() {
    return this.unknownFields;
  }
  private Query(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    this();
    if (extensionRegistry == null) {
      throw new java.lang.NullPointerException();
    }
    int mutable_bitField0_ = 0;
    com.google.protobuf.UnknownFieldSet.Builder unknownFields =
        com.google.protobuf.UnknownFieldSet.newBuilder();
    try {
      boolean done = false;
      while (!done) {
        int tag = input.readTag();
        switch (tag) {
          case 0:
            done = true;
            break;
          default: {
            if (!parseUnknownFieldProto3(
                input, unknownFields, extensionRegistry, tag)) {
              done = true;
            }
            break;
          }
          case 18: {
            if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
              projection_ = new java.util.ArrayList<com.google.datastore.v1.Projection>();
              mutable_bitField0_ |= 0x00000001;
            }
            projection_.add(
                input.readMessage(com.google.datastore.v1.Projection.parser(), extensionRegistry));
            break;
          }
          case 26: {
            if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) {
              kind_ = new java.util.ArrayList<com.google.datastore.v1.KindExpression>();
              mutable_bitField0_ |= 0x00000002;
            }
            kind_.add(
                input.readMessage(com.google.datastore.v1.KindExpression.parser(), extensionRegistry));
            break;
          }
          case 34: {
            com.google.datastore.v1.Filter.Builder subBuilder = null;
            if (filter_ != null) {
              subBuilder = filter_.toBuilder();
            }
            filter_ = input.readMessage(com.google.datastore.v1.Filter.parser(), extensionRegistry);
            if (subBuilder != null) {
              subBuilder.mergeFrom(filter_);
              filter_ = subBuilder.buildPartial();
            }

            break;
          }
          case 42: {
            if (!((mutable_bitField0_ & 0x00000008) == 0x00000008)) {
              order_ = new java.util.ArrayList<com.google.datastore.v1.PropertyOrder>();
              mutable_bitField0_ |= 0x00000008;
            }
            order_.add(
                input.readMessage(com.google.datastore.v1.PropertyOrder.parser(), extensionRegistry));
            break;
          }
          case 50: {
            if (!((mutable_bitField0_ & 0x00000010) == 0x00000010)) {
              distinctOn_ = new java.util.ArrayList<com.google.datastore.v1.PropertyReference>();
              mutable_bitField0_ |= 0x00000010;
            }
            distinctOn_.add(
                input.readMessage(com.google.datastore.v1.PropertyReference.parser(), extensionRegistry));
            break;
          }
          case 58: {

            startCursor_ = input.readBytes();
            break;
          }
          case 66: {

            endCursor_ = input.readBytes();
            break;
          }
          case 80: {

            offset_ = input.readInt32();
            break;
          }
          case 98: {
            com.google.protobuf.Int32Value.Builder subBuilder = null;
            if (limit_ != null) {
              subBuilder = limit_.toBuilder();
            }
            limit_ = input.readMessage(com.google.protobuf.Int32Value.parser(), extensionRegistry);
            if (subBuilder != null) {
              subBuilder.mergeFrom(limit_);
              limit_ = subBuilder.buildPartial();
            }

            break;
          }
        }
      }
    } catch (com.google.protobuf.InvalidProtocolBufferException e) {
      throw e.setUnfinishedMessage(this);
    } catch (java.io.IOException e) {
      throw new com.google.protobuf.InvalidProtocolBufferException(
          e).setUnfinishedMessage(this);
    } finally {
      if (((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
        projection_ = java.util.Collections.unmodifiableList(projection_);
      }
      if (((mutable_bitField0_ & 0x00000002) == 0x00000002)) {
        kind_ = java.util.Collections.unmodifiableList(kind_);
      }
      if (((mutable_bitField0_ & 0x00000008) == 0x00000008)) {
        order_ = java.util.Collections.unmodifiableList(order_);
      }
      if (((mutable_bitField0_ & 0x00000010) == 0x00000010)) {
        distinctOn_ = java.util.Collections.unmodifiableList(distinctOn_);
      }
      this.unknownFields = unknownFields.build();
      makeExtensionsImmutable();
    }
  }
  public static final com.google.protobuf.Descriptors.Descriptor
      getDescriptor() {
    return com.google.datastore.v1.QueryProto.internal_static_google_datastore_v1_Query_descriptor;
  }

  protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
      internalGetFieldAccessorTable() {
    return com.google.datastore.v1.QueryProto.internal_static_google_datastore_v1_Query_fieldAccessorTable
        .ensureFieldAccessorsInitialized(
            com.google.datastore.v1.Query.class, com.google.datastore.v1.Query.Builder.class);
  }

  private int bitField0_;
  public static final int PROJECTION_FIELD_NUMBER = 2;
  private java.util.List<com.google.datastore.v1.Projection> projection_;
  /**
   * <pre>
   * The projection to return. Defaults to returning all properties.
   * </pre>
   *
   * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
   */
  public java.util.List<com.google.datastore.v1.Projection> getProjectionList() {
    return projection_;
  }
  /**
   * <pre>
   * The projection to return. Defaults to returning all properties.
   * </pre>
   *
   * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
   */
  public java.util.List<? extends com.google.datastore.v1.ProjectionOrBuilder> 
      getProjectionOrBuilderList() {
    return projection_;
  }
  /**
   * <pre>
   * The projection to return. Defaults to returning all properties.
   * </pre>
   *
   * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
   */
  public int getProjectionCount() {
    return projection_.size();
  }
  /**
   * <pre>
   * The projection to return. Defaults to returning all properties.
   * </pre>
   *
   * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
   */
  public com.google.datastore.v1.Projection getProjection(int index) {
    return projection_.get(index);
  }
  /**
   * <pre>
   * The projection to return. Defaults to returning all properties.
   * </pre>
   *
   * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
   */
  public com.google.datastore.v1.ProjectionOrBuilder getProjectionOrBuilder(
      int index) {
    return projection_.get(index);
  }

  public static final int KIND_FIELD_NUMBER = 3;
  private java.util.List<com.google.datastore.v1.KindExpression> kind_;
  /**
   * <pre>
   * The kinds to query (if empty, returns entities of all kinds).
   * Currently at most 1 kind may be specified.
   * </pre>
   *
   * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
   */
  public java.util.List<com.google.datastore.v1.KindExpression> getKindList() {
    return kind_;
  }
  /**
   * <pre>
   * The kinds to query (if empty, returns entities of all kinds).
   * Currently at most 1 kind may be specified.
   * </pre>
   *
   * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
   */
  public java.util.List<? extends com.google.datastore.v1.KindExpressionOrBuilder> 
      getKindOrBuilderList() {
    return kind_;
  }
  /**
   * <pre>
   * The kinds to query (if empty, returns entities of all kinds).
   * Currently at most 1 kind may be specified.
   * </pre>
   *
   * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
   */
  public int getKindCount() {
    return kind_.size();
  }
  /**
   * <pre>
   * The kinds to query (if empty, returns entities of all kinds).
   * Currently at most 1 kind may be specified.
   * </pre>
   *
   * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
   */
  public com.google.datastore.v1.KindExpression getKind(int index) {
    return kind_.get(index);
  }
  /**
   * <pre>
   * The kinds to query (if empty, returns entities of all kinds).
   * Currently at most 1 kind may be specified.
   * </pre>
   *
   * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
   */
  public com.google.datastore.v1.KindExpressionOrBuilder getKindOrBuilder(
      int index) {
    return kind_.get(index);
  }

  public static final int FILTER_FIELD_NUMBER = 4;
  private com.google.datastore.v1.Filter filter_;
  /**
   * <pre>
   * The filter to apply.
   * </pre>
   *
   * <code>.google.datastore.v1.Filter filter = 4;</code>
   */
  public boolean hasFilter() {
    return filter_ != null;
  }
  /**
   * <pre>
   * The filter to apply.
   * </pre>
   *
   * <code>.google.datastore.v1.Filter filter = 4;</code>
   */
  public com.google.datastore.v1.Filter getFilter() {
    return filter_ == null ? com.google.datastore.v1.Filter.getDefaultInstance() : filter_;
  }
  /**
   * <pre>
   * The filter to apply.
   * </pre>
   *
   * <code>.google.datastore.v1.Filter filter = 4;</code>
   */
  public com.google.datastore.v1.FilterOrBuilder getFilterOrBuilder() {
    return getFilter();
  }

  public static final int ORDER_FIELD_NUMBER = 5;
  private java.util.List<com.google.datastore.v1.PropertyOrder> order_;
  /**
   * <pre>
   * The order to apply to the query results (if empty, order is unspecified).
   * </pre>
   *
   * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
   */
  public java.util.List<com.google.datastore.v1.PropertyOrder> getOrderList() {
    return order_;
  }
  /**
   * <pre>
   * The order to apply to the query results (if empty, order is unspecified).
   * </pre>
   *
   * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
   */
  public java.util.List<? extends com.google.datastore.v1.PropertyOrderOrBuilder> 
      getOrderOrBuilderList() {
    return order_;
  }
  /**
   * <pre>
   * The order to apply to the query results (if empty, order is unspecified).
   * </pre>
   *
   * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
   */
  public int getOrderCount() {
    return order_.size();
  }
  /**
   * <pre>
   * The order to apply to the query results (if empty, order is unspecified).
   * </pre>
   *
   * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
   */
  public com.google.datastore.v1.PropertyOrder getOrder(int index) {
    return order_.get(index);
  }
  /**
   * <pre>
   * The order to apply to the query results (if empty, order is unspecified).
   * </pre>
   *
   * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
   */
  public com.google.datastore.v1.PropertyOrderOrBuilder getOrderOrBuilder(
      int index) {
    return order_.get(index);
  }

  public static final int DISTINCT_ON_FIELD_NUMBER = 6;
  private java.util.List<com.google.datastore.v1.PropertyReference> distinctOn_;
  /**
   * <pre>
   * The properties to make distinct. The query results will contain the first
   * result for each distinct combination of values for the given properties
   * (if empty, all results are returned).
   * </pre>
   *
   * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
   */
  public java.util.List<com.google.datastore.v1.PropertyReference> getDistinctOnList() {
    return distinctOn_;
  }
  /**
   * <pre>
   * The properties to make distinct. The query results will contain the first
   * result for each distinct combination of values for the given properties
   * (if empty, all results are returned).
   * </pre>
   *
   * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
   */
  public java.util.List<? extends com.google.datastore.v1.PropertyReferenceOrBuilder> 
      getDistinctOnOrBuilderList() {
    return distinctOn_;
  }
  /**
   * <pre>
   * The properties to make distinct. The query results will contain the first
   * result for each distinct combination of values for the given properties
   * (if empty, all results are returned).
   * </pre>
   *
   * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
   */
  public int getDistinctOnCount() {
    return distinctOn_.size();
  }
  /**
   * <pre>
   * The properties to make distinct. The query results will contain the first
   * result for each distinct combination of values for the given properties
   * (if empty, all results are returned).
   * </pre>
   *
   * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
   */
  public com.google.datastore.v1.PropertyReference getDistinctOn(int index) {
    return distinctOn_.get(index);
  }
  /**
   * <pre>
   * The properties to make distinct. The query results will contain the first
   * result for each distinct combination of values for the given properties
   * (if empty, all results are returned).
   * </pre>
   *
   * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
   */
  public com.google.datastore.v1.PropertyReferenceOrBuilder getDistinctOnOrBuilder(
      int index) {
    return distinctOn_.get(index);
  }

  public static final int START_CURSOR_FIELD_NUMBER = 7;
  private com.google.protobuf.ByteString startCursor_;
  /**
   * <pre>
   * A starting point for the query results. Query cursors are
   * returned in query result batches and
   * [can only be used to continue the same query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
   * </pre>
   *
   * <code>bytes start_cursor = 7;</code>
   */
  public com.google.protobuf.ByteString getStartCursor() {
    return startCursor_;
  }

  public static final int END_CURSOR_FIELD_NUMBER = 8;
  private com.google.protobuf.ByteString endCursor_;
  /**
   * <pre>
   * An ending point for the query results. Query cursors are
   * returned in query result batches and
   * [can only be used to limit the same query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
   * </pre>
   *
   * <code>bytes end_cursor = 8;</code>
   */
  public com.google.protobuf.ByteString getEndCursor() {
    return endCursor_;
  }

  public static final int OFFSET_FIELD_NUMBER = 10;
  private int offset_;
  /**
   * <pre>
   * The number of results to skip. Applies before limit, but after all other
   * constraints. Optional. Must be &gt;= 0 if specified.
   * </pre>
   *
   * <code>int32 offset = 10;</code>
   */
  public int getOffset() {
    return offset_;
  }

  public static final int LIMIT_FIELD_NUMBER = 12;
  private com.google.protobuf.Int32Value limit_;
  /**
   * <pre>
   * The maximum number of results to return. Applies after all other
   * constraints. Optional.
   * Unspecified is interpreted as no limit.
   * Must be &gt;= 0 if specified.
   * </pre>
   *
   * <code>.google.protobuf.Int32Value limit = 12;</code>
   */
  public boolean hasLimit() {
    return limit_ != null;
  }
  /**
   * <pre>
   * The maximum number of results to return. Applies after all other
   * constraints. Optional.
   * Unspecified is interpreted as no limit.
   * Must be &gt;= 0 if specified.
   * </pre>
   *
   * <code>.google.protobuf.Int32Value limit = 12;</code>
   */
  public com.google.protobuf.Int32Value getLimit() {
    return limit_ == null ? com.google.protobuf.Int32Value.getDefaultInstance() : limit_;
  }
  /**
   * <pre>
   * The maximum number of results to return. Applies after all other
   * constraints. Optional.
   * Unspecified is interpreted as no limit.
   * Must be &gt;= 0 if specified.
   * </pre>
   *
   * <code>.google.protobuf.Int32Value limit = 12;</code>
   */
  public com.google.protobuf.Int32ValueOrBuilder getLimitOrBuilder() {
    return getLimit();
  }

  private byte memoizedIsInitialized = -1;
  public final boolean isInitialized() {
    byte isInitialized = memoizedIsInitialized;
    if (isInitialized == 1) return true;
    if (isInitialized == 0) return false;

    memoizedIsInitialized = 1;
    return true;
  }

  public void writeTo(com.google.protobuf.CodedOutputStream output)
                      throws java.io.IOException {
    for (int i = 0; i < projection_.size(); i++) {
      output.writeMessage(2, projection_.get(i));
    }
    for (int i = 0; i < kind_.size(); i++) {
      output.writeMessage(3, kind_.get(i));
    }
    if (filter_ != null) {
      output.writeMessage(4, getFilter());
    }
    for (int i = 0; i < order_.size(); i++) {
      output.writeMessage(5, order_.get(i));
    }
    for (int i = 0; i < distinctOn_.size(); i++) {
      output.writeMessage(6, distinctOn_.get(i));
    }
    if (!startCursor_.isEmpty()) {
      output.writeBytes(7, startCursor_);
    }
    if (!endCursor_.isEmpty()) {
      output.writeBytes(8, endCursor_);
    }
    if (offset_ != 0) {
      output.writeInt32(10, offset_);
    }
    if (limit_ != null) {
      output.writeMessage(12, getLimit());
    }
    unknownFields.writeTo(output);
  }

  public int getSerializedSize() {
    int size = memoizedSize;
    if (size != -1) return size;

    size = 0;
    for (int i = 0; i < projection_.size(); i++) {
      size += com.google.protobuf.CodedOutputStream
        .computeMessageSize(2, projection_.get(i));
    }
    for (int i = 0; i < kind_.size(); i++) {
      size += com.google.protobuf.CodedOutputStream
        .computeMessageSize(3, kind_.get(i));
    }
    if (filter_ != null) {
      size += com.google.protobuf.CodedOutputStream
        .computeMessageSize(4, getFilter());
    }
    for (int i = 0; i < order_.size(); i++) {
      size += com.google.protobuf.CodedOutputStream
        .computeMessageSize(5, order_.get(i));
    }
    for (int i = 0; i < distinctOn_.size(); i++) {
      size += com.google.protobuf.CodedOutputStream
        .computeMessageSize(6, distinctOn_.get(i));
    }
    if (!startCursor_.isEmpty()) {
      size += com.google.protobuf.CodedOutputStream
        .computeBytesSize(7, startCursor_);
    }
    if (!endCursor_.isEmpty()) {
      size += com.google.protobuf.CodedOutputStream
        .computeBytesSize(8, endCursor_);
    }
    if (offset_ != 0) {
      size += com.google.protobuf.CodedOutputStream
        .computeInt32Size(10, offset_);
    }
    if (limit_ != null) {
      size += com.google.protobuf.CodedOutputStream
        .computeMessageSize(12, getLimit());
    }
    size += unknownFields.getSerializedSize();
    memoizedSize = size;
    return size;
  }

  @java.lang.Override
  public boolean equals(final java.lang.Object obj) {
    if (obj == this) {
     return true;
    }
    if (!(obj instanceof com.google.datastore.v1.Query)) {
      return super.equals(obj);
    }
    com.google.datastore.v1.Query other = (com.google.datastore.v1.Query) obj;

    boolean result = true;
    result = result && getProjectionList()
        .equals(other.getProjectionList());
    result = result && getKindList()
        .equals(other.getKindList());
    result = result && (hasFilter() == other.hasFilter());
    if (hasFilter()) {
      result = result && getFilter()
          .equals(other.getFilter());
    }
    result = result && getOrderList()
        .equals(other.getOrderList());
    result = result && getDistinctOnList()
        .equals(other.getDistinctOnList());
    result = result && getStartCursor()
        .equals(other.getStartCursor());
    result = result && getEndCursor()
        .equals(other.getEndCursor());
    result = result && (getOffset()
        == other.getOffset());
    result = result && (hasLimit() == other.hasLimit());
    if (hasLimit()) {
      result = result && getLimit()
          .equals(other.getLimit());
    }
    result = result && unknownFields.equals(other.unknownFields);
    return result;
  }

  @java.lang.Override
  public int hashCode() {
    if (memoizedHashCode != 0) {
      return memoizedHashCode;
    }
    int hash = 41;
    hash = (19 * hash) + getDescriptor().hashCode();
    if (getProjectionCount() > 0) {
      hash = (37 * hash) + PROJECTION_FIELD_NUMBER;
      hash = (53 * hash) + getProjectionList().hashCode();
    }
    if (getKindCount() > 0) {
      hash = (37 * hash) + KIND_FIELD_NUMBER;
      hash = (53 * hash) + getKindList().hashCode();
    }
    if (hasFilter()) {
      hash = (37 * hash) + FILTER_FIELD_NUMBER;
      hash = (53 * hash) + getFilter().hashCode();
    }
    if (getOrderCount() > 0) {
      hash = (37 * hash) + ORDER_FIELD_NUMBER;
      hash = (53 * hash) + getOrderList().hashCode();
    }
    if (getDistinctOnCount() > 0) {
      hash = (37 * hash) + DISTINCT_ON_FIELD_NUMBER;
      hash = (53 * hash) + getDistinctOnList().hashCode();
    }
    hash = (37 * hash) + START_CURSOR_FIELD_NUMBER;
    hash = (53 * hash) + getStartCursor().hashCode();
    hash = (37 * hash) + END_CURSOR_FIELD_NUMBER;
    hash = (53 * hash) + getEndCursor().hashCode();
    hash = (37 * hash) + OFFSET_FIELD_NUMBER;
    hash = (53 * hash) + getOffset();
    if (hasLimit()) {
      hash = (37 * hash) + LIMIT_FIELD_NUMBER;
      hash = (53 * hash) + getLimit().hashCode();
    }
    hash = (29 * hash) + unknownFields.hashCode();
    memoizedHashCode = hash;
    return hash;
  }

  public static com.google.datastore.v1.Query parseFrom(
      java.nio.ByteBuffer data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.google.datastore.v1.Query parseFrom(
      java.nio.ByteBuffer data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.google.datastore.v1.Query parseFrom(
      com.google.protobuf.ByteString data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.google.datastore.v1.Query parseFrom(
      com.google.protobuf.ByteString data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.google.datastore.v1.Query parseFrom(byte[] data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.google.datastore.v1.Query parseFrom(
      byte[] data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.google.datastore.v1.Query parseFrom(java.io.InputStream input)
      throws java.io.IOException {
    return com.google.protobuf.GeneratedMessageV3
        .parseWithIOException(PARSER, input);
  }
  public static com.google.datastore.v1.Query parseFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return com.google.protobuf.GeneratedMessageV3
        .parseWithIOException(PARSER, input, extensionRegistry);
  }
  public static com.google.datastore.v1.Query parseDelimitedFrom(java.io.InputStream input)
      throws java.io.IOException {
    return com.google.protobuf.GeneratedMessageV3
        .parseDelimitedWithIOException(PARSER, input);
  }
  public static com.google.datastore.v1.Query parseDelimitedFrom(
      java.io.InputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return com.google.protobuf.GeneratedMessageV3
        .parseDelimitedWithIOException(PARSER, input, extensionRegistry);
  }
  public static com.google.datastore.v1.Query parseFrom(
      com.google.protobuf.CodedInputStream input)
      throws java.io.IOException {
    return com.google.protobuf.GeneratedMessageV3
        .parseWithIOException(PARSER, input);
  }
  public static com.google.datastore.v1.Query parseFrom(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return com.google.protobuf.GeneratedMessageV3
        .parseWithIOException(PARSER, input, extensionRegistry);
  }

  public Builder newBuilderForType() { return newBuilder(); }
  public static Builder newBuilder() {
    return DEFAULT_INSTANCE.toBuilder();
  }
  public static Builder newBuilder(com.google.datastore.v1.Query prototype) {
    return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
  }
  public Builder toBuilder() {
    return this == DEFAULT_INSTANCE
        ? new Builder() : new Builder().mergeFrom(this);
  }

  @java.lang.Override
  protected Builder newBuilderForType(
      com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
    Builder builder = new Builder(parent);
    return builder;
  }
  /**
   * <pre>
   * A query for entities.
   * </pre>
   *
   * Protobuf type {@code google.datastore.v1.Query}
   */
  public static final class Builder extends
      com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
      // @@protoc_insertion_point(builder_implements:google.datastore.v1.Query)
      com.google.datastore.v1.QueryOrBuilder {
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return com.google.datastore.v1.QueryProto.internal_static_google_datastore_v1_Query_descriptor;
    }

    protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return com.google.datastore.v1.QueryProto.internal_static_google_datastore_v1_Query_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.google.datastore.v1.Query.class, com.google.datastore.v1.Query.Builder.class);
    }

    // Construct using com.google.datastore.v1.Query.newBuilder()
    private Builder() {
      maybeForceBuilderInitialization();
    }

    private Builder(
        com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
      super(parent);
      maybeForceBuilderInitialization();
    }
    private void maybeForceBuilderInitialization() {
      if (com.google.protobuf.GeneratedMessageV3
              .alwaysUseFieldBuilders) {
        getProjectionFieldBuilder();
        getKindFieldBuilder();
        getOrderFieldBuilder();
        getDistinctOnFieldBuilder();
      }
    }
    public Builder clear() {
      super.clear();
      if (projectionBuilder_ == null) {
        projection_ = java.util.Collections.emptyList();
        bitField0_ = (bitField0_ & ~0x00000001);
      } else {
        projectionBuilder_.clear();
      }
      if (kindBuilder_ == null) {
        kind_ = java.util.Collections.emptyList();
        bitField0_ = (bitField0_ & ~0x00000002);
      } else {
        kindBuilder_.clear();
      }
      if (filterBuilder_ == null) {
        filter_ = null;
      } else {
        filter_ = null;
        filterBuilder_ = null;
      }
      if (orderBuilder_ == null) {
        order_ = java.util.Collections.emptyList();
        bitField0_ = (bitField0_ & ~0x00000008);
      } else {
        orderBuilder_.clear();
      }
      if (distinctOnBuilder_ == null) {
        distinctOn_ = java.util.Collections.emptyList();
        bitField0_ = (bitField0_ & ~0x00000010);
      } else {
        distinctOnBuilder_.clear();
      }
      startCursor_ = com.google.protobuf.ByteString.EMPTY;

      endCursor_ = com.google.protobuf.ByteString.EMPTY;

      offset_ = 0;

      if (limitBuilder_ == null) {
        limit_ = null;
      } else {
        limit_ = null;
        limitBuilder_ = null;
      }
      return this;
    }

    public com.google.protobuf.Descriptors.Descriptor
        getDescriptorForType() {
      return com.google.datastore.v1.QueryProto.internal_static_google_datastore_v1_Query_descriptor;
    }

    public com.google.datastore.v1.Query getDefaultInstanceForType() {
      return com.google.datastore.v1.Query.getDefaultInstance();
    }

    public com.google.datastore.v1.Query build() {
      com.google.datastore.v1.Query result = buildPartial();
      if (!result.isInitialized()) {
        throw newUninitializedMessageException(result);
      }
      return result;
    }

    public com.google.datastore.v1.Query buildPartial() {
      com.google.datastore.v1.Query result = new com.google.datastore.v1.Query(this);
      int from_bitField0_ = bitField0_;
      int to_bitField0_ = 0;
      if (projectionBuilder_ == null) {
        if (((bitField0_ & 0x00000001) == 0x00000001)) {
          projection_ = java.util.Collections.unmodifiableList(projection_);
          bitField0_ = (bitField0_ & ~0x00000001);
        }
        result.projection_ = projection_;
      } else {
        result.projection_ = projectionBuilder_.build();
      }
      if (kindBuilder_ == null) {
        if (((bitField0_ & 0x00000002) == 0x00000002)) {
          kind_ = java.util.Collections.unmodifiableList(kind_);
          bitField0_ = (bitField0_ & ~0x00000002);
        }
        result.kind_ = kind_;
      } else {
        result.kind_ = kindBuilder_.build();
      }
      if (filterBuilder_ == null) {
        result.filter_ = filter_;
      } else {
        result.filter_ = filterBuilder_.build();
      }
      if (orderBuilder_ == null) {
        if (((bitField0_ & 0x00000008) == 0x00000008)) {
          order_ = java.util.Collections.unmodifiableList(order_);
          bitField0_ = (bitField0_ & ~0x00000008);
        }
        result.order_ = order_;
      } else {
        result.order_ = orderBuilder_.build();
      }
      if (distinctOnBuilder_ == null) {
        if (((bitField0_ & 0x00000010) == 0x00000010)) {
          distinctOn_ = java.util.Collections.unmodifiableList(distinctOn_);
          bitField0_ = (bitField0_ & ~0x00000010);
        }
        result.distinctOn_ = distinctOn_;
      } else {
        result.distinctOn_ = distinctOnBuilder_.build();
      }
      result.startCursor_ = startCursor_;
      result.endCursor_ = endCursor_;
      result.offset_ = offset_;
      if (limitBuilder_ == null) {
        result.limit_ = limit_;
      } else {
        result.limit_ = limitBuilder_.build();
      }
      result.bitField0_ = to_bitField0_;
      onBuilt();
      return result;
    }

    public Builder clone() {
      return (Builder) super.clone();
    }
    public Builder setField(
        com.google.protobuf.Descriptors.FieldDescriptor field,
        java.lang.Object value) {
      return (Builder) super.setField(field, value);
    }
    public Builder clearField(
        com.google.protobuf.Descriptors.FieldDescriptor field) {
      return (Builder) super.clearField(field);
    }
    public Builder clearOneof(
        com.google.protobuf.Descriptors.OneofDescriptor oneof) {
      return (Builder) super.clearOneof(oneof);
    }
    public Builder setRepeatedField(
        com.google.protobuf.Descriptors.FieldDescriptor field,
        int index, java.lang.Object value) {
      return (Builder) super.setRepeatedField(field, index, value);
    }
    public Builder addRepeatedField(
        com.google.protobuf.Descriptors.FieldDescriptor field,
        java.lang.Object value) {
      return (Builder) super.addRepeatedField(field, value);
    }
    public Builder mergeFrom(com.google.protobuf.Message other) {
      if (other instanceof com.google.datastore.v1.Query) {
        return mergeFrom((com.google.datastore.v1.Query)other);
      } else {
        super.mergeFrom(other);
        return this;
      }
    }

    public Builder mergeFrom(com.google.datastore.v1.Query other) {
      if (other == com.google.datastore.v1.Query.getDefaultInstance()) return this;
      if (projectionBuilder_ == null) {
        if (!other.projection_.isEmpty()) {
          if (projection_.isEmpty()) {
            projection_ = other.projection_;
            bitField0_ = (bitField0_ & ~0x00000001);
          } else {
            ensureProjectionIsMutable();
            projection_.addAll(other.projection_);
          }
          onChanged();
        }
      } else {
        if (!other.projection_.isEmpty()) {
          if (projectionBuilder_.isEmpty()) {
            projectionBuilder_.dispose();
            projectionBuilder_ = null;
            projection_ = other.projection_;
            bitField0_ = (bitField0_ & ~0x00000001);
            projectionBuilder_ = 
              com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ?
                 getProjectionFieldBuilder() : null;
          } else {
            projectionBuilder_.addAllMessages(other.projection_);
          }
        }
      }
      if (kindBuilder_ == null) {
        if (!other.kind_.isEmpty()) {
          if (kind_.isEmpty()) {
            kind_ = other.kind_;
            bitField0_ = (bitField0_ & ~0x00000002);
          } else {
            ensureKindIsMutable();
            kind_.addAll(other.kind_);
          }
          onChanged();
        }
      } else {
        if (!other.kind_.isEmpty()) {
          if (kindBuilder_.isEmpty()) {
            kindBuilder_.dispose();
            kindBuilder_ = null;
            kind_ = other.kind_;
            bitField0_ = (bitField0_ & ~0x00000002);
            kindBuilder_ = 
              com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ?
                 getKindFieldBuilder() : null;
          } else {
            kindBuilder_.addAllMessages(other.kind_);
          }
        }
      }
      if (other.hasFilter()) {
        mergeFilter(other.getFilter());
      }
      if (orderBuilder_ == null) {
        if (!other.order_.isEmpty()) {
          if (order_.isEmpty()) {
            order_ = other.order_;
            bitField0_ = (bitField0_ & ~0x00000008);
          } else {
            ensureOrderIsMutable();
            order_.addAll(other.order_);
          }
          onChanged();
        }
      } else {
        if (!other.order_.isEmpty()) {
          if (orderBuilder_.isEmpty()) {
            orderBuilder_.dispose();
            orderBuilder_ = null;
            order_ = other.order_;
            bitField0_ = (bitField0_ & ~0x00000008);
            orderBuilder_ = 
              com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ?
                 getOrderFieldBuilder() : null;
          } else {
            orderBuilder_.addAllMessages(other.order_);
          }
        }
      }
      if (distinctOnBuilder_ == null) {
        if (!other.distinctOn_.isEmpty()) {
          if (distinctOn_.isEmpty()) {
            distinctOn_ = other.distinctOn_;
            bitField0_ = (bitField0_ & ~0x00000010);
          } else {
            ensureDistinctOnIsMutable();
            distinctOn_.addAll(other.distinctOn_);
          }
          onChanged();
        }
      } else {
        if (!other.distinctOn_.isEmpty()) {
          if (distinctOnBuilder_.isEmpty()) {
            distinctOnBuilder_.dispose();
            distinctOnBuilder_ = null;
            distinctOn_ = other.distinctOn_;
            bitField0_ = (bitField0_ & ~0x00000010);
            distinctOnBuilder_ = 
              com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ?
                 getDistinctOnFieldBuilder() : null;
          } else {
            distinctOnBuilder_.addAllMessages(other.distinctOn_);
          }
        }
      }
      if (other.getStartCursor() != com.google.protobuf.ByteString.EMPTY) {
        setStartCursor(other.getStartCursor());
      }
      if (other.getEndCursor() != com.google.protobuf.ByteString.EMPTY) {
        setEndCursor(other.getEndCursor());
      }
      if (other.getOffset() != 0) {
        setOffset(other.getOffset());
      }
      if (other.hasLimit()) {
        mergeLimit(other.getLimit());
      }
      this.mergeUnknownFields(other.unknownFields);
      onChanged();
      return this;
    }

    public final boolean isInitialized() {
      return true;
    }

    public Builder mergeFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      com.google.datastore.v1.Query parsedMessage = null;
      try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        parsedMessage = (com.google.datastore.v1.Query) e.getUnfinishedMessage();
        throw e.unwrapIOException();
      } finally {
        if (parsedMessage != null) {
          mergeFrom(parsedMessage);
        }
      }
      return this;
    }
    private int bitField0_;

    private java.util.List<com.google.datastore.v1.Projection> projection_ =
      java.util.Collections.emptyList();
    private void ensureProjectionIsMutable() {
      if (!((bitField0_ & 0x00000001) == 0x00000001)) {
        projection_ = new java.util.ArrayList<com.google.datastore.v1.Projection>(projection_);
        bitField0_ |= 0x00000001;
       }
    }

    private com.google.protobuf.RepeatedFieldBuilderV3<
        com.google.datastore.v1.Projection, com.google.datastore.v1.Projection.Builder, com.google.datastore.v1.ProjectionOrBuilder> projectionBuilder_;

    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public java.util.List<com.google.datastore.v1.Projection> getProjectionList() {
      if (projectionBuilder_ == null) {
        return java.util.Collections.unmodifiableList(projection_);
      } else {
        return projectionBuilder_.getMessageList();
      }
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public int getProjectionCount() {
      if (projectionBuilder_ == null) {
        return projection_.size();
      } else {
        return projectionBuilder_.getCount();
      }
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public com.google.datastore.v1.Projection getProjection(int index) {
      if (projectionBuilder_ == null) {
        return projection_.get(index);
      } else {
        return projectionBuilder_.getMessage(index);
      }
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public Builder setProjection(
        int index, com.google.datastore.v1.Projection value) {
      if (projectionBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensureProjectionIsMutable();
        projection_.set(index, value);
        onChanged();
      } else {
        projectionBuilder_.setMessage(index, value);
      }
      return this;
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public Builder setProjection(
        int index, com.google.datastore.v1.Projection.Builder builderForValue) {
      if (projectionBuilder_ == null) {
        ensureProjectionIsMutable();
        projection_.set(index, builderForValue.build());
        onChanged();
      } else {
        projectionBuilder_.setMessage(index, builderForValue.build());
      }
      return this;
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public Builder addProjection(com.google.datastore.v1.Projection value) {
      if (projectionBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensureProjectionIsMutable();
        projection_.add(value);
        onChanged();
      } else {
        projectionBuilder_.addMessage(value);
      }
      return this;
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public Builder addProjection(
        int index, com.google.datastore.v1.Projection value) {
      if (projectionBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensureProjectionIsMutable();
        projection_.add(index, value);
        onChanged();
      } else {
        projectionBuilder_.addMessage(index, value);
      }
      return this;
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public Builder addProjection(
        com.google.datastore.v1.Projection.Builder builderForValue) {
      if (projectionBuilder_ == null) {
        ensureProjectionIsMutable();
        projection_.add(builderForValue.build());
        onChanged();
      } else {
        projectionBuilder_.addMessage(builderForValue.build());
      }
      return this;
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public Builder addProjection(
        int index, com.google.datastore.v1.Projection.Builder builderForValue) {
      if (projectionBuilder_ == null) {
        ensureProjectionIsMutable();
        projection_.add(index, builderForValue.build());
        onChanged();
      } else {
        projectionBuilder_.addMessage(index, builderForValue.build());
      }
      return this;
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public Builder addAllProjection(
        java.lang.Iterable<? extends com.google.datastore.v1.Projection> values) {
      if (projectionBuilder_ == null) {
        ensureProjectionIsMutable();
        com.google.protobuf.AbstractMessageLite.Builder.addAll(
            values, projection_);
        onChanged();
      } else {
        projectionBuilder_.addAllMessages(values);
      }
      return this;
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public Builder clearProjection() {
      if (projectionBuilder_ == null) {
        projection_ = java.util.Collections.emptyList();
        bitField0_ = (bitField0_ & ~0x00000001);
        onChanged();
      } else {
        projectionBuilder_.clear();
      }
      return this;
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public Builder removeProjection(int index) {
      if (projectionBuilder_ == null) {
        ensureProjectionIsMutable();
        projection_.remove(index);
        onChanged();
      } else {
        projectionBuilder_.remove(index);
      }
      return this;
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public com.google.datastore.v1.Projection.Builder getProjectionBuilder(
        int index) {
      return getProjectionFieldBuilder().getBuilder(index);
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public com.google.datastore.v1.ProjectionOrBuilder getProjectionOrBuilder(
        int index) {
      if (projectionBuilder_ == null) {
        return projection_.get(index);  } else {
        return projectionBuilder_.getMessageOrBuilder(index);
      }
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public java.util.List<? extends com.google.datastore.v1.ProjectionOrBuilder> 
         getProjectionOrBuilderList() {
      if (projectionBuilder_ != null) {
        return projectionBuilder_.getMessageOrBuilderList();
      } else {
        return java.util.Collections.unmodifiableList(projection_);
      }
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public com.google.datastore.v1.Projection.Builder addProjectionBuilder() {
      return getProjectionFieldBuilder().addBuilder(
          com.google.datastore.v1.Projection.getDefaultInstance());
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public com.google.datastore.v1.Projection.Builder addProjectionBuilder(
        int index) {
      return getProjectionFieldBuilder().addBuilder(
          index, com.google.datastore.v1.Projection.getDefaultInstance());
    }
    /**
     * <pre>
     * The projection to return. Defaults to returning all properties.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Projection projection = 2;</code>
     */
    public java.util.List<com.google.datastore.v1.Projection.Builder> 
         getProjectionBuilderList() {
      return getProjectionFieldBuilder().getBuilderList();
    }
    private com.google.protobuf.RepeatedFieldBuilderV3<
        com.google.datastore.v1.Projection, com.google.datastore.v1.Projection.Builder, com.google.datastore.v1.ProjectionOrBuilder> 
        getProjectionFieldBuilder() {
      if (projectionBuilder_ == null) {
        projectionBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
            com.google.datastore.v1.Projection, com.google.datastore.v1.Projection.Builder, com.google.datastore.v1.ProjectionOrBuilder>(
                projection_,
                ((bitField0_ & 0x00000001) == 0x00000001),
                getParentForChildren(),
                isClean());
        projection_ = null;
      }
      return projectionBuilder_;
    }

    private java.util.List<com.google.datastore.v1.KindExpression> kind_ =
      java.util.Collections.emptyList();
    private void ensureKindIsMutable() {
      if (!((bitField0_ & 0x00000002) == 0x00000002)) {
        kind_ = new java.util.ArrayList<com.google.datastore.v1.KindExpression>(kind_);
        bitField0_ |= 0x00000002;
       }
    }

    private com.google.protobuf.RepeatedFieldBuilderV3<
        com.google.datastore.v1.KindExpression, com.google.datastore.v1.KindExpression.Builder, com.google.datastore.v1.KindExpressionOrBuilder> kindBuilder_;

    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public java.util.List<com.google.datastore.v1.KindExpression> getKindList() {
      if (kindBuilder_ == null) {
        return java.util.Collections.unmodifiableList(kind_);
      } else {
        return kindBuilder_.getMessageList();
      }
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public int getKindCount() {
      if (kindBuilder_ == null) {
        return kind_.size();
      } else {
        return kindBuilder_.getCount();
      }
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public com.google.datastore.v1.KindExpression getKind(int index) {
      if (kindBuilder_ == null) {
        return kind_.get(index);
      } else {
        return kindBuilder_.getMessage(index);
      }
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public Builder setKind(
        int index, com.google.datastore.v1.KindExpression value) {
      if (kindBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensureKindIsMutable();
        kind_.set(index, value);
        onChanged();
      } else {
        kindBuilder_.setMessage(index, value);
      }
      return this;
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public Builder setKind(
        int index, com.google.datastore.v1.KindExpression.Builder builderForValue) {
      if (kindBuilder_ == null) {
        ensureKindIsMutable();
        kind_.set(index, builderForValue.build());
        onChanged();
      } else {
        kindBuilder_.setMessage(index, builderForValue.build());
      }
      return this;
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public Builder addKind(com.google.datastore.v1.KindExpression value) {
      if (kindBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensureKindIsMutable();
        kind_.add(value);
        onChanged();
      } else {
        kindBuilder_.addMessage(value);
      }
      return this;
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public Builder addKind(
        int index, com.google.datastore.v1.KindExpression value) {
      if (kindBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensureKindIsMutable();
        kind_.add(index, value);
        onChanged();
      } else {
        kindBuilder_.addMessage(index, value);
      }
      return this;
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public Builder addKind(
        com.google.datastore.v1.KindExpression.Builder builderForValue) {
      if (kindBuilder_ == null) {
        ensureKindIsMutable();
        kind_.add(builderForValue.build());
        onChanged();
      } else {
        kindBuilder_.addMessage(builderForValue.build());
      }
      return this;
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public Builder addKind(
        int index, com.google.datastore.v1.KindExpression.Builder builderForValue) {
      if (kindBuilder_ == null) {
        ensureKindIsMutable();
        kind_.add(index, builderForValue.build());
        onChanged();
      } else {
        kindBuilder_.addMessage(index, builderForValue.build());
      }
      return this;
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public Builder addAllKind(
        java.lang.Iterable<? extends com.google.datastore.v1.KindExpression> values) {
      if (kindBuilder_ == null) {
        ensureKindIsMutable();
        com.google.protobuf.AbstractMessageLite.Builder.addAll(
            values, kind_);
        onChanged();
      } else {
        kindBuilder_.addAllMessages(values);
      }
      return this;
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public Builder clearKind() {
      if (kindBuilder_ == null) {
        kind_ = java.util.Collections.emptyList();
        bitField0_ = (bitField0_ & ~0x00000002);
        onChanged();
      } else {
        kindBuilder_.clear();
      }
      return this;
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public Builder removeKind(int index) {
      if (kindBuilder_ == null) {
        ensureKindIsMutable();
        kind_.remove(index);
        onChanged();
      } else {
        kindBuilder_.remove(index);
      }
      return this;
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public com.google.datastore.v1.KindExpression.Builder getKindBuilder(
        int index) {
      return getKindFieldBuilder().getBuilder(index);
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public com.google.datastore.v1.KindExpressionOrBuilder getKindOrBuilder(
        int index) {
      if (kindBuilder_ == null) {
        return kind_.get(index);  } else {
        return kindBuilder_.getMessageOrBuilder(index);
      }
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public java.util.List<? extends com.google.datastore.v1.KindExpressionOrBuilder> 
         getKindOrBuilderList() {
      if (kindBuilder_ != null) {
        return kindBuilder_.getMessageOrBuilderList();
      } else {
        return java.util.Collections.unmodifiableList(kind_);
      }
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public com.google.datastore.v1.KindExpression.Builder addKindBuilder() {
      return getKindFieldBuilder().addBuilder(
          com.google.datastore.v1.KindExpression.getDefaultInstance());
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public com.google.datastore.v1.KindExpression.Builder addKindBuilder(
        int index) {
      return getKindFieldBuilder().addBuilder(
          index, com.google.datastore.v1.KindExpression.getDefaultInstance());
    }
    /**
     * <pre>
     * The kinds to query (if empty, returns entities of all kinds).
     * Currently at most 1 kind may be specified.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.KindExpression kind = 3;</code>
     */
    public java.util.List<com.google.datastore.v1.KindExpression.Builder> 
         getKindBuilderList() {
      return getKindFieldBuilder().getBuilderList();
    }
    private com.google.protobuf.RepeatedFieldBuilderV3<
        com.google.datastore.v1.KindExpression, com.google.datastore.v1.KindExpression.Builder, com.google.datastore.v1.KindExpressionOrBuilder> 
        getKindFieldBuilder() {
      if (kindBuilder_ == null) {
        kindBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
            com.google.datastore.v1.KindExpression, com.google.datastore.v1.KindExpression.Builder, com.google.datastore.v1.KindExpressionOrBuilder>(
                kind_,
                ((bitField0_ & 0x00000002) == 0x00000002),
                getParentForChildren(),
                isClean());
        kind_ = null;
      }
      return kindBuilder_;
    }

    private com.google.datastore.v1.Filter filter_ = null;
    private com.google.protobuf.SingleFieldBuilderV3<
        com.google.datastore.v1.Filter, com.google.datastore.v1.Filter.Builder, com.google.datastore.v1.FilterOrBuilder> filterBuilder_;
    /**
     * <pre>
     * The filter to apply.
     * </pre>
     *
     * <code>.google.datastore.v1.Filter filter = 4;</code>
     */
    public boolean hasFilter() {
      return filterBuilder_ != null || filter_ != null;
    }
    /**
     * <pre>
     * The filter to apply.
     * </pre>
     *
     * <code>.google.datastore.v1.Filter filter = 4;</code>
     */
    public com.google.datastore.v1.Filter getFilter() {
      if (filterBuilder_ == null) {
        return filter_ == null ? com.google.datastore.v1.Filter.getDefaultInstance() : filter_;
      } else {
        return filterBuilder_.getMessage();
      }
    }
    /**
     * <pre>
     * The filter to apply.
     * </pre>
     *
     * <code>.google.datastore.v1.Filter filter = 4;</code>
     */
    public Builder setFilter(com.google.datastore.v1.Filter value) {
      if (filterBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        filter_ = value;
        onChanged();
      } else {
        filterBuilder_.setMessage(value);
      }

      return this;
    }
    /**
     * <pre>
     * The filter to apply.
     * </pre>
     *
     * <code>.google.datastore.v1.Filter filter = 4;</code>
     */
    public Builder setFilter(
        com.google.datastore.v1.Filter.Builder builderForValue) {
      if (filterBuilder_ == null) {
        filter_ = builderForValue.build();
        onChanged();
      } else {
        filterBuilder_.setMessage(builderForValue.build());
      }

      return this;
    }
    /**
     * <pre>
     * The filter to apply.
     * </pre>
     *
     * <code>.google.datastore.v1.Filter filter = 4;</code>
     */
    public Builder mergeFilter(com.google.datastore.v1.Filter value) {
      if (filterBuilder_ == null) {
        if (filter_ != null) {
          filter_ =
            com.google.datastore.v1.Filter.newBuilder(filter_).mergeFrom(value).buildPartial();
        } else {
          filter_ = value;
        }
        onChanged();
      } else {
        filterBuilder_.mergeFrom(value);
      }

      return this;
    }
    /**
     * <pre>
     * The filter to apply.
     * </pre>
     *
     * <code>.google.datastore.v1.Filter filter = 4;</code>
     */
    public Builder clearFilter() {
      if (filterBuilder_ == null) {
        filter_ = null;
        onChanged();
      } else {
        filter_ = null;
        filterBuilder_ = null;
      }

      return this;
    }
    /**
     * <pre>
     * The filter to apply.
     * </pre>
     *
     * <code>.google.datastore.v1.Filter filter = 4;</code>
     */
    public com.google.datastore.v1.Filter.Builder getFilterBuilder() {
      
      onChanged();
      return getFilterFieldBuilder().getBuilder();
    }
    /**
     * <pre>
     * The filter to apply.
     * </pre>
     *
     * <code>.google.datastore.v1.Filter filter = 4;</code>
     */
    public com.google.datastore.v1.FilterOrBuilder getFilterOrBuilder() {
      if (filterBuilder_ != null) {
        return filterBuilder_.getMessageOrBuilder();
      } else {
        return filter_ == null ?
            com.google.datastore.v1.Filter.getDefaultInstance() : filter_;
      }
    }
    /**
     * <pre>
     * The filter to apply.
     * </pre>
     *
     * <code>.google.datastore.v1.Filter filter = 4;</code>
     */
    private com.google.protobuf.SingleFieldBuilderV3<
        com.google.datastore.v1.Filter, com.google.datastore.v1.Filter.Builder, com.google.datastore.v1.FilterOrBuilder> 
        getFilterFieldBuilder() {
      if (filterBuilder_ == null) {
        filterBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
            com.google.datastore.v1.Filter, com.google.datastore.v1.Filter.Builder, com.google.datastore.v1.FilterOrBuilder>(
                getFilter(),
                getParentForChildren(),
                isClean());
        filter_ = null;
      }
      return filterBuilder_;
    }

    private java.util.List<com.google.datastore.v1.PropertyOrder> order_ =
      java.util.Collections.emptyList();
    private void ensureOrderIsMutable() {
      if (!((bitField0_ & 0x00000008) == 0x00000008)) {
        order_ = new java.util.ArrayList<com.google.datastore.v1.PropertyOrder>(order_);
        bitField0_ |= 0x00000008;
       }
    }

    private com.google.protobuf.RepeatedFieldBuilderV3<
        com.google.datastore.v1.PropertyOrder, com.google.datastore.v1.PropertyOrder.Builder, com.google.datastore.v1.PropertyOrderOrBuilder> orderBuilder_;

    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public java.util.List<com.google.datastore.v1.PropertyOrder> getOrderList() {
      if (orderBuilder_ == null) {
        return java.util.Collections.unmodifiableList(order_);
      } else {
        return orderBuilder_.getMessageList();
      }
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public int getOrderCount() {
      if (orderBuilder_ == null) {
        return order_.size();
      } else {
        return orderBuilder_.getCount();
      }
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public com.google.datastore.v1.PropertyOrder getOrder(int index) {
      if (orderBuilder_ == null) {
        return order_.get(index);
      } else {
        return orderBuilder_.getMessage(index);
      }
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public Builder setOrder(
        int index, com.google.datastore.v1.PropertyOrder value) {
      if (orderBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensureOrderIsMutable();
        order_.set(index, value);
        onChanged();
      } else {
        orderBuilder_.setMessage(index, value);
      }
      return this;
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public Builder setOrder(
        int index, com.google.datastore.v1.PropertyOrder.Builder builderForValue) {
      if (orderBuilder_ == null) {
        ensureOrderIsMutable();
        order_.set(index, builderForValue.build());
        onChanged();
      } else {
        orderBuilder_.setMessage(index, builderForValue.build());
      }
      return this;
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public Builder addOrder(com.google.datastore.v1.PropertyOrder value) {
      if (orderBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensureOrderIsMutable();
        order_.add(value);
        onChanged();
      } else {
        orderBuilder_.addMessage(value);
      }
      return this;
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public Builder addOrder(
        int index, com.google.datastore.v1.PropertyOrder value) {
      if (orderBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensureOrderIsMutable();
        order_.add(index, value);
        onChanged();
      } else {
        orderBuilder_.addMessage(index, value);
      }
      return this;
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public Builder addOrder(
        com.google.datastore.v1.PropertyOrder.Builder builderForValue) {
      if (orderBuilder_ == null) {
        ensureOrderIsMutable();
        order_.add(builderForValue.build());
        onChanged();
      } else {
        orderBuilder_.addMessage(builderForValue.build());
      }
      return this;
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public Builder addOrder(
        int index, com.google.datastore.v1.PropertyOrder.Builder builderForValue) {
      if (orderBuilder_ == null) {
        ensureOrderIsMutable();
        order_.add(index, builderForValue.build());
        onChanged();
      } else {
        orderBuilder_.addMessage(index, builderForValue.build());
      }
      return this;
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public Builder addAllOrder(
        java.lang.Iterable<? extends com.google.datastore.v1.PropertyOrder> values) {
      if (orderBuilder_ == null) {
        ensureOrderIsMutable();
        com.google.protobuf.AbstractMessageLite.Builder.addAll(
            values, order_);
        onChanged();
      } else {
        orderBuilder_.addAllMessages(values);
      }
      return this;
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public Builder clearOrder() {
      if (orderBuilder_ == null) {
        order_ = java.util.Collections.emptyList();
        bitField0_ = (bitField0_ & ~0x00000008);
        onChanged();
      } else {
        orderBuilder_.clear();
      }
      return this;
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public Builder removeOrder(int index) {
      if (orderBuilder_ == null) {
        ensureOrderIsMutable();
        order_.remove(index);
        onChanged();
      } else {
        orderBuilder_.remove(index);
      }
      return this;
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public com.google.datastore.v1.PropertyOrder.Builder getOrderBuilder(
        int index) {
      return getOrderFieldBuilder().getBuilder(index);
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public com.google.datastore.v1.PropertyOrderOrBuilder getOrderOrBuilder(
        int index) {
      if (orderBuilder_ == null) {
        return order_.get(index);  } else {
        return orderBuilder_.getMessageOrBuilder(index);
      }
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public java.util.List<? extends com.google.datastore.v1.PropertyOrderOrBuilder> 
         getOrderOrBuilderList() {
      if (orderBuilder_ != null) {
        return orderBuilder_.getMessageOrBuilderList();
      } else {
        return java.util.Collections.unmodifiableList(order_);
      }
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public com.google.datastore.v1.PropertyOrder.Builder addOrderBuilder() {
      return getOrderFieldBuilder().addBuilder(
          com.google.datastore.v1.PropertyOrder.getDefaultInstance());
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public com.google.datastore.v1.PropertyOrder.Builder addOrderBuilder(
        int index) {
      return getOrderFieldBuilder().addBuilder(
          index, com.google.datastore.v1.PropertyOrder.getDefaultInstance());
    }
    /**
     * <pre>
     * The order to apply to the query results (if empty, order is unspecified).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyOrder order = 5;</code>
     */
    public java.util.List<com.google.datastore.v1.PropertyOrder.Builder> 
         getOrderBuilderList() {
      return getOrderFieldBuilder().getBuilderList();
    }
    private com.google.protobuf.RepeatedFieldBuilderV3<
        com.google.datastore.v1.PropertyOrder, com.google.datastore.v1.PropertyOrder.Builder, com.google.datastore.v1.PropertyOrderOrBuilder> 
        getOrderFieldBuilder() {
      if (orderBuilder_ == null) {
        orderBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
            com.google.datastore.v1.PropertyOrder, com.google.datastore.v1.PropertyOrder.Builder, com.google.datastore.v1.PropertyOrderOrBuilder>(
                order_,
                ((bitField0_ & 0x00000008) == 0x00000008),
                getParentForChildren(),
                isClean());
        order_ = null;
      }
      return orderBuilder_;
    }

    private java.util.List<com.google.datastore.v1.PropertyReference> distinctOn_ =
      java.util.Collections.emptyList();
    private void ensureDistinctOnIsMutable() {
      if (!((bitField0_ & 0x00000010) == 0x00000010)) {
        distinctOn_ = new java.util.ArrayList<com.google.datastore.v1.PropertyReference>(distinctOn_);
        bitField0_ |= 0x00000010;
       }
    }

    private com.google.protobuf.RepeatedFieldBuilderV3<
        com.google.datastore.v1.PropertyReference, com.google.datastore.v1.PropertyReference.Builder, com.google.datastore.v1.PropertyReferenceOrBuilder> distinctOnBuilder_;

    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public java.util.List<com.google.datastore.v1.PropertyReference> getDistinctOnList() {
      if (distinctOnBuilder_ == null) {
        return java.util.Collections.unmodifiableList(distinctOn_);
      } else {
        return distinctOnBuilder_.getMessageList();
      }
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public int getDistinctOnCount() {
      if (distinctOnBuilder_ == null) {
        return distinctOn_.size();
      } else {
        return distinctOnBuilder_.getCount();
      }
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public com.google.datastore.v1.PropertyReference getDistinctOn(int index) {
      if (distinctOnBuilder_ == null) {
        return distinctOn_.get(index);
      } else {
        return distinctOnBuilder_.getMessage(index);
      }
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public Builder setDistinctOn(
        int index, com.google.datastore.v1.PropertyReference value) {
      if (distinctOnBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensureDistinctOnIsMutable();
        distinctOn_.set(index, value);
        onChanged();
      } else {
        distinctOnBuilder_.setMessage(index, value);
      }
      return this;
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public Builder setDistinctOn(
        int index, com.google.datastore.v1.PropertyReference.Builder builderForValue) {
      if (distinctOnBuilder_ == null) {
        ensureDistinctOnIsMutable();
        distinctOn_.set(index, builderForValue.build());
        onChanged();
      } else {
        distinctOnBuilder_.setMessage(index, builderForValue.build());
      }
      return this;
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public Builder addDistinctOn(com.google.datastore.v1.PropertyReference value) {
      if (distinctOnBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensureDistinctOnIsMutable();
        distinctOn_.add(value);
        onChanged();
      } else {
        distinctOnBuilder_.addMessage(value);
      }
      return this;
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public Builder addDistinctOn(
        int index, com.google.datastore.v1.PropertyReference value) {
      if (distinctOnBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensureDistinctOnIsMutable();
        distinctOn_.add(index, value);
        onChanged();
      } else {
        distinctOnBuilder_.addMessage(index, value);
      }
      return this;
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public Builder addDistinctOn(
        com.google.datastore.v1.PropertyReference.Builder builderForValue) {
      if (distinctOnBuilder_ == null) {
        ensureDistinctOnIsMutable();
        distinctOn_.add(builderForValue.build());
        onChanged();
      } else {
        distinctOnBuilder_.addMessage(builderForValue.build());
      }
      return this;
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public Builder addDistinctOn(
        int index, com.google.datastore.v1.PropertyReference.Builder builderForValue) {
      if (distinctOnBuilder_ == null) {
        ensureDistinctOnIsMutable();
        distinctOn_.add(index, builderForValue.build());
        onChanged();
      } else {
        distinctOnBuilder_.addMessage(index, builderForValue.build());
      }
      return this;
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public Builder addAllDistinctOn(
        java.lang.Iterable<? extends com.google.datastore.v1.PropertyReference> values) {
      if (distinctOnBuilder_ == null) {
        ensureDistinctOnIsMutable();
        com.google.protobuf.AbstractMessageLite.Builder.addAll(
            values, distinctOn_);
        onChanged();
      } else {
        distinctOnBuilder_.addAllMessages(values);
      }
      return this;
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public Builder clearDistinctOn() {
      if (distinctOnBuilder_ == null) {
        distinctOn_ = java.util.Collections.emptyList();
        bitField0_ = (bitField0_ & ~0x00000010);
        onChanged();
      } else {
        distinctOnBuilder_.clear();
      }
      return this;
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public Builder removeDistinctOn(int index) {
      if (distinctOnBuilder_ == null) {
        ensureDistinctOnIsMutable();
        distinctOn_.remove(index);
        onChanged();
      } else {
        distinctOnBuilder_.remove(index);
      }
      return this;
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public com.google.datastore.v1.PropertyReference.Builder getDistinctOnBuilder(
        int index) {
      return getDistinctOnFieldBuilder().getBuilder(index);
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public com.google.datastore.v1.PropertyReferenceOrBuilder getDistinctOnOrBuilder(
        int index) {
      if (distinctOnBuilder_ == null) {
        return distinctOn_.get(index);  } else {
        return distinctOnBuilder_.getMessageOrBuilder(index);
      }
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public java.util.List<? extends com.google.datastore.v1.PropertyReferenceOrBuilder> 
         getDistinctOnOrBuilderList() {
      if (distinctOnBuilder_ != null) {
        return distinctOnBuilder_.getMessageOrBuilderList();
      } else {
        return java.util.Collections.unmodifiableList(distinctOn_);
      }
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public com.google.datastore.v1.PropertyReference.Builder addDistinctOnBuilder() {
      return getDistinctOnFieldBuilder().addBuilder(
          com.google.datastore.v1.PropertyReference.getDefaultInstance());
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public com.google.datastore.v1.PropertyReference.Builder addDistinctOnBuilder(
        int index) {
      return getDistinctOnFieldBuilder().addBuilder(
          index, com.google.datastore.v1.PropertyReference.getDefaultInstance());
    }
    /**
     * <pre>
     * The properties to make distinct. The query results will contain the first
     * result for each distinct combination of values for the given properties
     * (if empty, all results are returned).
     * </pre>
     *
     * <code>repeated .google.datastore.v1.PropertyReference distinct_on = 6;</code>
     */
    public java.util.List<com.google.datastore.v1.PropertyReference.Builder> 
         getDistinctOnBuilderList() {
      return getDistinctOnFieldBuilder().getBuilderList();
    }
    private com.google.protobuf.RepeatedFieldBuilderV3<
        com.google.datastore.v1.PropertyReference, com.google.datastore.v1.PropertyReference.Builder, com.google.datastore.v1.PropertyReferenceOrBuilder> 
        getDistinctOnFieldBuilder() {
      if (distinctOnBuilder_ == null) {
        distinctOnBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
            com.google.datastore.v1.PropertyReference, com.google.datastore.v1.PropertyReference.Builder, com.google.datastore.v1.PropertyReferenceOrBuilder>(
                distinctOn_,
                ((bitField0_ & 0x00000010) == 0x00000010),
                getParentForChildren(),
                isClean());
        distinctOn_ = null;
      }
      return distinctOnBuilder_;
    }

    private com.google.protobuf.ByteString startCursor_ = com.google.protobuf.ByteString.EMPTY;
    /**
     * <pre>
     * A starting point for the query results. Query cursors are
     * returned in query result batches and
     * [can only be used to continue the same query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
     * </pre>
     *
     * <code>bytes start_cursor = 7;</code>
     */
    public com.google.protobuf.ByteString getStartCursor() {
      return startCursor_;
    }
    /**
     * <pre>
     * A starting point for the query results. Query cursors are
     * returned in query result batches and
     * [can only be used to continue the same query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
     * </pre>
     *
     * <code>bytes start_cursor = 7;</code>
     */
    public Builder setStartCursor(com.google.protobuf.ByteString value) {
      if (value == null) {
    throw new NullPointerException();
  }
  
      startCursor_ = value;
      onChanged();
      return this;
    }
    /**
     * <pre>
     * A starting point for the query results. Query cursors are
     * returned in query result batches and
     * [can only be used to continue the same query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
     * </pre>
     *
     * <code>bytes start_cursor = 7;</code>
     */
    public Builder clearStartCursor() {
      
      startCursor_ = getDefaultInstance().getStartCursor();
      onChanged();
      return this;
    }

    private com.google.protobuf.ByteString endCursor_ = com.google.protobuf.ByteString.EMPTY;
    /**
     * <pre>
     * An ending point for the query results. Query cursors are
     * returned in query result batches and
     * [can only be used to limit the same query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
     * </pre>
     *
     * <code>bytes end_cursor = 8;</code>
     */
    public com.google.protobuf.ByteString getEndCursor() {
      return endCursor_;
    }
    /**
     * <pre>
     * An ending point for the query results. Query cursors are
     * returned in query result batches and
     * [can only be used to limit the same query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
     * </pre>
     *
     * <code>bytes end_cursor = 8;</code>
     */
    public Builder setEndCursor(com.google.protobuf.ByteString value) {
      if (value == null) {
    throw new NullPointerException();
  }
  
      endCursor_ = value;
      onChanged();
      return this;
    }
    /**
     * <pre>
     * An ending point for the query results. Query cursors are
     * returned in query result batches and
     * [can only be used to limit the same query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
     * </pre>
     *
     * <code>bytes end_cursor = 8;</code>
     */
    public Builder clearEndCursor() {
      
      endCursor_ = getDefaultInstance().getEndCursor();
      onChanged();
      return this;
    }

    private int offset_ ;
    /**
     * <pre>
     * The number of results to skip. Applies before limit, but after all other
     * constraints. Optional. Must be &gt;= 0 if specified.
     * </pre>
     *
     * <code>int32 offset = 10;</code>
     */
    public int getOffset() {
      return offset_;
    }
    /**
     * <pre>
     * The number of results to skip. Applies before limit, but after all other
     * constraints. Optional. Must be &gt;= 0 if specified.
     * </pre>
     *
     * <code>int32 offset = 10;</code>
     */
    public Builder setOffset(int value) {
      
      offset_ = value;
      onChanged();
      return this;
    }
    /**
     * <pre>
     * The number of results to skip. Applies before limit, but after all other
     * constraints. Optional. Must be &gt;= 0 if specified.
     * </pre>
     *
     * <code>int32 offset = 10;</code>
     */
    public Builder clearOffset() {
      
      offset_ = 0;
      onChanged();
      return this;
    }

    private com.google.protobuf.Int32Value limit_ = null;
    private com.google.protobuf.SingleFieldBuilderV3<
        com.google.protobuf.Int32Value, com.google.protobuf.Int32Value.Builder, com.google.protobuf.Int32ValueOrBuilder> limitBuilder_;
    /**
     * <pre>
     * The maximum number of results to return. Applies after all other
     * constraints. Optional.
     * Unspecified is interpreted as no limit.
     * Must be &gt;= 0 if specified.
     * </pre>
     *
     * <code>.google.protobuf.Int32Value limit = 12;</code>
     */
    public boolean hasLimit() {
      return limitBuilder_ != null || limit_ != null;
    }
    /**
     * <pre>
     * The maximum number of results to return. Applies after all other
     * constraints. Optional.
     * Unspecified is interpreted as no limit.
     * Must be &gt;= 0 if specified.
     * </pre>
     *
     * <code>.google.protobuf.Int32Value limit = 12;</code>
     */
    public com.google.protobuf.Int32Value getLimit() {
      if (limitBuilder_ == null) {
        return limit_ == null ? com.google.protobuf.Int32Value.getDefaultInstance() : limit_;
      } else {
        return limitBuilder_.getMessage();
      }
    }
    /**
     * <pre>
     * The maximum number of results to return. Applies after all other
     * constraints. Optional.
     * Unspecified is interpreted as no limit.
     * Must be &gt;= 0 if specified.
     * </pre>
     *
     * <code>.google.protobuf.Int32Value limit = 12;</code>
     */
    public Builder setLimit(com.google.protobuf.Int32Value value) {
      if (limitBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        limit_ = value;
        onChanged();
      } else {
        limitBuilder_.setMessage(value);
      }

      return this;
    }
    /**
     * <pre>
     * The maximum number of results to return. Applies after all other
     * constraints. Optional.
     * Unspecified is interpreted as no limit.
     * Must be &gt;= 0 if specified.
     * </pre>
     *
     * <code>.google.protobuf.Int32Value limit = 12;</code>
     */
    public Builder setLimit(
        com.google.protobuf.Int32Value.Builder builderForValue) {
      if (limitBuilder_ == null) {
        limit_ = builderForValue.build();
        onChanged();
      } else {
        limitBuilder_.setMessage(builderForValue.build());
      }

      return this;
    }
    /**
     * <pre>
     * The maximum number of results to return. Applies after all other
     * constraints. Optional.
     * Unspecified is interpreted as no limit.
     * Must be &gt;= 0 if specified.
     * </pre>
     *
     * <code>.google.protobuf.Int32Value limit = 12;</code>
     */
    public Builder mergeLimit(com.google.protobuf.Int32Value value) {
      if (limitBuilder_ == null) {
        if (limit_ != null) {
          limit_ =
            com.google.protobuf.Int32Value.newBuilder(limit_).mergeFrom(value).buildPartial();
        } else {
          limit_ = value;
        }
        onChanged();
      } else {
        limitBuilder_.mergeFrom(value);
      }

      return this;
    }
    /**
     * <pre>
     * The maximum number of results to return. Applies after all other
     * constraints. Optional.
     * Unspecified is interpreted as no limit.
     * Must be &gt;= 0 if specified.
     * </pre>
     *
     * <code>.google.protobuf.Int32Value limit = 12;</code>
     */
    public Builder clearLimit() {
      if (limitBuilder_ == null) {
        limit_ = null;
        onChanged();
      } else {
        limit_ = null;
        limitBuilder_ = null;
      }

      return this;
    }
    /**
     * <pre>
     * The maximum number of results to return. Applies after all other
     * constraints. Optional.
     * Unspecified is interpreted as no limit.
     * Must be &gt;= 0 if specified.
     * </pre>
     *
     * <code>.google.protobuf.Int32Value limit = 12;</code>
     */
    public com.google.protobuf.Int32Value.Builder getLimitBuilder() {
      
      onChanged();
      return getLimitFieldBuilder().getBuilder();
    }
    /**
     * <pre>
     * The maximum number of results to return. Applies after all other
     * constraints. Optional.
     * Unspecified is interpreted as no limit.
     * Must be &gt;= 0 if specified.
     * </pre>
     *
     * <code>.google.protobuf.Int32Value limit = 12;</code>
     */
    public com.google.protobuf.Int32ValueOrBuilder getLimitOrBuilder() {
      if (limitBuilder_ != null) {
        return limitBuilder_.getMessageOrBuilder();
      } else {
        return limit_ == null ?
            com.google.protobuf.Int32Value.getDefaultInstance() : limit_;
      }
    }
    /**
     * <pre>
     * The maximum number of results to return. Applies after all other
     * constraints. Optional.
     * Unspecified is interpreted as no limit.
     * Must be &gt;= 0 if specified.
     * </pre>
     *
     * <code>.google.protobuf.Int32Value limit = 12;</code>
     */
    private com.google.protobuf.SingleFieldBuilderV3<
        com.google.protobuf.Int32Value, com.google.protobuf.Int32Value.Builder, com.google.protobuf.Int32ValueOrBuilder> 
        getLimitFieldBuilder() {
      if (limitBuilder_ == null) {
        limitBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
            com.google.protobuf.Int32Value, com.google.protobuf.Int32Value.Builder, com.google.protobuf.Int32ValueOrBuilder>(
                getLimit(),
                getParentForChildren(),
                isClean());
        limit_ = null;
      }
      return limitBuilder_;
    }
    public final Builder setUnknownFields(
        final com.google.protobuf.UnknownFieldSet unknownFields) {
      return super.setUnknownFieldsProto3(unknownFields);
    }

    public final Builder mergeUnknownFields(
        final com.google.protobuf.UnknownFieldSet unknownFields) {
      return super.mergeUnknownFields(unknownFields);
    }


    // @@protoc_insertion_point(builder_scope:google.datastore.v1.Query)
  }

  // @@protoc_insertion_point(class_scope:google.datastore.v1.Query)
  private static final com.google.datastore.v1.Query DEFAULT_INSTANCE;
  static {
    DEFAULT_INSTANCE = new com.google.datastore.v1.Query();
  }

  public static com.google.datastore.v1.Query getDefaultInstance() {
    return DEFAULT_INSTANCE;
  }

  private static final com.google.protobuf.Parser<Query>
      PARSER = new com.google.protobuf.AbstractParser<Query>() {
    public Query parsePartialFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return new Query(input, extensionRegistry);
    }
  };

  public static com.google.protobuf.Parser<Query> parser() {
    return PARSER;
  }

  @java.lang.Override
  public com.google.protobuf.Parser<Query> getParserForType() {
    return PARSER;
  }

  public com.google.datastore.v1.Query getDefaultInstanceForType() {
    return DEFAULT_INSTANCE;
  }

}

