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

package com.google.datastore.v1;

/**
 * <pre>
 * A unique identifier for an entity.
 * If a key's partition ID or any of its path kinds or names are
 * reserved/read-only, the key is reserved/read-only.
 * A reserved/read-only key is forbidden in certain documented contexts.
 * </pre>
 *
 * Protobuf type {@code google.datastore.v1.Key}
 */
public  final class Key extends
    com.google.protobuf.GeneratedMessageV3 implements
    // @@protoc_insertion_point(message_implements:google.datastore.v1.Key)
    KeyOrBuilder {
private static final long serialVersionUID = 0L;
  // Use Key.newBuilder() to construct.
  private Key(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
    super(builder);
  }
  private Key() {
    path_ = java.util.Collections.emptyList();
  }

  @java.lang.Override
  public final com.google.protobuf.UnknownFieldSet
  getUnknownFields() {
    return this.unknownFields;
  }
  private Key(
      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 10: {
            com.google.datastore.v1.PartitionId.Builder subBuilder = null;
            if (partitionId_ != null) {
              subBuilder = partitionId_.toBuilder();
            }
            partitionId_ = input.readMessage(com.google.datastore.v1.PartitionId.parser(), extensionRegistry);
            if (subBuilder != null) {
              subBuilder.mergeFrom(partitionId_);
              partitionId_ = subBuilder.buildPartial();
            }

            break;
          }
          case 18: {
            if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) {
              path_ = new java.util.ArrayList<com.google.datastore.v1.Key.PathElement>();
              mutable_bitField0_ |= 0x00000002;
            }
            path_.add(
                input.readMessage(com.google.datastore.v1.Key.PathElement.parser(), extensionRegistry));
            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_ & 0x00000002) == 0x00000002)) {
        path_ = java.util.Collections.unmodifiableList(path_);
      }
      this.unknownFields = unknownFields.build();
      makeExtensionsImmutable();
    }
  }
  public static final com.google.protobuf.Descriptors.Descriptor
      getDescriptor() {
    return com.google.datastore.v1.EntityProto.internal_static_google_datastore_v1_Key_descriptor;
  }

  protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
      internalGetFieldAccessorTable() {
    return com.google.datastore.v1.EntityProto.internal_static_google_datastore_v1_Key_fieldAccessorTable
        .ensureFieldAccessorsInitialized(
            com.google.datastore.v1.Key.class, com.google.datastore.v1.Key.Builder.class);
  }

  public interface PathElementOrBuilder extends
      // @@protoc_insertion_point(interface_extends:google.datastore.v1.Key.PathElement)
      com.google.protobuf.MessageOrBuilder {

    /**
     * <pre>
     * The kind of the entity.
     * A kind matching regex `__.*__` is reserved/read-only.
     * A kind must not contain more than 1500 bytes when UTF-8 encoded.
     * Cannot be `""`.
     * </pre>
     *
     * <code>string kind = 1;</code>
     */
    java.lang.String getKind();
    /**
     * <pre>
     * The kind of the entity.
     * A kind matching regex `__.*__` is reserved/read-only.
     * A kind must not contain more than 1500 bytes when UTF-8 encoded.
     * Cannot be `""`.
     * </pre>
     *
     * <code>string kind = 1;</code>
     */
    com.google.protobuf.ByteString
        getKindBytes();

    /**
     * <pre>
     * The auto-allocated ID of the entity.
     * Never equal to zero. Values less than zero are discouraged and may not
     * be supported in the future.
     * </pre>
     *
     * <code>int64 id = 2;</code>
     */
    long getId();

    /**
     * <pre>
     * The name of the entity.
     * A name matching regex `__.*__` is reserved/read-only.
     * A name must not be more than 1500 bytes when UTF-8 encoded.
     * Cannot be `""`.
     * </pre>
     *
     * <code>string name = 3;</code>
     */
    java.lang.String getName();
    /**
     * <pre>
     * The name of the entity.
     * A name matching regex `__.*__` is reserved/read-only.
     * A name must not be more than 1500 bytes when UTF-8 encoded.
     * Cannot be `""`.
     * </pre>
     *
     * <code>string name = 3;</code>
     */
    com.google.protobuf.ByteString
        getNameBytes();

    public com.google.datastore.v1.Key.PathElement.IdTypeCase getIdTypeCase();
  }
  /**
   * <pre>
   * A (kind, ID/name) pair used to construct a key path.
   * If either name or ID is set, the element is complete.
   * If neither is set, the element is incomplete.
   * </pre>
   *
   * Protobuf type {@code google.datastore.v1.Key.PathElement}
   */
  public  static final class PathElement extends
      com.google.protobuf.GeneratedMessageV3 implements
      // @@protoc_insertion_point(message_implements:google.datastore.v1.Key.PathElement)
      PathElementOrBuilder {
  private static final long serialVersionUID = 0L;
    // Use PathElement.newBuilder() to construct.
    private PathElement(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
      super(builder);
    }
    private PathElement() {
      kind_ = "";
    }

    @java.lang.Override
    public final com.google.protobuf.UnknownFieldSet
    getUnknownFields() {
      return this.unknownFields;
    }
    private PathElement(
        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 10: {
              java.lang.String s = input.readStringRequireUtf8();

              kind_ = s;
              break;
            }
            case 16: {
              idTypeCase_ = 2;
              idType_ = input.readInt64();
              break;
            }
            case 26: {
              java.lang.String s = input.readStringRequireUtf8();
              idTypeCase_ = 3;
              idType_ = s;
              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 {
        this.unknownFields = unknownFields.build();
        makeExtensionsImmutable();
      }
    }
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return com.google.datastore.v1.EntityProto.internal_static_google_datastore_v1_Key_PathElement_descriptor;
    }

    protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return com.google.datastore.v1.EntityProto.internal_static_google_datastore_v1_Key_PathElement_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.google.datastore.v1.Key.PathElement.class, com.google.datastore.v1.Key.PathElement.Builder.class);
    }

    private int idTypeCase_ = 0;
    private java.lang.Object idType_;
    public enum IdTypeCase
        implements com.google.protobuf.Internal.EnumLite {
      ID(2),
      NAME(3),
      IDTYPE_NOT_SET(0);
      private final int value;
      private IdTypeCase(int value) {
        this.value = value;
      }
      /**
       * @deprecated Use {@link #forNumber(int)} instead.
       */
      @java.lang.Deprecated
      public static IdTypeCase valueOf(int value) {
        return forNumber(value);
      }

      public static IdTypeCase forNumber(int value) {
        switch (value) {
          case 2: return ID;
          case 3: return NAME;
          case 0: return IDTYPE_NOT_SET;
          default: return null;
        }
      }
      public int getNumber() {
        return this.value;
      }
    };

    public IdTypeCase
    getIdTypeCase() {
      return IdTypeCase.forNumber(
          idTypeCase_);
    }

    public static final int KIND_FIELD_NUMBER = 1;
    private volatile java.lang.Object kind_;
    /**
     * <pre>
     * The kind of the entity.
     * A kind matching regex `__.*__` is reserved/read-only.
     * A kind must not contain more than 1500 bytes when UTF-8 encoded.
     * Cannot be `""`.
     * </pre>
     *
     * <code>string kind = 1;</code>
     */
    public java.lang.String getKind() {
      java.lang.Object ref = kind_;
      if (ref instanceof java.lang.String) {
        return (java.lang.String) ref;
      } else {
        com.google.protobuf.ByteString bs = 
            (com.google.protobuf.ByteString) ref;
        java.lang.String s = bs.toStringUtf8();
        kind_ = s;
        return s;
      }
    }
    /**
     * <pre>
     * The kind of the entity.
     * A kind matching regex `__.*__` is reserved/read-only.
     * A kind must not contain more than 1500 bytes when UTF-8 encoded.
     * Cannot be `""`.
     * </pre>
     *
     * <code>string kind = 1;</code>
     */
    public com.google.protobuf.ByteString
        getKindBytes() {
      java.lang.Object ref = kind_;
      if (ref instanceof java.lang.String) {
        com.google.protobuf.ByteString b = 
            com.google.protobuf.ByteString.copyFromUtf8(
                (java.lang.String) ref);
        kind_ = b;
        return b;
      } else {
        return (com.google.protobuf.ByteString) ref;
      }
    }

    public static final int ID_FIELD_NUMBER = 2;
    /**
     * <pre>
     * The auto-allocated ID of the entity.
     * Never equal to zero. Values less than zero are discouraged and may not
     * be supported in the future.
     * </pre>
     *
     * <code>int64 id = 2;</code>
     */
    public long getId() {
      if (idTypeCase_ == 2) {
        return (java.lang.Long) idType_;
      }
      return 0L;
    }

    public static final int NAME_FIELD_NUMBER = 3;
    /**
     * <pre>
     * The name of the entity.
     * A name matching regex `__.*__` is reserved/read-only.
     * A name must not be more than 1500 bytes when UTF-8 encoded.
     * Cannot be `""`.
     * </pre>
     *
     * <code>string name = 3;</code>
     */
    public java.lang.String getName() {
      java.lang.Object ref = "";
      if (idTypeCase_ == 3) {
        ref = idType_;
      }
      if (ref instanceof java.lang.String) {
        return (java.lang.String) ref;
      } else {
        com.google.protobuf.ByteString bs = 
            (com.google.protobuf.ByteString) ref;
        java.lang.String s = bs.toStringUtf8();
        if (idTypeCase_ == 3) {
          idType_ = s;
        }
        return s;
      }
    }
    /**
     * <pre>
     * The name of the entity.
     * A name matching regex `__.*__` is reserved/read-only.
     * A name must not be more than 1500 bytes when UTF-8 encoded.
     * Cannot be `""`.
     * </pre>
     *
     * <code>string name = 3;</code>
     */
    public com.google.protobuf.ByteString
        getNameBytes() {
      java.lang.Object ref = "";
      if (idTypeCase_ == 3) {
        ref = idType_;
      }
      if (ref instanceof java.lang.String) {
        com.google.protobuf.ByteString b = 
            com.google.protobuf.ByteString.copyFromUtf8(
                (java.lang.String) ref);
        if (idTypeCase_ == 3) {
          idType_ = b;
        }
        return b;
      } else {
        return (com.google.protobuf.ByteString) ref;
      }
    }

    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 {
      if (!getKindBytes().isEmpty()) {
        com.google.protobuf.GeneratedMessageV3.writeString(output, 1, kind_);
      }
      if (idTypeCase_ == 2) {
        output.writeInt64(
            2, (long)((java.lang.Long) idType_));
      }
      if (idTypeCase_ == 3) {
        com.google.protobuf.GeneratedMessageV3.writeString(output, 3, idType_);
      }
      unknownFields.writeTo(output);
    }

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

      size = 0;
      if (!getKindBytes().isEmpty()) {
        size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, kind_);
      }
      if (idTypeCase_ == 2) {
        size += com.google.protobuf.CodedOutputStream
          .computeInt64Size(
              2, (long)((java.lang.Long) idType_));
      }
      if (idTypeCase_ == 3) {
        size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, idType_);
      }
      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.Key.PathElement)) {
        return super.equals(obj);
      }
      com.google.datastore.v1.Key.PathElement other = (com.google.datastore.v1.Key.PathElement) obj;

      boolean result = true;
      result = result && getKind()
          .equals(other.getKind());
      result = result && getIdTypeCase().equals(
          other.getIdTypeCase());
      if (!result) return false;
      switch (idTypeCase_) {
        case 2:
          result = result && (getId()
              == other.getId());
          break;
        case 3:
          result = result && getName()
              .equals(other.getName());
          break;
        case 0:
        default:
      }
      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();
      hash = (37 * hash) + KIND_FIELD_NUMBER;
      hash = (53 * hash) + getKind().hashCode();
      switch (idTypeCase_) {
        case 2:
          hash = (37 * hash) + ID_FIELD_NUMBER;
          hash = (53 * hash) + com.google.protobuf.Internal.hashLong(
              getId());
          break;
        case 3:
          hash = (37 * hash) + NAME_FIELD_NUMBER;
          hash = (53 * hash) + getName().hashCode();
          break;
        case 0:
        default:
      }
      hash = (29 * hash) + unknownFields.hashCode();
      memoizedHashCode = hash;
      return hash;
    }

    public static com.google.datastore.v1.Key.PathElement parseFrom(
        java.nio.ByteBuffer data)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return PARSER.parseFrom(data);
    }
    public static com.google.datastore.v1.Key.PathElement 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.Key.PathElement parseFrom(
        com.google.protobuf.ByteString data)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return PARSER.parseFrom(data);
    }
    public static com.google.datastore.v1.Key.PathElement 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.Key.PathElement parseFrom(byte[] data)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return PARSER.parseFrom(data);
    }
    public static com.google.datastore.v1.Key.PathElement parseFrom(
        byte[] data,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws com.google.protobuf.InvalidProtocolBufferException {
      return PARSER.parseFrom(data, extensionRegistry);
    }
    public static com.google.datastore.v1.Key.PathElement parseFrom(java.io.InputStream input)
        throws java.io.IOException {
      return com.google.protobuf.GeneratedMessageV3
          .parseWithIOException(PARSER, input);
    }
    public static com.google.datastore.v1.Key.PathElement 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.Key.PathElement parseDelimitedFrom(java.io.InputStream input)
        throws java.io.IOException {
      return com.google.protobuf.GeneratedMessageV3
          .parseDelimitedWithIOException(PARSER, input);
    }
    public static com.google.datastore.v1.Key.PathElement 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.Key.PathElement parseFrom(
        com.google.protobuf.CodedInputStream input)
        throws java.io.IOException {
      return com.google.protobuf.GeneratedMessageV3
          .parseWithIOException(PARSER, input);
    }
    public static com.google.datastore.v1.Key.PathElement 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.Key.PathElement 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 (kind, ID/name) pair used to construct a key path.
     * If either name or ID is set, the element is complete.
     * If neither is set, the element is incomplete.
     * </pre>
     *
     * Protobuf type {@code google.datastore.v1.Key.PathElement}
     */
    public static final class Builder extends
        com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
        // @@protoc_insertion_point(builder_implements:google.datastore.v1.Key.PathElement)
        com.google.datastore.v1.Key.PathElementOrBuilder {
      public static final com.google.protobuf.Descriptors.Descriptor
          getDescriptor() {
        return com.google.datastore.v1.EntityProto.internal_static_google_datastore_v1_Key_PathElement_descriptor;
      }

      protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
          internalGetFieldAccessorTable() {
        return com.google.datastore.v1.EntityProto.internal_static_google_datastore_v1_Key_PathElement_fieldAccessorTable
            .ensureFieldAccessorsInitialized(
                com.google.datastore.v1.Key.PathElement.class, com.google.datastore.v1.Key.PathElement.Builder.class);
      }

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

      private Builder(
          com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
        super(parent);
        maybeForceBuilderInitialization();
      }
      private void maybeForceBuilderInitialization() {
        if (com.google.protobuf.GeneratedMessageV3
                .alwaysUseFieldBuilders) {
        }
      }
      public Builder clear() {
        super.clear();
        kind_ = "";

        idTypeCase_ = 0;
        idType_ = null;
        return this;
      }

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

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

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

      public com.google.datastore.v1.Key.PathElement buildPartial() {
        com.google.datastore.v1.Key.PathElement result = new com.google.datastore.v1.Key.PathElement(this);
        result.kind_ = kind_;
        if (idTypeCase_ == 2) {
          result.idType_ = idType_;
        }
        if (idTypeCase_ == 3) {
          result.idType_ = idType_;
        }
        result.idTypeCase_ = idTypeCase_;
        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.Key.PathElement) {
          return mergeFrom((com.google.datastore.v1.Key.PathElement)other);
        } else {
          super.mergeFrom(other);
          return this;
        }
      }

      public Builder mergeFrom(com.google.datastore.v1.Key.PathElement other) {
        if (other == com.google.datastore.v1.Key.PathElement.getDefaultInstance()) return this;
        if (!other.getKind().isEmpty()) {
          kind_ = other.kind_;
          onChanged();
        }
        switch (other.getIdTypeCase()) {
          case ID: {
            setId(other.getId());
            break;
          }
          case NAME: {
            idTypeCase_ = 3;
            idType_ = other.idType_;
            onChanged();
            break;
          }
          case IDTYPE_NOT_SET: {
            break;
          }
        }
        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.Key.PathElement parsedMessage = null;
        try {
          parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
        } catch (com.google.protobuf.InvalidProtocolBufferException e) {
          parsedMessage = (com.google.datastore.v1.Key.PathElement) e.getUnfinishedMessage();
          throw e.unwrapIOException();
        } finally {
          if (parsedMessage != null) {
            mergeFrom(parsedMessage);
          }
        }
        return this;
      }
      private int idTypeCase_ = 0;
      private java.lang.Object idType_;
      public IdTypeCase
          getIdTypeCase() {
        return IdTypeCase.forNumber(
            idTypeCase_);
      }

      public Builder clearIdType() {
        idTypeCase_ = 0;
        idType_ = null;
        onChanged();
        return this;
      }


      private java.lang.Object kind_ = "";
      /**
       * <pre>
       * The kind of the entity.
       * A kind matching regex `__.*__` is reserved/read-only.
       * A kind must not contain more than 1500 bytes when UTF-8 encoded.
       * Cannot be `""`.
       * </pre>
       *
       * <code>string kind = 1;</code>
       */
      public java.lang.String getKind() {
        java.lang.Object ref = kind_;
        if (!(ref instanceof java.lang.String)) {
          com.google.protobuf.ByteString bs =
              (com.google.protobuf.ByteString) ref;
          java.lang.String s = bs.toStringUtf8();
          kind_ = s;
          return s;
        } else {
          return (java.lang.String) ref;
        }
      }
      /**
       * <pre>
       * The kind of the entity.
       * A kind matching regex `__.*__` is reserved/read-only.
       * A kind must not contain more than 1500 bytes when UTF-8 encoded.
       * Cannot be `""`.
       * </pre>
       *
       * <code>string kind = 1;</code>
       */
      public com.google.protobuf.ByteString
          getKindBytes() {
        java.lang.Object ref = kind_;
        if (ref instanceof String) {
          com.google.protobuf.ByteString b = 
              com.google.protobuf.ByteString.copyFromUtf8(
                  (java.lang.String) ref);
          kind_ = b;
          return b;
        } else {
          return (com.google.protobuf.ByteString) ref;
        }
      }
      /**
       * <pre>
       * The kind of the entity.
       * A kind matching regex `__.*__` is reserved/read-only.
       * A kind must not contain more than 1500 bytes when UTF-8 encoded.
       * Cannot be `""`.
       * </pre>
       *
       * <code>string kind = 1;</code>
       */
      public Builder setKind(
          java.lang.String value) {
        if (value == null) {
    throw new NullPointerException();
  }
  
        kind_ = value;
        onChanged();
        return this;
      }
      /**
       * <pre>
       * The kind of the entity.
       * A kind matching regex `__.*__` is reserved/read-only.
       * A kind must not contain more than 1500 bytes when UTF-8 encoded.
       * Cannot be `""`.
       * </pre>
       *
       * <code>string kind = 1;</code>
       */
      public Builder clearKind() {
        
        kind_ = getDefaultInstance().getKind();
        onChanged();
        return this;
      }
      /**
       * <pre>
       * The kind of the entity.
       * A kind matching regex `__.*__` is reserved/read-only.
       * A kind must not contain more than 1500 bytes when UTF-8 encoded.
       * Cannot be `""`.
       * </pre>
       *
       * <code>string kind = 1;</code>
       */
      public Builder setKindBytes(
          com.google.protobuf.ByteString value) {
        if (value == null) {
    throw new NullPointerException();
  }
  checkByteStringIsUtf8(value);
        
        kind_ = value;
        onChanged();
        return this;
      }

      /**
       * <pre>
       * The auto-allocated ID of the entity.
       * Never equal to zero. Values less than zero are discouraged and may not
       * be supported in the future.
       * </pre>
       *
       * <code>int64 id = 2;</code>
       */
      public long getId() {
        if (idTypeCase_ == 2) {
          return (java.lang.Long) idType_;
        }
        return 0L;
      }
      /**
       * <pre>
       * The auto-allocated ID of the entity.
       * Never equal to zero. Values less than zero are discouraged and may not
       * be supported in the future.
       * </pre>
       *
       * <code>int64 id = 2;</code>
       */
      public Builder setId(long value) {
        idTypeCase_ = 2;
        idType_ = value;
        onChanged();
        return this;
      }
      /**
       * <pre>
       * The auto-allocated ID of the entity.
       * Never equal to zero. Values less than zero are discouraged and may not
       * be supported in the future.
       * </pre>
       *
       * <code>int64 id = 2;</code>
       */
      public Builder clearId() {
        if (idTypeCase_ == 2) {
          idTypeCase_ = 0;
          idType_ = null;
          onChanged();
        }
        return this;
      }

      /**
       * <pre>
       * The name of the entity.
       * A name matching regex `__.*__` is reserved/read-only.
       * A name must not be more than 1500 bytes when UTF-8 encoded.
       * Cannot be `""`.
       * </pre>
       *
       * <code>string name = 3;</code>
       */
      public java.lang.String getName() {
        java.lang.Object ref = "";
        if (idTypeCase_ == 3) {
          ref = idType_;
        }
        if (!(ref instanceof java.lang.String)) {
          com.google.protobuf.ByteString bs =
              (com.google.protobuf.ByteString) ref;
          java.lang.String s = bs.toStringUtf8();
          if (idTypeCase_ == 3) {
            idType_ = s;
          }
          return s;
        } else {
          return (java.lang.String) ref;
        }
      }
      /**
       * <pre>
       * The name of the entity.
       * A name matching regex `__.*__` is reserved/read-only.
       * A name must not be more than 1500 bytes when UTF-8 encoded.
       * Cannot be `""`.
       * </pre>
       *
       * <code>string name = 3;</code>
       */
      public com.google.protobuf.ByteString
          getNameBytes() {
        java.lang.Object ref = "";
        if (idTypeCase_ == 3) {
          ref = idType_;
        }
        if (ref instanceof String) {
          com.google.protobuf.ByteString b = 
              com.google.protobuf.ByteString.copyFromUtf8(
                  (java.lang.String) ref);
          if (idTypeCase_ == 3) {
            idType_ = b;
          }
          return b;
        } else {
          return (com.google.protobuf.ByteString) ref;
        }
      }
      /**
       * <pre>
       * The name of the entity.
       * A name matching regex `__.*__` is reserved/read-only.
       * A name must not be more than 1500 bytes when UTF-8 encoded.
       * Cannot be `""`.
       * </pre>
       *
       * <code>string name = 3;</code>
       */
      public Builder setName(
          java.lang.String value) {
        if (value == null) {
    throw new NullPointerException();
  }
  idTypeCase_ = 3;
        idType_ = value;
        onChanged();
        return this;
      }
      /**
       * <pre>
       * The name of the entity.
       * A name matching regex `__.*__` is reserved/read-only.
       * A name must not be more than 1500 bytes when UTF-8 encoded.
       * Cannot be `""`.
       * </pre>
       *
       * <code>string name = 3;</code>
       */
      public Builder clearName() {
        if (idTypeCase_ == 3) {
          idTypeCase_ = 0;
          idType_ = null;
          onChanged();
        }
        return this;
      }
      /**
       * <pre>
       * The name of the entity.
       * A name matching regex `__.*__` is reserved/read-only.
       * A name must not be more than 1500 bytes when UTF-8 encoded.
       * Cannot be `""`.
       * </pre>
       *
       * <code>string name = 3;</code>
       */
      public Builder setNameBytes(
          com.google.protobuf.ByteString value) {
        if (value == null) {
    throw new NullPointerException();
  }
  checkByteStringIsUtf8(value);
        idTypeCase_ = 3;
        idType_ = value;
        onChanged();
        return this;
      }
      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.Key.PathElement)
    }

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

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

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

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

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

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

  }

  private int bitField0_;
  public static final int PARTITION_ID_FIELD_NUMBER = 1;
  private com.google.datastore.v1.PartitionId partitionId_;
  /**
   * <pre>
   * Entities are partitioned into subsets, currently identified by a project
   * ID and namespace ID.
   * Queries are scoped to a single partition.
   * </pre>
   *
   * <code>.google.datastore.v1.PartitionId partition_id = 1;</code>
   */
  public boolean hasPartitionId() {
    return partitionId_ != null;
  }
  /**
   * <pre>
   * Entities are partitioned into subsets, currently identified by a project
   * ID and namespace ID.
   * Queries are scoped to a single partition.
   * </pre>
   *
   * <code>.google.datastore.v1.PartitionId partition_id = 1;</code>
   */
  public com.google.datastore.v1.PartitionId getPartitionId() {
    return partitionId_ == null ? com.google.datastore.v1.PartitionId.getDefaultInstance() : partitionId_;
  }
  /**
   * <pre>
   * Entities are partitioned into subsets, currently identified by a project
   * ID and namespace ID.
   * Queries are scoped to a single partition.
   * </pre>
   *
   * <code>.google.datastore.v1.PartitionId partition_id = 1;</code>
   */
  public com.google.datastore.v1.PartitionIdOrBuilder getPartitionIdOrBuilder() {
    return getPartitionId();
  }

  public static final int PATH_FIELD_NUMBER = 2;
  private java.util.List<com.google.datastore.v1.Key.PathElement> path_;
  /**
   * <pre>
   * The entity path.
   * An entity path consists of one or more elements composed of a kind and a
   * string or numerical identifier, which identify entities. The first
   * element identifies a _root entity_, the second element identifies
   * a _child_ of the root entity, the third element identifies a child of the
   * second entity, and so forth. The entities identified by all prefixes of
   * the path are called the element's _ancestors_.
   * An entity path is always fully complete: *all* of the entity's ancestors
   * are required to be in the path along with the entity identifier itself.
   * The only exception is that in some documented cases, the identifier in the
   * last path element (for the entity) itself may be omitted. For example,
   * the last path element of the key of `Mutation.insert` may have no
   * identifier.
   * A path can never be empty, and a path can have at most 100 elements.
   * </pre>
   *
   * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
   */
  public java.util.List<com.google.datastore.v1.Key.PathElement> getPathList() {
    return path_;
  }
  /**
   * <pre>
   * The entity path.
   * An entity path consists of one or more elements composed of a kind and a
   * string or numerical identifier, which identify entities. The first
   * element identifies a _root entity_, the second element identifies
   * a _child_ of the root entity, the third element identifies a child of the
   * second entity, and so forth. The entities identified by all prefixes of
   * the path are called the element's _ancestors_.
   * An entity path is always fully complete: *all* of the entity's ancestors
   * are required to be in the path along with the entity identifier itself.
   * The only exception is that in some documented cases, the identifier in the
   * last path element (for the entity) itself may be omitted. For example,
   * the last path element of the key of `Mutation.insert` may have no
   * identifier.
   * A path can never be empty, and a path can have at most 100 elements.
   * </pre>
   *
   * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
   */
  public java.util.List<? extends com.google.datastore.v1.Key.PathElementOrBuilder> 
      getPathOrBuilderList() {
    return path_;
  }
  /**
   * <pre>
   * The entity path.
   * An entity path consists of one or more elements composed of a kind and a
   * string or numerical identifier, which identify entities. The first
   * element identifies a _root entity_, the second element identifies
   * a _child_ of the root entity, the third element identifies a child of the
   * second entity, and so forth. The entities identified by all prefixes of
   * the path are called the element's _ancestors_.
   * An entity path is always fully complete: *all* of the entity's ancestors
   * are required to be in the path along with the entity identifier itself.
   * The only exception is that in some documented cases, the identifier in the
   * last path element (for the entity) itself may be omitted. For example,
   * the last path element of the key of `Mutation.insert` may have no
   * identifier.
   * A path can never be empty, and a path can have at most 100 elements.
   * </pre>
   *
   * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
   */
  public int getPathCount() {
    return path_.size();
  }
  /**
   * <pre>
   * The entity path.
   * An entity path consists of one or more elements composed of a kind and a
   * string or numerical identifier, which identify entities. The first
   * element identifies a _root entity_, the second element identifies
   * a _child_ of the root entity, the third element identifies a child of the
   * second entity, and so forth. The entities identified by all prefixes of
   * the path are called the element's _ancestors_.
   * An entity path is always fully complete: *all* of the entity's ancestors
   * are required to be in the path along with the entity identifier itself.
   * The only exception is that in some documented cases, the identifier in the
   * last path element (for the entity) itself may be omitted. For example,
   * the last path element of the key of `Mutation.insert` may have no
   * identifier.
   * A path can never be empty, and a path can have at most 100 elements.
   * </pre>
   *
   * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
   */
  public com.google.datastore.v1.Key.PathElement getPath(int index) {
    return path_.get(index);
  }
  /**
   * <pre>
   * The entity path.
   * An entity path consists of one or more elements composed of a kind and a
   * string or numerical identifier, which identify entities. The first
   * element identifies a _root entity_, the second element identifies
   * a _child_ of the root entity, the third element identifies a child of the
   * second entity, and so forth. The entities identified by all prefixes of
   * the path are called the element's _ancestors_.
   * An entity path is always fully complete: *all* of the entity's ancestors
   * are required to be in the path along with the entity identifier itself.
   * The only exception is that in some documented cases, the identifier in the
   * last path element (for the entity) itself may be omitted. For example,
   * the last path element of the key of `Mutation.insert` may have no
   * identifier.
   * A path can never be empty, and a path can have at most 100 elements.
   * </pre>
   *
   * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
   */
  public com.google.datastore.v1.Key.PathElementOrBuilder getPathOrBuilder(
      int index) {
    return path_.get(index);
  }

  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 {
    if (partitionId_ != null) {
      output.writeMessage(1, getPartitionId());
    }
    for (int i = 0; i < path_.size(); i++) {
      output.writeMessage(2, path_.get(i));
    }
    unknownFields.writeTo(output);
  }

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

    size = 0;
    if (partitionId_ != null) {
      size += com.google.protobuf.CodedOutputStream
        .computeMessageSize(1, getPartitionId());
    }
    for (int i = 0; i < path_.size(); i++) {
      size += com.google.protobuf.CodedOutputStream
        .computeMessageSize(2, path_.get(i));
    }
    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.Key)) {
      return super.equals(obj);
    }
    com.google.datastore.v1.Key other = (com.google.datastore.v1.Key) obj;

    boolean result = true;
    result = result && (hasPartitionId() == other.hasPartitionId());
    if (hasPartitionId()) {
      result = result && getPartitionId()
          .equals(other.getPartitionId());
    }
    result = result && getPathList()
        .equals(other.getPathList());
    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 (hasPartitionId()) {
      hash = (37 * hash) + PARTITION_ID_FIELD_NUMBER;
      hash = (53 * hash) + getPartitionId().hashCode();
    }
    if (getPathCount() > 0) {
      hash = (37 * hash) + PATH_FIELD_NUMBER;
      hash = (53 * hash) + getPathList().hashCode();
    }
    hash = (29 * hash) + unknownFields.hashCode();
    memoizedHashCode = hash;
    return hash;
  }

  public static com.google.datastore.v1.Key parseFrom(
      java.nio.ByteBuffer data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.google.datastore.v1.Key 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.Key parseFrom(
      com.google.protobuf.ByteString data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.google.datastore.v1.Key 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.Key parseFrom(byte[] data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }
  public static com.google.datastore.v1.Key parseFrom(
      byte[] data,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }
  public static com.google.datastore.v1.Key parseFrom(java.io.InputStream input)
      throws java.io.IOException {
    return com.google.protobuf.GeneratedMessageV3
        .parseWithIOException(PARSER, input);
  }
  public static com.google.datastore.v1.Key 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.Key parseDelimitedFrom(java.io.InputStream input)
      throws java.io.IOException {
    return com.google.protobuf.GeneratedMessageV3
        .parseDelimitedWithIOException(PARSER, input);
  }
  public static com.google.datastore.v1.Key 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.Key parseFrom(
      com.google.protobuf.CodedInputStream input)
      throws java.io.IOException {
    return com.google.protobuf.GeneratedMessageV3
        .parseWithIOException(PARSER, input);
  }
  public static com.google.datastore.v1.Key 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.Key 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 unique identifier for an entity.
   * If a key's partition ID or any of its path kinds or names are
   * reserved/read-only, the key is reserved/read-only.
   * A reserved/read-only key is forbidden in certain documented contexts.
   * </pre>
   *
   * Protobuf type {@code google.datastore.v1.Key}
   */
  public static final class Builder extends
      com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
      // @@protoc_insertion_point(builder_implements:google.datastore.v1.Key)
      com.google.datastore.v1.KeyOrBuilder {
    public static final com.google.protobuf.Descriptors.Descriptor
        getDescriptor() {
      return com.google.datastore.v1.EntityProto.internal_static_google_datastore_v1_Key_descriptor;
    }

    protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return com.google.datastore.v1.EntityProto.internal_static_google_datastore_v1_Key_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.google.datastore.v1.Key.class, com.google.datastore.v1.Key.Builder.class);
    }

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

    private Builder(
        com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
      super(parent);
      maybeForceBuilderInitialization();
    }
    private void maybeForceBuilderInitialization() {
      if (com.google.protobuf.GeneratedMessageV3
              .alwaysUseFieldBuilders) {
        getPathFieldBuilder();
      }
    }
    public Builder clear() {
      super.clear();
      if (partitionIdBuilder_ == null) {
        partitionId_ = null;
      } else {
        partitionId_ = null;
        partitionIdBuilder_ = null;
      }
      if (pathBuilder_ == null) {
        path_ = java.util.Collections.emptyList();
        bitField0_ = (bitField0_ & ~0x00000002);
      } else {
        pathBuilder_.clear();
      }
      return this;
    }

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

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

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

    public com.google.datastore.v1.Key buildPartial() {
      com.google.datastore.v1.Key result = new com.google.datastore.v1.Key(this);
      int from_bitField0_ = bitField0_;
      int to_bitField0_ = 0;
      if (partitionIdBuilder_ == null) {
        result.partitionId_ = partitionId_;
      } else {
        result.partitionId_ = partitionIdBuilder_.build();
      }
      if (pathBuilder_ == null) {
        if (((bitField0_ & 0x00000002) == 0x00000002)) {
          path_ = java.util.Collections.unmodifiableList(path_);
          bitField0_ = (bitField0_ & ~0x00000002);
        }
        result.path_ = path_;
      } else {
        result.path_ = pathBuilder_.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.Key) {
        return mergeFrom((com.google.datastore.v1.Key)other);
      } else {
        super.mergeFrom(other);
        return this;
      }
    }

    public Builder mergeFrom(com.google.datastore.v1.Key other) {
      if (other == com.google.datastore.v1.Key.getDefaultInstance()) return this;
      if (other.hasPartitionId()) {
        mergePartitionId(other.getPartitionId());
      }
      if (pathBuilder_ == null) {
        if (!other.path_.isEmpty()) {
          if (path_.isEmpty()) {
            path_ = other.path_;
            bitField0_ = (bitField0_ & ~0x00000002);
          } else {
            ensurePathIsMutable();
            path_.addAll(other.path_);
          }
          onChanged();
        }
      } else {
        if (!other.path_.isEmpty()) {
          if (pathBuilder_.isEmpty()) {
            pathBuilder_.dispose();
            pathBuilder_ = null;
            path_ = other.path_;
            bitField0_ = (bitField0_ & ~0x00000002);
            pathBuilder_ = 
              com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ?
                 getPathFieldBuilder() : null;
          } else {
            pathBuilder_.addAllMessages(other.path_);
          }
        }
      }
      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.Key parsedMessage = null;
      try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        parsedMessage = (com.google.datastore.v1.Key) e.getUnfinishedMessage();
        throw e.unwrapIOException();
      } finally {
        if (parsedMessage != null) {
          mergeFrom(parsedMessage);
        }
      }
      return this;
    }
    private int bitField0_;

    private com.google.datastore.v1.PartitionId partitionId_ = null;
    private com.google.protobuf.SingleFieldBuilderV3<
        com.google.datastore.v1.PartitionId, com.google.datastore.v1.PartitionId.Builder, com.google.datastore.v1.PartitionIdOrBuilder> partitionIdBuilder_;
    /**
     * <pre>
     * Entities are partitioned into subsets, currently identified by a project
     * ID and namespace ID.
     * Queries are scoped to a single partition.
     * </pre>
     *
     * <code>.google.datastore.v1.PartitionId partition_id = 1;</code>
     */
    public boolean hasPartitionId() {
      return partitionIdBuilder_ != null || partitionId_ != null;
    }
    /**
     * <pre>
     * Entities are partitioned into subsets, currently identified by a project
     * ID and namespace ID.
     * Queries are scoped to a single partition.
     * </pre>
     *
     * <code>.google.datastore.v1.PartitionId partition_id = 1;</code>
     */
    public com.google.datastore.v1.PartitionId getPartitionId() {
      if (partitionIdBuilder_ == null) {
        return partitionId_ == null ? com.google.datastore.v1.PartitionId.getDefaultInstance() : partitionId_;
      } else {
        return partitionIdBuilder_.getMessage();
      }
    }
    /**
     * <pre>
     * Entities are partitioned into subsets, currently identified by a project
     * ID and namespace ID.
     * Queries are scoped to a single partition.
     * </pre>
     *
     * <code>.google.datastore.v1.PartitionId partition_id = 1;</code>
     */
    public Builder setPartitionId(com.google.datastore.v1.PartitionId value) {
      if (partitionIdBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        partitionId_ = value;
        onChanged();
      } else {
        partitionIdBuilder_.setMessage(value);
      }

      return this;
    }
    /**
     * <pre>
     * Entities are partitioned into subsets, currently identified by a project
     * ID and namespace ID.
     * Queries are scoped to a single partition.
     * </pre>
     *
     * <code>.google.datastore.v1.PartitionId partition_id = 1;</code>
     */
    public Builder setPartitionId(
        com.google.datastore.v1.PartitionId.Builder builderForValue) {
      if (partitionIdBuilder_ == null) {
        partitionId_ = builderForValue.build();
        onChanged();
      } else {
        partitionIdBuilder_.setMessage(builderForValue.build());
      }

      return this;
    }
    /**
     * <pre>
     * Entities are partitioned into subsets, currently identified by a project
     * ID and namespace ID.
     * Queries are scoped to a single partition.
     * </pre>
     *
     * <code>.google.datastore.v1.PartitionId partition_id = 1;</code>
     */
    public Builder mergePartitionId(com.google.datastore.v1.PartitionId value) {
      if (partitionIdBuilder_ == null) {
        if (partitionId_ != null) {
          partitionId_ =
            com.google.datastore.v1.PartitionId.newBuilder(partitionId_).mergeFrom(value).buildPartial();
        } else {
          partitionId_ = value;
        }
        onChanged();
      } else {
        partitionIdBuilder_.mergeFrom(value);
      }

      return this;
    }
    /**
     * <pre>
     * Entities are partitioned into subsets, currently identified by a project
     * ID and namespace ID.
     * Queries are scoped to a single partition.
     * </pre>
     *
     * <code>.google.datastore.v1.PartitionId partition_id = 1;</code>
     */
    public Builder clearPartitionId() {
      if (partitionIdBuilder_ == null) {
        partitionId_ = null;
        onChanged();
      } else {
        partitionId_ = null;
        partitionIdBuilder_ = null;
      }

      return this;
    }
    /**
     * <pre>
     * Entities are partitioned into subsets, currently identified by a project
     * ID and namespace ID.
     * Queries are scoped to a single partition.
     * </pre>
     *
     * <code>.google.datastore.v1.PartitionId partition_id = 1;</code>
     */
    public com.google.datastore.v1.PartitionId.Builder getPartitionIdBuilder() {
      
      onChanged();
      return getPartitionIdFieldBuilder().getBuilder();
    }
    /**
     * <pre>
     * Entities are partitioned into subsets, currently identified by a project
     * ID and namespace ID.
     * Queries are scoped to a single partition.
     * </pre>
     *
     * <code>.google.datastore.v1.PartitionId partition_id = 1;</code>
     */
    public com.google.datastore.v1.PartitionIdOrBuilder getPartitionIdOrBuilder() {
      if (partitionIdBuilder_ != null) {
        return partitionIdBuilder_.getMessageOrBuilder();
      } else {
        return partitionId_ == null ?
            com.google.datastore.v1.PartitionId.getDefaultInstance() : partitionId_;
      }
    }
    /**
     * <pre>
     * Entities are partitioned into subsets, currently identified by a project
     * ID and namespace ID.
     * Queries are scoped to a single partition.
     * </pre>
     *
     * <code>.google.datastore.v1.PartitionId partition_id = 1;</code>
     */
    private com.google.protobuf.SingleFieldBuilderV3<
        com.google.datastore.v1.PartitionId, com.google.datastore.v1.PartitionId.Builder, com.google.datastore.v1.PartitionIdOrBuilder> 
        getPartitionIdFieldBuilder() {
      if (partitionIdBuilder_ == null) {
        partitionIdBuilder_ = new com.google.protobuf.SingleFieldBuilderV3<
            com.google.datastore.v1.PartitionId, com.google.datastore.v1.PartitionId.Builder, com.google.datastore.v1.PartitionIdOrBuilder>(
                getPartitionId(),
                getParentForChildren(),
                isClean());
        partitionId_ = null;
      }
      return partitionIdBuilder_;
    }

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

    private com.google.protobuf.RepeatedFieldBuilderV3<
        com.google.datastore.v1.Key.PathElement, com.google.datastore.v1.Key.PathElement.Builder, com.google.datastore.v1.Key.PathElementOrBuilder> pathBuilder_;

    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public java.util.List<com.google.datastore.v1.Key.PathElement> getPathList() {
      if (pathBuilder_ == null) {
        return java.util.Collections.unmodifiableList(path_);
      } else {
        return pathBuilder_.getMessageList();
      }
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public int getPathCount() {
      if (pathBuilder_ == null) {
        return path_.size();
      } else {
        return pathBuilder_.getCount();
      }
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public com.google.datastore.v1.Key.PathElement getPath(int index) {
      if (pathBuilder_ == null) {
        return path_.get(index);
      } else {
        return pathBuilder_.getMessage(index);
      }
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public Builder setPath(
        int index, com.google.datastore.v1.Key.PathElement value) {
      if (pathBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensurePathIsMutable();
        path_.set(index, value);
        onChanged();
      } else {
        pathBuilder_.setMessage(index, value);
      }
      return this;
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public Builder setPath(
        int index, com.google.datastore.v1.Key.PathElement.Builder builderForValue) {
      if (pathBuilder_ == null) {
        ensurePathIsMutable();
        path_.set(index, builderForValue.build());
        onChanged();
      } else {
        pathBuilder_.setMessage(index, builderForValue.build());
      }
      return this;
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public Builder addPath(com.google.datastore.v1.Key.PathElement value) {
      if (pathBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensurePathIsMutable();
        path_.add(value);
        onChanged();
      } else {
        pathBuilder_.addMessage(value);
      }
      return this;
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public Builder addPath(
        int index, com.google.datastore.v1.Key.PathElement value) {
      if (pathBuilder_ == null) {
        if (value == null) {
          throw new NullPointerException();
        }
        ensurePathIsMutable();
        path_.add(index, value);
        onChanged();
      } else {
        pathBuilder_.addMessage(index, value);
      }
      return this;
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public Builder addPath(
        com.google.datastore.v1.Key.PathElement.Builder builderForValue) {
      if (pathBuilder_ == null) {
        ensurePathIsMutable();
        path_.add(builderForValue.build());
        onChanged();
      } else {
        pathBuilder_.addMessage(builderForValue.build());
      }
      return this;
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public Builder addPath(
        int index, com.google.datastore.v1.Key.PathElement.Builder builderForValue) {
      if (pathBuilder_ == null) {
        ensurePathIsMutable();
        path_.add(index, builderForValue.build());
        onChanged();
      } else {
        pathBuilder_.addMessage(index, builderForValue.build());
      }
      return this;
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public Builder addAllPath(
        java.lang.Iterable<? extends com.google.datastore.v1.Key.PathElement> values) {
      if (pathBuilder_ == null) {
        ensurePathIsMutable();
        com.google.protobuf.AbstractMessageLite.Builder.addAll(
            values, path_);
        onChanged();
      } else {
        pathBuilder_.addAllMessages(values);
      }
      return this;
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public Builder clearPath() {
      if (pathBuilder_ == null) {
        path_ = java.util.Collections.emptyList();
        bitField0_ = (bitField0_ & ~0x00000002);
        onChanged();
      } else {
        pathBuilder_.clear();
      }
      return this;
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public Builder removePath(int index) {
      if (pathBuilder_ == null) {
        ensurePathIsMutable();
        path_.remove(index);
        onChanged();
      } else {
        pathBuilder_.remove(index);
      }
      return this;
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public com.google.datastore.v1.Key.PathElement.Builder getPathBuilder(
        int index) {
      return getPathFieldBuilder().getBuilder(index);
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public com.google.datastore.v1.Key.PathElementOrBuilder getPathOrBuilder(
        int index) {
      if (pathBuilder_ == null) {
        return path_.get(index);  } else {
        return pathBuilder_.getMessageOrBuilder(index);
      }
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public java.util.List<? extends com.google.datastore.v1.Key.PathElementOrBuilder> 
         getPathOrBuilderList() {
      if (pathBuilder_ != null) {
        return pathBuilder_.getMessageOrBuilderList();
      } else {
        return java.util.Collections.unmodifiableList(path_);
      }
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public com.google.datastore.v1.Key.PathElement.Builder addPathBuilder() {
      return getPathFieldBuilder().addBuilder(
          com.google.datastore.v1.Key.PathElement.getDefaultInstance());
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public com.google.datastore.v1.Key.PathElement.Builder addPathBuilder(
        int index) {
      return getPathFieldBuilder().addBuilder(
          index, com.google.datastore.v1.Key.PathElement.getDefaultInstance());
    }
    /**
     * <pre>
     * The entity path.
     * An entity path consists of one or more elements composed of a kind and a
     * string or numerical identifier, which identify entities. The first
     * element identifies a _root entity_, the second element identifies
     * a _child_ of the root entity, the third element identifies a child of the
     * second entity, and so forth. The entities identified by all prefixes of
     * the path are called the element's _ancestors_.
     * An entity path is always fully complete: *all* of the entity's ancestors
     * are required to be in the path along with the entity identifier itself.
     * The only exception is that in some documented cases, the identifier in the
     * last path element (for the entity) itself may be omitted. For example,
     * the last path element of the key of `Mutation.insert` may have no
     * identifier.
     * A path can never be empty, and a path can have at most 100 elements.
     * </pre>
     *
     * <code>repeated .google.datastore.v1.Key.PathElement path = 2;</code>
     */
    public java.util.List<com.google.datastore.v1.Key.PathElement.Builder> 
         getPathBuilderList() {
      return getPathFieldBuilder().getBuilderList();
    }
    private com.google.protobuf.RepeatedFieldBuilderV3<
        com.google.datastore.v1.Key.PathElement, com.google.datastore.v1.Key.PathElement.Builder, com.google.datastore.v1.Key.PathElementOrBuilder> 
        getPathFieldBuilder() {
      if (pathBuilder_ == null) {
        pathBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3<
            com.google.datastore.v1.Key.PathElement, com.google.datastore.v1.Key.PathElement.Builder, com.google.datastore.v1.Key.PathElementOrBuilder>(
                path_,
                ((bitField0_ & 0x00000002) == 0x00000002),
                getParentForChildren(),
                isClean());
        path_ = null;
      }
      return pathBuilder_;
    }
    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.Key)
  }

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

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

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

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

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

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

}

