<commit_before>/*
 * Copyright 2017, 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.internal;

import com.google.common.math.LongMath;
import com.google.instrumentation.common.Clock;
import com.google.instrumentation.common.Duration;
import com.google.instrumentation.common.Timestamp;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;

/**
 * A {@link Clock} that allows the time to be set for testing.
 */
@ThreadSafe
public final class TestClock extends Clock {
  private static final int NUM_NANOS_PER_SECOND = 1000 * 1000 * 1000;

  @GuardedBy("this")
  private Timestamp currentTime = Timestamp.create(123, 456);

  private TestClock() {}

  /**
   * Creates a clock initialized to a constant non-zero time. {@code Timestamp.create(0, 0)} is not
   * a good default, because it represents an invalid time.
   *
   * @return a clock initialized to a constant non-zero time.
   */
  public static TestClock create() {
    return new TestClock();
  }<commit_msg>Use a time from 2017 as TestClock's default time.<commit_after>/*
 * Copyright 2017, 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.internal;

import com.google.common.math.LongMath;
import com.google.instrumentation.common.Clock;
import com.google.instrumentation.common.Duration;
import com.google.instrumentation.common.Timestamp;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;

/**
 * A {@link Clock} that allows the time to be set for testing.
 */
@ThreadSafe
public final class TestClock extends Clock {
  private static final int NUM_NANOS_PER_SECOND = 1000 * 1000 * 1000;

  @GuardedBy("this")
  private Timestamp currentTime = validateNanos(Timestamp.create(1493419949, 223123456));

  private TestClock() {}

  /**
   * Creates a clock initialized to a constant non-zero time. {@code Timestamp.create(0, 0)} is not
   * a good default, because it represents an invalid time.
   *
   * @return a clock initialized to a constant non-zero time.
   */
  public static TestClock create() {
    return new TestClock();
  }
{'fraction_non_alphanumeric': 0.08657465495608532, 'fraction_numerical': 0.022898368883312422, 'mean_word_length': 4.127009646302251, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6079625', 'n_tokens_mistral': 916, 'n_tokens_neox': 843, 'n_words': 350}