Coverage Summary for Class: Ticker (com.google.common.base)

Class Method, % Line, %
Ticker 100% (3/3) 100% (3/3)
Ticker$1 100% (2/2) 100% (2/2)
Total 100% (5/5) 100% (5/5)


1 /* 2  * Copyright (C) 2011 The Guava Authors 3  * 4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5  * in compliance with the License. You may obtain a copy of the License at 6  * 7  * http://www.apache.org/licenses/LICENSE-2.0 8  * 9  * Unless required by applicable law or agreed to in writing, software distributed under the License 10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11  * or implied. See the License for the specific language governing permissions and limitations under 12  * the License. 13  */ 14  15 package com.google.common.base; 16  17 import com.google.common.annotations.GwtCompatible; 18  19 /** 20  * A time source; returns a time value representing the number of nanoseconds elapsed since some 21  * fixed but arbitrary point in time. Note that most users should use {@link Stopwatch} instead of 22  * interacting with this class directly. 23  * 24  * <p><b>Warning:</b> this interface can only be used to measure elapsed time, not wall time. 25  * 26  * @author Kevin Bourrillion 27  * @since 10.0 (<a href="https://github.com/google/guava/wiki/Compatibility">mostly 28  * source-compatible</a> since 9.0) 29  */ 30 @GwtCompatible 31 @ElementTypesAreNonnullByDefault 32 public abstract class Ticker { 33  /** Constructor for use by subclasses. */ 34  protected Ticker() {} 35  36  /** Returns the number of nanoseconds elapsed since this ticker's fixed point of reference. */ 37  public abstract long read(); 38  39  /** 40  * A ticker that reads the current time using {@link System#nanoTime}. 41  * 42  * @since 10.0 43  */ 44  public static Ticker systemTicker() { 45  return SYSTEM_TICKER; 46  } 47  48  private static final Ticker SYSTEM_TICKER = 49  new Ticker() { 50  @Override 51  public long read() { 52  return Platform.systemNanoTime(); 53  } 54  }; 55 }