/*
 * Copyright 2020 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: google/dataflow/v1beta3/metrics.proto

package com.google.dataflow.v1beta3;

/**
 *
 *
 * <pre>
 * Identifies a metric, by describing the source which generated the
 * metric.
 * </pre>
 *
 * Protobuf type {@code google.dataflow.v1beta3.MetricStructuredName}
 */
public final class MetricStructuredName extends com.google.protobuf.GeneratedMessageV3
    implements
    // @@protoc_insertion_point(message_implements:google.dataflow.v1beta3.MetricStructuredName)
    MetricStructuredNameOrBuilder {
  private static final long serialVersionUID = 0L;
  // Use MetricStructuredName.newBuilder() to construct.
  private MetricStructuredName(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
    super(builder);
  }

  private MetricStructuredName() {
    origin_ = "";
    name_ = "";
  }

  @java.lang.Override
  @SuppressWarnings({"unused"})
  protected java.lang.Object newInstance(UnusedPrivateParameter unused) {
    return new MetricStructuredName();
  }

  @java.lang.Override
  public final com.google.protobuf.UnknownFieldSet getUnknownFields() {
    return this.unknownFields;
  }

  private MetricStructuredName(
      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;
          case 10:
            {
              java.lang.String s = input.readStringRequireUtf8();

              origin_ = s;
              break;
            }
          case 18:
            {
              java.lang.String s = input.readStringRequireUtf8();

              name_ = s;
              break;
            }
          case 26:
            {
              if (!((mutable_bitField0_ & 0x00000001) != 0)) {
                context_ =
                    com.google.protobuf.MapField.newMapField(
                        ContextDefaultEntryHolder.defaultEntry);
                mutable_bitField0_ |= 0x00000001;
              }
              com.google.protobuf.MapEntry<java.lang.String, java.lang.String> context__ =
                  input.readMessage(
                      ContextDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry);
              context_.getMutableMap().put(context__.getKey(), context__.getValue());
              break;
            }
          default:
            {
              if (!parseUnknownField(input, unknownFields, extensionRegistry, tag)) {
                done = true;
              }
              break;
            }
        }
      }
    } catch (com.google.protobuf.InvalidProtocolBufferException e) {
      throw e.setUnfinishedMessage(this);
    } catch (com.google.protobuf.UninitializedMessageException e) {
      throw e.asInvalidProtocolBufferException().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.dataflow.v1beta3.MetricsProto
        .internal_static_google_dataflow_v1beta3_MetricStructuredName_descriptor;
  }

  @SuppressWarnings({"rawtypes"})
  @java.lang.Override
  protected com.google.protobuf.MapField internalGetMapField(int number) {
    switch (number) {
      case 3:
        return internalGetContext();
      default:
        throw new RuntimeException("Invalid map field number: " + number);
    }
  }

  @java.lang.Override
  protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
      internalGetFieldAccessorTable() {
    return com.google.dataflow.v1beta3.MetricsProto
        .internal_static_google_dataflow_v1beta3_MetricStructuredName_fieldAccessorTable
        .ensureFieldAccessorsInitialized(
            com.google.dataflow.v1beta3.MetricStructuredName.class,
            com.google.dataflow.v1beta3.MetricStructuredName.Builder.class);
  }

  public static final int ORIGIN_FIELD_NUMBER = 1;
  private volatile java.lang.Object origin_;
  /**
   *
   *
   * <pre>
   * Origin (namespace) of metric name. May be blank for user-define metrics;
   * will be "dataflow" for metrics defined by the Dataflow service or SDK.
   * </pre>
   *
   * <code>string origin = 1;</code>
   *
   * @return The origin.
   */
  @java.lang.Override
  public java.lang.String getOrigin() {
    java.lang.Object ref = origin_;
    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();
      origin_ = s;
      return s;
    }
  }
  /**
   *
   *
   * <pre>
   * Origin (namespace) of metric name. May be blank for user-define metrics;
   * will be "dataflow" for metrics defined by the Dataflow service or SDK.
   * </pre>
   *
   * <code>string origin = 1;</code>
   *
   * @return The bytes for origin.
   */
  @java.lang.Override
  public com.google.protobuf.ByteString getOriginBytes() {
    java.lang.Object ref = origin_;
    if (ref instanceof java.lang.String) {
      com.google.protobuf.ByteString b =
          com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);
      origin_ = b;
      return b;
    } else {
      return (com.google.protobuf.ByteString) ref;
    }
  }

  public static final int NAME_FIELD_NUMBER = 2;
  private volatile java.lang.Object name_;
  /**
   *
   *
   * <pre>
   * Worker-defined metric name.
   * </pre>
   *
   * <code>string name = 2;</code>
   *
   * @return The name.
   */
  @java.lang.Override
  public java.lang.String getName() {
    java.lang.Object ref = name_;
    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();
      name_ = s;
      return s;
    }
  }
  /**
   *
   *
   * <pre>
   * Worker-defined metric name.
   * </pre>
   *
   * <code>string name = 2;</code>
   *
   * @return The bytes for name.
   */
  @java.lang.Override
  public com.google.protobuf.ByteString getNameBytes() {
    java.lang.Object ref = name_;
    if (ref instanceof java.lang.String) {
      com.google.protobuf.ByteString b =
          com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);
      name_ = b;
      return b;
    } else {
      return (com.google.protobuf.ByteString) ref;
    }
  }

  public static final int CONTEXT_FIELD_NUMBER = 3;

  private static final class ContextDefaultEntryHolder {
    static final com.google.protobuf.MapEntry<java.lang.String, java.lang.String> defaultEntry =
        com.google.protobuf.MapEntry.<java.lang.String, java.lang.String>newDefaultInstance(
            com.google.dataflow.v1beta3.MetricsProto
                .internal_static_google_dataflow_v1beta3_MetricStructuredName_ContextEntry_descriptor,
            com.google.protobuf.WireFormat.FieldType.STRING,
            "",
            com.google.protobuf.WireFormat.FieldType.STRING,
            "");
  }

  private com.google.protobuf.MapField<java.lang.String, java.lang.String> context_;

  private com.google.protobuf.MapField<java.lang.String, java.lang.String> internalGetContext() {
    if (context_ == null) {
      return com.google.protobuf.MapField.emptyMapField(ContextDefaultEntryHolder.defaultEntry);
    }
    return context_;
  }

  public int getContextCount() {
    return internalGetContext().getMap().size();
  }
  /**
   *
   *
   * <pre>
   * Zero or more labeled fields which identify the part of the job this
   * metric is associated with, such as the name of a step or collection.
   * For example, built-in counters associated with steps will have
   * context['step'] = &lt;step-name&gt;. Counters associated with PCollections
   * in the SDK will have context['pcollection'] = &lt;pcollection-name&gt;.
   * </pre>
   *
   * <code>map&lt;string, string&gt; context = 3;</code>
   */
  @java.lang.Override
  public boolean containsContext(java.lang.String key) {
    if (key == null) {
      throw new NullPointerException("map key");
    }
    return internalGetContext().getMap().containsKey(key);
  }
  /** Use {@link #getContextMap()} instead. */
  @java.lang.Override
  @java.lang.Deprecated
  public java.util.Map<java.lang.String, java.lang.String> getContext() {
    return getContextMap();
  }
  /**
   *
   *
   * <pre>
   * Zero or more labeled fields which identify the part of the job this
   * metric is associated with, such as the name of a step or collection.
   * For example, built-in counters associated with steps will have
   * context['step'] = &lt;step-name&gt;. Counters associated with PCollections
   * in the SDK will have context['pcollection'] = &lt;pcollection-name&gt;.
   * </pre>
   *
   * <code>map&lt;string, string&gt; context = 3;</code>
   */
  @java.lang.Override
  public java.util.Map<java.lang.String, java.lang.String> getContextMap() {
    return internalGetContext().getMap();
  }
  /**
   *
   *
   * <pre>
   * Zero or more labeled fields which identify the part of the job this
   * metric is associated with, such as the name of a step or collection.
   * For example, built-in counters associated with steps will have
   * context['step'] = &lt;step-name&gt;. Counters associated with PCollections
   * in the SDK will have context['pcollection'] = &lt;pcollection-name&gt;.
   * </pre>
   *
   * <code>map&lt;string, string&gt; context = 3;</code>
   */
  @java.lang.Override
  public java.lang.String getContextOrDefault(java.lang.String key, java.lang.String defaultValue) {
    if (key == null) {
      throw new NullPointerException("map key");
    }
    java.util.Map<java.lang.String, java.lang.String> map = internalGetContext().getMap();
    return map.containsKey(key) ? map.get(key) : defaultValue;
  }
  /**
   *
   *
   * <pre>
   * Zero or more labeled fields which identify the part of the job this
   * metric is associated with, such as the name of a step or collection.
   * For example, built-in counters associated with steps will have
   * context['step'] = &lt;step-name&gt;. Counters associated with PCollections
   * in the SDK will have context['pcollection'] = &lt;pcollection-name&gt;.
   * </pre>
   *
   * <code>map&lt;string, string&gt; context = 3;</code>
   */
  @java.lang.Override
  public java.lang.String getContextOrThrow(java.lang.String key) {
    if (key == null) {
      throw new NullPointerException("map key");
    }
    java.util.Map<java.lang.String, java.lang.String> map = internalGetContext().getMap();
    if (!map.containsKey(key)) {
      throw new java.lang.IllegalArgumentException();
    }
    return map.get(key);
  }

  private byte memoizedIsInitialized = -1;

  @java.lang.Override
  public final boolean isInitialized() {
    byte isInitialized = memoizedIsInitialized;
    if (isInitialized == 1) return true;
    if (isInitialized == 0) return false;

    memoizedIsInitialized = 1;
    return true;
  }

  @java.lang.Override
  public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException {
    if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(origin_)) {
      com.google.protobuf.GeneratedMessageV3.writeString(output, 1, origin_);
    }
    if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) {
      com.google.protobuf.GeneratedMessageV3.writeString(output, 2, name_);
    }
    com.google.protobuf.GeneratedMessageV3.serializeStringMapTo(
        output, internalGetContext(), ContextDefaultEntryHolder.defaultEntry, 3);
    unknownFields.writeTo(output);
  }

  @java.lang.Override
  public int getSerializedSize() {
    int size = memoizedSize;
    if (size != -1) return size;

    size = 0;
    if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(origin_)) {
      size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, origin_);
    }
    if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) {
      size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, name_);
    }
    for (java.util.Map.Entry<java.lang.String, java.lang.String> entry :
        internalGetContext().getMap().entrySet()) {
      com.google.protobuf.MapEntry<java.lang.String, java.lang.String> context__ =
          ContextDefaultEntryHolder.defaultEntry
              .newBuilderForType()
              .setKey(entry.getKey())
              .setValue(entry.getValue())
              .build();
      size += com.google.protobuf.CodedOutputStream.computeMessageSize(3, context__);
    }
    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.dataflow.v1beta3.MetricStructuredName)) {
      return super.equals(obj);
    }
    com.google.dataflow.v1beta3.MetricStructuredName other =
        (com.google.dataflow.v1beta3.MetricStructuredName) obj;

    if (!getOrigin().equals(other.getOrigin())) return false;
    if (!getName().equals(other.getName())) return false;
    if (!internalGetContext().equals(other.internalGetContext())) return false;
    if (!unknownFields.equals(other.unknownFields)) return false;
    return true;
  }

  @java.lang.Override
  public int hashCode() {
    if (memoizedHashCode != 0) {
      return memoizedHashCode;
    }
    int hash = 41;
    hash = (19 * hash) + getDescriptor().hashCode();
    hash = (37 * hash) + ORIGIN_FIELD_NUMBER;
    hash = (53 * hash) + getOrigin().hashCode();
    hash = (37 * hash) + NAME_FIELD_NUMBER;
    hash = (53 * hash) + getName().hashCode();
    if (!internalGetContext().getMap().isEmpty()) {
      hash = (37 * hash) + CONTEXT_FIELD_NUMBER;
      hash = (53 * hash) + internalGetContext().hashCode();
    }
    hash = (29 * hash) + unknownFields.hashCode();
    memoizedHashCode = hash;
    return hash;
  }

  public static com.google.dataflow.v1beta3.MetricStructuredName parseFrom(java.nio.ByteBuffer data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }

  public static com.google.dataflow.v1beta3.MetricStructuredName parseFrom(
      java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }

  public static com.google.dataflow.v1beta3.MetricStructuredName parseFrom(
      com.google.protobuf.ByteString data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }

  public static com.google.dataflow.v1beta3.MetricStructuredName 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.dataflow.v1beta3.MetricStructuredName parseFrom(byte[] data)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data);
  }

  public static com.google.dataflow.v1beta3.MetricStructuredName parseFrom(
      byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws com.google.protobuf.InvalidProtocolBufferException {
    return PARSER.parseFrom(data, extensionRegistry);
  }

  public static com.google.dataflow.v1beta3.MetricStructuredName parseFrom(
      java.io.InputStream input) throws java.io.IOException {
    return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input);
  }

  public static com.google.dataflow.v1beta3.MetricStructuredName 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.dataflow.v1beta3.MetricStructuredName parseDelimitedFrom(
      java.io.InputStream input) throws java.io.IOException {
    return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input);
  }

  public static com.google.dataflow.v1beta3.MetricStructuredName 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.dataflow.v1beta3.MetricStructuredName parseFrom(
      com.google.protobuf.CodedInputStream input) throws java.io.IOException {
    return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input);
  }

  public static com.google.dataflow.v1beta3.MetricStructuredName parseFrom(
      com.google.protobuf.CodedInputStream input,
      com.google.protobuf.ExtensionRegistryLite extensionRegistry)
      throws java.io.IOException {
    return com.google.protobuf.GeneratedMessageV3.parseWithIOException(
        PARSER, input, extensionRegistry);
  }

  @java.lang.Override
  public Builder newBuilderForType() {
    return newBuilder();
  }

  public static Builder newBuilder() {
    return DEFAULT_INSTANCE.toBuilder();
  }

  public static Builder newBuilder(com.google.dataflow.v1beta3.MetricStructuredName prototype) {
    return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
  }

  @java.lang.Override
  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>
   * Identifies a metric, by describing the source which generated the
   * metric.
   * </pre>
   *
   * Protobuf type {@code google.dataflow.v1beta3.MetricStructuredName}
   */
  public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder<Builder>
      implements
      // @@protoc_insertion_point(builder_implements:google.dataflow.v1beta3.MetricStructuredName)
      com.google.dataflow.v1beta3.MetricStructuredNameOrBuilder {
    public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() {
      return com.google.dataflow.v1beta3.MetricsProto
          .internal_static_google_dataflow_v1beta3_MetricStructuredName_descriptor;
    }

    @SuppressWarnings({"rawtypes"})
    protected com.google.protobuf.MapField internalGetMapField(int number) {
      switch (number) {
        case 3:
          return internalGetContext();
        default:
          throw new RuntimeException("Invalid map field number: " + number);
      }
    }

    @SuppressWarnings({"rawtypes"})
    protected com.google.protobuf.MapField internalGetMutableMapField(int number) {
      switch (number) {
        case 3:
          return internalGetMutableContext();
        default:
          throw new RuntimeException("Invalid map field number: " + number);
      }
    }

    @java.lang.Override
    protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
        internalGetFieldAccessorTable() {
      return com.google.dataflow.v1beta3.MetricsProto
          .internal_static_google_dataflow_v1beta3_MetricStructuredName_fieldAccessorTable
          .ensureFieldAccessorsInitialized(
              com.google.dataflow.v1beta3.MetricStructuredName.class,
              com.google.dataflow.v1beta3.MetricStructuredName.Builder.class);
    }

    // Construct using com.google.dataflow.v1beta3.MetricStructuredName.newBuilder()
    private Builder() {
      maybeForceBuilderInitialization();
    }

    private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
      super(parent);
      maybeForceBuilderInitialization();
    }

    private void maybeForceBuilderInitialization() {
      if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) {}
    }

    @java.lang.Override
    public Builder clear() {
      super.clear();
      origin_ = "";

      name_ = "";

      internalGetMutableContext().clear();
      return this;
    }

    @java.lang.Override
    public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() {
      return com.google.dataflow.v1beta3.MetricsProto
          .internal_static_google_dataflow_v1beta3_MetricStructuredName_descriptor;
    }

    @java.lang.Override
    public com.google.dataflow.v1beta3.MetricStructuredName getDefaultInstanceForType() {
      return com.google.dataflow.v1beta3.MetricStructuredName.getDefaultInstance();
    }

    @java.lang.Override
    public com.google.dataflow.v1beta3.MetricStructuredName build() {
      com.google.dataflow.v1beta3.MetricStructuredName result = buildPartial();
      if (!result.isInitialized()) {
        throw newUninitializedMessageException(result);
      }
      return result;
    }

    @java.lang.Override
    public com.google.dataflow.v1beta3.MetricStructuredName buildPartial() {
      com.google.dataflow.v1beta3.MetricStructuredName result =
          new com.google.dataflow.v1beta3.MetricStructuredName(this);
      int from_bitField0_ = bitField0_;
      result.origin_ = origin_;
      result.name_ = name_;
      result.context_ = internalGetContext();
      result.context_.makeImmutable();
      onBuilt();
      return result;
    }

    @java.lang.Override
    public Builder clone() {
      return super.clone();
    }

    @java.lang.Override
    public Builder setField(
        com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) {
      return super.setField(field, value);
    }

    @java.lang.Override
    public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) {
      return super.clearField(field);
    }

    @java.lang.Override
    public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) {
      return super.clearOneof(oneof);
    }

    @java.lang.Override
    public Builder setRepeatedField(
        com.google.protobuf.Descriptors.FieldDescriptor field, int index, java.lang.Object value) {
      return super.setRepeatedField(field, index, value);
    }

    @java.lang.Override
    public Builder addRepeatedField(
        com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) {
      return super.addRepeatedField(field, value);
    }

    @java.lang.Override
    public Builder mergeFrom(com.google.protobuf.Message other) {
      if (other instanceof com.google.dataflow.v1beta3.MetricStructuredName) {
        return mergeFrom((com.google.dataflow.v1beta3.MetricStructuredName) other);
      } else {
        super.mergeFrom(other);
        return this;
      }
    }

    public Builder mergeFrom(com.google.dataflow.v1beta3.MetricStructuredName other) {
      if (other == com.google.dataflow.v1beta3.MetricStructuredName.getDefaultInstance())
        return this;
      if (!other.getOrigin().isEmpty()) {
        origin_ = other.origin_;
        onChanged();
      }
      if (!other.getName().isEmpty()) {
        name_ = other.name_;
        onChanged();
      }
      internalGetMutableContext().mergeFrom(other.internalGetContext());
      this.mergeUnknownFields(other.unknownFields);
      onChanged();
      return this;
    }

    @java.lang.Override
    public final boolean isInitialized() {
      return true;
    }

    @java.lang.Override
    public Builder mergeFrom(
        com.google.protobuf.CodedInputStream input,
        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
        throws java.io.IOException {
      com.google.dataflow.v1beta3.MetricStructuredName parsedMessage = null;
      try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
      } catch (com.google.protobuf.InvalidProtocolBufferException e) {
        parsedMessage = (com.google.dataflow.v1beta3.MetricStructuredName) e.getUnfinishedMessage();
        throw e.unwrapIOException();
      } finally {
        if (parsedMessage != null) {
          mergeFrom(parsedMessage);
        }
      }
      return this;
    }

    private int bitField0_;

    private java.lang.Object origin_ = "";
    /**
     *
     *
     * <pre>
     * Origin (namespace) of metric name. May be blank for user-define metrics;
     * will be "dataflow" for metrics defined by the Dataflow service or SDK.
     * </pre>
     *
     * <code>string origin = 1;</code>
     *
     * @return The origin.
     */
    public java.lang.String getOrigin() {
      java.lang.Object ref = origin_;
      if (!(ref instanceof java.lang.String)) {
        com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;
        java.lang.String s = bs.toStringUtf8();
        origin_ = s;
        return s;
      } else {
        return (java.lang.String) ref;
      }
    }
    /**
     *
     *
     * <pre>
     * Origin (namespace) of metric name. May be blank for user-define metrics;
     * will be "dataflow" for metrics defined by the Dataflow service or SDK.
     * </pre>
     *
     * <code>string origin = 1;</code>
     *
     * @return The bytes for origin.
     */
    public com.google.protobuf.ByteString getOriginBytes() {
      java.lang.Object ref = origin_;
      if (ref instanceof String) {
        com.google.protobuf.ByteString b =
            com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);
        origin_ = b;
        return b;
      } else {
        return (com.google.protobuf.ByteString) ref;
      }
    }
    /**
     *
     *
     * <pre>
     * Origin (namespace) of metric name. May be blank for user-define metrics;
     * will be "dataflow" for metrics defined by the Dataflow service or SDK.
     * </pre>
     *
     * <code>string origin = 1;</code>
     *
     * @param value The origin to set.
     * @return This builder for chaining.
     */
    public Builder setOrigin(java.lang.String value) {
      if (value == null) {
        throw new NullPointerException();
      }

      origin_ = value;
      onChanged();
      return this;
    }
    /**
     *
     *
     * <pre>
     * Origin (namespace) of metric name. May be blank for user-define metrics;
     * will be "dataflow" for metrics defined by the Dataflow service or SDK.
     * </pre>
     *
     * <code>string origin = 1;</code>
     *
     * @return This builder for chaining.
     */
    public Builder clearOrigin() {

      origin_ = getDefaultInstance().getOrigin();
      onChanged();
      return this;
    }
    /**
     *
     *
     * <pre>
     * Origin (namespace) of metric name. May be blank for user-define metrics;
     * will be "dataflow" for metrics defined by the Dataflow service or SDK.
     * </pre>
     *
     * <code>string origin = 1;</code>
     *
     * @param value The bytes for origin to set.
     * @return This builder for chaining.
     */
    public Builder setOriginBytes(com.google.protobuf.ByteString value) {
      if (value == null) {
        throw new NullPointerException();
      }
      checkByteStringIsUtf8(value);

      origin_ = value;
      onChanged();
      return this;
    }

    private java.lang.Object name_ = "";
    /**
     *
     *
     * <pre>
     * Worker-defined metric name.
     * </pre>
     *
     * <code>string name = 2;</code>
     *
     * @return The name.
     */
    public java.lang.String getName() {
      java.lang.Object ref = name_;
      if (!(ref instanceof java.lang.String)) {
        com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;
        java.lang.String s = bs.toStringUtf8();
        name_ = s;
        return s;
      } else {
        return (java.lang.String) ref;
      }
    }
    /**
     *
     *
     * <pre>
     * Worker-defined metric name.
     * </pre>
     *
     * <code>string name = 2;</code>
     *
     * @return The bytes for name.
     */
    public com.google.protobuf.ByteString getNameBytes() {
      java.lang.Object ref = name_;
      if (ref instanceof String) {
        com.google.protobuf.ByteString b =
            com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);
        name_ = b;
        return b;
      } else {
        return (com.google.protobuf.ByteString) ref;
      }
    }
    /**
     *
     *
     * <pre>
     * Worker-defined metric name.
     * </pre>
     *
     * <code>string name = 2;</code>
     *
     * @param value The name to set.
     * @return This builder for chaining.
     */
    public Builder setName(java.lang.String value) {
      if (value == null) {
        throw new NullPointerException();
      }

      name_ = value;
      onChanged();
      return this;
    }
    /**
     *
     *
     * <pre>
     * Worker-defined metric name.
     * </pre>
     *
     * <code>string name = 2;</code>
     *
     * @return This builder for chaining.
     */
    public Builder clearName() {

      name_ = getDefaultInstance().getName();
      onChanged();
      return this;
    }
    /**
     *
     *
     * <pre>
     * Worker-defined metric name.
     * </pre>
     *
     * <code>string name = 2;</code>
     *
     * @param value The bytes for name to set.
     * @return This builder for chaining.
     */
    public Builder setNameBytes(com.google.protobuf.ByteString value) {
      if (value == null) {
        throw new NullPointerException();
      }
      checkByteStringIsUtf8(value);

      name_ = value;
      onChanged();
      return this;
    }

    private com.google.protobuf.MapField<java.lang.String, java.lang.String> context_;

    private com.google.protobuf.MapField<java.lang.String, java.lang.String> internalGetContext() {
      if (context_ == null) {
        return com.google.protobuf.MapField.emptyMapField(ContextDefaultEntryHolder.defaultEntry);
      }
      return context_;
    }

    private com.google.protobuf.MapField<java.lang.String, java.lang.String>
        internalGetMutableContext() {
      onChanged();
      ;
      if (context_ == null) {
        context_ = com.google.protobuf.MapField.newMapField(ContextDefaultEntryHolder.defaultEntry);
      }
      if (!context_.isMutable()) {
        context_ = context_.copy();
      }
      return context_;
    }

    public int getContextCount() {
      return internalGetContext().getMap().size();
    }
    /**
     *
     *
     * <pre>
     * Zero or more labeled fields which identify the part of the job this
     * metric is associated with, such as the name of a step or collection.
     * For example, built-in counters associated with steps will have
     * context['step'] = &lt;step-name&gt;. Counters associated with PCollections
     * in the SDK will have context['pcollection'] = &lt;pcollection-name&gt;.
     * </pre>
     *
     * <code>map&lt;string, string&gt; context = 3;</code>
     */
    @java.lang.Override
    public boolean containsContext(java.lang.String key) {
      if (key == null) {
        throw new NullPointerException("map key");
      }
      return internalGetContext().getMap().containsKey(key);
    }
    /** Use {@link #getContextMap()} instead. */
    @java.lang.Override
    @java.lang.Deprecated
    public java.util.Map<java.lang.String, java.lang.String> getContext() {
      return getContextMap();
    }
    /**
     *
     *
     * <pre>
     * Zero or more labeled fields which identify the part of the job this
     * metric is associated with, such as the name of a step or collection.
     * For example, built-in counters associated with steps will have
     * context['step'] = &lt;step-name&gt;. Counters associated with PCollections
     * in the SDK will have context['pcollection'] = &lt;pcollection-name&gt;.
     * </pre>
     *
     * <code>map&lt;string, string&gt; context = 3;</code>
     */
    @java.lang.Override
    public java.util.Map<java.lang.String, java.lang.String> getContextMap() {
      return internalGetContext().getMap();
    }
    /**
     *
     *
     * <pre>
     * Zero or more labeled fields which identify the part of the job this
     * metric is associated with, such as the name of a step or collection.
     * For example, built-in counters associated with steps will have
     * context['step'] = &lt;step-name&gt;. Counters associated with PCollections
     * in the SDK will have context['pcollection'] = &lt;pcollection-name&gt;.
     * </pre>
     *
     * <code>map&lt;string, string&gt; context = 3;</code>
     */
    @java.lang.Override
    public java.lang.String getContextOrDefault(
        java.lang.String key, java.lang.String defaultValue) {
      if (key == null) {
        throw new NullPointerException("map key");
      }
      java.util.Map<java.lang.String, java.lang.String> map = internalGetContext().getMap();
      return map.containsKey(key) ? map.get(key) : defaultValue;
    }
    /**
     *
     *
     * <pre>
     * Zero or more labeled fields which identify the part of the job this
     * metric is associated with, such as the name of a step or collection.
     * For example, built-in counters associated with steps will have
     * context['step'] = &lt;step-name&gt;. Counters associated with PCollections
     * in the SDK will have context['pcollection'] = &lt;pcollection-name&gt;.
     * </pre>
     *
     * <code>map&lt;string, string&gt; context = 3;</code>
     */
    @java.lang.Override
    public java.lang.String getContextOrThrow(java.lang.String key) {
      if (key == null) {
        throw new NullPointerException("map key");
      }
      java.util.Map<java.lang.String, java.lang.String> map = internalGetContext().getMap();
      if (!map.containsKey(key)) {
        throw new java.lang.IllegalArgumentException();
      }
      return map.get(key);
    }

    public Builder clearContext() {
      internalGetMutableContext().getMutableMap().clear();
      return this;
    }
    /**
     *
     *
     * <pre>
     * Zero or more labeled fields which identify the part of the job this
     * metric is associated with, such as the name of a step or collection.
     * For example, built-in counters associated with steps will have
     * context['step'] = &lt;step-name&gt;. Counters associated with PCollections
     * in the SDK will have context['pcollection'] = &lt;pcollection-name&gt;.
     * </pre>
     *
     * <code>map&lt;string, string&gt; context = 3;</code>
     */
    public Builder removeContext(java.lang.String key) {
      if (key == null) {
        throw new NullPointerException("map key");
      }
      internalGetMutableContext().getMutableMap().remove(key);
      return this;
    }
    /** Use alternate mutation accessors instead. */
    @java.lang.Deprecated
    public java.util.Map<java.lang.String, java.lang.String> getMutableContext() {
      return internalGetMutableContext().getMutableMap();
    }
    /**
     *
     *
     * <pre>
     * Zero or more labeled fields which identify the part of the job this
     * metric is associated with, such as the name of a step or collection.
     * For example, built-in counters associated with steps will have
     * context['step'] = &lt;step-name&gt;. Counters associated with PCollections
     * in the SDK will have context['pcollection'] = &lt;pcollection-name&gt;.
     * </pre>
     *
     * <code>map&lt;string, string&gt; context = 3;</code>
     */
    public Builder putContext(java.lang.String key, java.lang.String value) {
      if (key == null) {
        throw new NullPointerException("map key");
      }
      if (value == null) {
        throw new NullPointerException("map value");
      }

      internalGetMutableContext().getMutableMap().put(key, value);
      return this;
    }
    /**
     *
     *
     * <pre>
     * Zero or more labeled fields which identify the part of the job this
     * metric is associated with, such as the name of a step or collection.
     * For example, built-in counters associated with steps will have
     * context['step'] = &lt;step-name&gt;. Counters associated with PCollections
     * in the SDK will have context['pcollection'] = &lt;pcollection-name&gt;.
     * </pre>
     *
     * <code>map&lt;string, string&gt; context = 3;</code>
     */
    public Builder putAllContext(java.util.Map<java.lang.String, java.lang.String> values) {
      internalGetMutableContext().getMutableMap().putAll(values);
      return this;
    }

    @java.lang.Override
    public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) {
      return super.setUnknownFields(unknownFields);
    }

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

    // @@protoc_insertion_point(builder_scope:google.dataflow.v1beta3.MetricStructuredName)
  }

  // @@protoc_insertion_point(class_scope:google.dataflow.v1beta3.MetricStructuredName)
  private static final com.google.dataflow.v1beta3.MetricStructuredName DEFAULT_INSTANCE;

  static {
    DEFAULT_INSTANCE = new com.google.dataflow.v1beta3.MetricStructuredName();
  }

  public static com.google.dataflow.v1beta3.MetricStructuredName getDefaultInstance() {
    return DEFAULT_INSTANCE;
  }

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

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

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

  @java.lang.Override
  public com.google.dataflow.v1beta3.MetricStructuredName getDefaultInstanceForType() {
    return DEFAULT_INSTANCE;
  }
}
