StopWatch.java 3.38 KB
package org.apache.commons.lang3.time;

import java.util.concurrent.TimeUnit;

public class StopWatch
{
  private b a = b.a;
  private int b = a.b;
  private long c;
  private long d;
  private long e;
  
  public static StopWatch createStarted()
  {
    StopWatch localStopWatch = new StopWatch();
    localStopWatch.start();
    return localStopWatch;
  }
  
  public long getNanoTime()
  {
    if ((this.a == b.c) || (this.a == b.d)) {
      return this.e - this.c;
    }
    if (this.a == b.a) {
      return 0L;
    }
    if (this.a == b.b) {
      return System.nanoTime() - this.c;
    }
    throw new RuntimeException("Illegal running state has occurred.");
  }
  
  public long getSplitNanoTime()
  {
    if (this.b != a.a) {
      throw new IllegalStateException("Stopwatch must be split to get the split time. ");
    }
    return this.e - this.c;
  }
  
  public long getSplitTime()
  {
    return getSplitNanoTime() / 1000000L;
  }
  
  public long getStartTime()
  {
    if (this.a == b.a) {
      throw new IllegalStateException("Stopwatch has not been started");
    }
    return this.d;
  }
  
  public long getTime()
  {
    return getNanoTime() / 1000000L;
  }
  
  public long getTime(TimeUnit paramTimeUnit)
  {
    return paramTimeUnit.convert(getNanoTime(), TimeUnit.NANOSECONDS);
  }
  
  public boolean isStarted()
  {
    return this.a.a();
  }
  
  public boolean isStopped()
  {
    return this.a.b();
  }
  
  public boolean isSuspended()
  {
    return this.a.c();
  }
  
  public void reset()
  {
    this.a = b.a;
    this.b = a.b;
  }
  
  public void resume()
  {
    if (this.a != b.d) {
      throw new IllegalStateException("Stopwatch must be suspended to resume. ");
    }
    this.c += System.nanoTime() - this.e;
    this.a = b.b;
  }
  
  public void split()
  {
    if (this.a != b.b) {
      throw new IllegalStateException("Stopwatch is not running. ");
    }
    this.e = System.nanoTime();
    this.b = a.a;
  }
  
  public void start()
  {
    if (this.a == b.c) {
      throw new IllegalStateException("Stopwatch must be reset before being restarted. ");
    }
    if (this.a != b.a) {
      throw new IllegalStateException("Stopwatch already started. ");
    }
    this.c = System.nanoTime();
    this.d = System.currentTimeMillis();
    this.a = b.b;
  }
  
  public void stop()
  {
    if ((this.a != b.b) && (this.a != b.d)) {
      throw new IllegalStateException("Stopwatch is not running. ");
    }
    if (this.a == b.b) {
      this.e = System.nanoTime();
    }
    this.a = b.c;
  }
  
  public void suspend()
  {
    if (this.a != b.b) {
      throw new IllegalStateException("Stopwatch must be running to suspend. ");
    }
    this.e = System.nanoTime();
    this.a = b.d;
  }
  
  public String toSplitString()
  {
    return DurationFormatUtils.formatDurationHMS(getSplitTime());
  }
  
  public String toString()
  {
    return DurationFormatUtils.formatDurationHMS(getTime());
  }
  
  public void unsplit()
  {
    if (this.b != a.a) {
      throw new IllegalStateException("Stopwatch has not been split. ");
    }
    this.b = a.b;
  }
  
  static enum a {}
  
  static abstract enum b
  {
    private b() {}
    
    abstract boolean a();
    
    abstract boolean b();
    
    abstract boolean c();
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/org/apache/commons/lang3/time/StopWatch.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */