<commit_before>/*
 * Copyright 2016, Google Inc.
 * 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
 *     http://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.
 */

package com.google.instrumentation.stats;

import java.io.OutputStream;

/**
 * An immutable context for stats operations.
 */
public abstract class StatsContext {
  /**
   * Returns a builder based on this {@link StatsContext}.
   */
  public abstract Builder builder();

  /** Shorthand for builder().set(k1, v1).build() */
  public final StatsContext with(TagKey k1, TagValue v1) {
    return builder().set(k1, v1).build();
  }

  /** Shorthand for builder().set(k1, v1).set(k2, v2).build() */
  public final StatsContext with(TagKey k1, TagValue v1, TagKey k2, TagValue v2) {
    return builder().set(k1, v1).set(k2, v2).build();
  }

  /** Shorthand for builder().set(k1, v1).set(k2, v2).set(k3, v3).build() */
  public final StatsContext with(
      TagKey k1, TagValue v1, TagKey k2, TagValue v2, TagKey k3, TagValue v3) {
    return builder().set(k1, v1).set(k2, v2).set(k3, v3).build();
  }

  /**
   * Records the given measurements against this {@link StatsContext}.
   *
   * @param measurements the measurements to record against the saved {@link StatsContext}
   * @return this
   */
  public abstract StatsContext record(MeasurementMap measurements);

  /**
   * Serializes the {@link StatsContext} into the on-the-wire representation.
   *
   * <p>The inverse of {@link StatsContextFactory#deserialize(OutputStream)} and should be based on
   * the {@link StatsContext} protobuf representation.
   *
   * @param output the {@link OutputStream} to add the serialized form of this {@link StatsContext}.
   * @return the given {@link OutputStream}
   */
  public abstract OutputStream serialize(OutputStream output);

  /**
   * Builder for {@link StatsContext}.
   */
  public abstract static class Builder {
    /**<commit_msg>Updates javadoc reference.<commit_after>/*
 * Copyright 2016, Google Inc.
 * 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
 *     http://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.
 */

package com.google.instrumentation.stats;

import java.io.OutputStream;

/**
 * An immutable context for stats operations.
 */
public abstract class StatsContext {
  /**
   * Returns a builder based on this {@link StatsContext}.
   */
  public abstract Builder builder();

  /** Shorthand for builder().set(k1, v1).build() */
  public final StatsContext with(TagKey k1, TagValue v1) {
    return builder().set(k1, v1).build();
  }

  /** Shorthand for builder().set(k1, v1).set(k2, v2).build() */
  public final StatsContext with(TagKey k1, TagValue v1, TagKey k2, TagValue v2) {
    return builder().set(k1, v1).set(k2, v2).build();
  }

  /** Shorthand for builder().set(k1, v1).set(k2, v2).set(k3, v3).build() */
  public final StatsContext with(
      TagKey k1, TagValue v1, TagKey k2, TagValue v2, TagKey k3, TagValue v3) {
    return builder().set(k1, v1).set(k2, v2).set(k3, v3).build();
  }

  /**
   * Records the given measurements against this {@link StatsContext}.
   *
   * @param measurements the measurements to record against the saved {@link StatsContext}
   * @return this
   */
  public abstract StatsContext record(MeasurementMap measurements);

  /**
   * Serializes the {@link StatsContext} into the on-the-wire representation.
   *
   * <p>The inverse of {@link StatsContextFactory#deserialize(ByteBuffer)} and should be based on
   * the {@link StatsContext} protobuf representation.
   *
   * @param output the {@link OutputStream} to add the serialized form of this {@link StatsContext}.
   * @return the given {@link OutputStream}
   */
  public abstract OutputStream serialize(OutputStream output);

  /**
   * Builder for {@link StatsContext}.
   */
  public abstract static class Builder {
    /**
{'fraction_non_alphanumeric': 0.11423101467772814, 'fraction_numerical': 0.01871942139970219, 'mean_word_length': 3.702, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6645494', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1347, 'n_words': 506}