Stopwatch.java 3.49 KB
package com.google.common.base;

import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import java.util.concurrent.TimeUnit;

@Beta
@GwtCompatible(emulated=true)
public final class Stopwatch
{
  private final Ticker a;
  private boolean b;
  private long c;
  private long d;
  
  @Deprecated
  Stopwatch()
  {
    this(Ticker.systemTicker());
  }
  
  @Deprecated
  private Stopwatch(Ticker paramTicker)
  {
    this.a = ((Ticker)Preconditions.checkNotNull(paramTicker, "ticker"));
  }
  
  private long a()
  {
    if (this.b) {
      return this.a.read() - this.d + this.c;
    }
    return this.c;
  }
  
  public static Stopwatch createStarted()
  {
    return new Stopwatch().start();
  }
  
  public static Stopwatch createStarted(Ticker paramTicker)
  {
    return new Stopwatch(paramTicker).start();
  }
  
  public static Stopwatch createUnstarted()
  {
    return new Stopwatch();
  }
  
  public static Stopwatch createUnstarted(Ticker paramTicker)
  {
    return new Stopwatch(paramTicker);
  }
  
  public final long elapsed(TimeUnit paramTimeUnit)
  {
    return paramTimeUnit.convert(a(), TimeUnit.NANOSECONDS);
  }
  
  public final boolean isRunning()
  {
    return this.b;
  }
  
  public final Stopwatch reset()
  {
    this.c = 0L;
    this.b = false;
    return this;
  }
  
  public final Stopwatch start()
  {
    if (!this.b) {}
    for (boolean bool = true;; bool = false)
    {
      Preconditions.checkState(bool, "This stopwatch is already running.");
      this.b = true;
      this.d = this.a.read();
      return this;
    }
  }
  
  public final Stopwatch stop()
  {
    long l1 = this.a.read();
    Preconditions.checkState(this.b, "This stopwatch is already stopped.");
    this.b = false;
    long l2 = this.c;
    this.c = (l1 - this.d + l2);
    return this;
  }
  
  @GwtIncompatible("String.format()")
  public final String toString()
  {
    long l = a();
    if (TimeUnit.DAYS.convert(l, TimeUnit.NANOSECONDS) > 0L) {
      localObject = TimeUnit.DAYS;
    }
    double d1;
    for (;;)
    {
      d1 = l / TimeUnit.NANOSECONDS.convert(1L, (TimeUnit)localObject);
      switch (1.a[localObject.ordinal()])
      {
      default: 
        throw new AssertionError();
        if (TimeUnit.HOURS.convert(l, TimeUnit.NANOSECONDS) > 0L) {
          localObject = TimeUnit.HOURS;
        } else if (TimeUnit.MINUTES.convert(l, TimeUnit.NANOSECONDS) > 0L) {
          localObject = TimeUnit.MINUTES;
        } else if (TimeUnit.SECONDS.convert(l, TimeUnit.NANOSECONDS) > 0L) {
          localObject = TimeUnit.SECONDS;
        } else if (TimeUnit.MILLISECONDS.convert(l, TimeUnit.NANOSECONDS) > 0L) {
          localObject = TimeUnit.MILLISECONDS;
        } else if (TimeUnit.MICROSECONDS.convert(l, TimeUnit.NANOSECONDS) > 0L) {
          localObject = TimeUnit.MICROSECONDS;
        } else {
          localObject = TimeUnit.NANOSECONDS;
        }
        break;
      }
    }
    Object localObject = "ns";
    for (;;)
    {
      return String.format("%.4g %s", new Object[] { Double.valueOf(d1), localObject });
      localObject = "μs";
      continue;
      localObject = "ms";
      continue;
      localObject = "s";
      continue;
      localObject = "min";
      continue;
      localObject = "h";
      continue;
      localObject = "d";
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/google/common/base/Stopwatch.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */