File: 09-preserve-stopwatch-methods.patch

package info (click to toggle)
guava-libraries 32.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,472 kB
  • sloc: java: 359,877; xml: 2,612; sh: 34; javascript: 12; makefile: 8
file content (83 lines) | stat: -rw-r--r-- 2,871 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Description:  Preserves the Stopwatch methods and constructors removed in Guava 15 and 16.
Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: not-needed
--- a/guava/src/com/google/common/base/Stopwatch.java
+++ b/guava/src/com/google/common/base/Stopwatch.java
@@ -139,11 +139,11 @@
     return new Stopwatch(ticker).start();
   }
 
-  Stopwatch() {
+  public Stopwatch() {
     this.ticker = Ticker.systemTicker();
   }
 
-  Stopwatch(Ticker ticker) {
+  public Stopwatch(Ticker ticker) {
     this.ticker = checkNotNull(ticker, "ticker");
   }
 
@@ -219,6 +219,35 @@
   }
 
   /**
+   * Returns the current elapsed time shown on this stopwatch, expressed
+   * in the desired time unit, with any fraction rounded down.
+   *
+   * <p>Note that the overhead of measurement can be more than a microsecond, so
+   * it is generally not useful to specify {@link TimeUnit#NANOSECONDS}
+   * precision here.
+   *
+   * @deprecated Use {@link Stopwatch#elapsed(TimeUnit)} instead. This method is
+   *     scheduled to be removed in Guava release 16.0.
+   */
+  @Deprecated
+  public long elapsedTime(TimeUnit desiredUnit) {
+    return elapsed(desiredUnit);
+  }
+
+  /**
+   * Returns the current elapsed time shown on this stopwatch, expressed
+   * in milliseconds, with any fraction rounded down. This is identical to
+   * {@code elapsed(TimeUnit.MILLISECONDS)}.
+   *
+   * @deprecated Use {@code stopwatch.elapsed(MILLISECONDS)} instead. This
+   *     method is scheduled to be removed in Guava release 16.0.
+   */
+  @Deprecated
+  public long elapsedMillis() {
+    return elapsed(MILLISECONDS);
+  }
+
+  /**
    * Returns the current elapsed time shown on this stopwatch as a {@link Duration}. Unlike {@link
    * #elapsed(TimeUnit)}, this method does not lose any precision due to rounding.
    *
@@ -243,6 +272,27 @@
     return Platform.formatCompact4Digits(value) + " " + abbreviate(unit);
   }
 
+  /**
+   * Returns a string representation of the current elapsed time, choosing an
+   * appropriate unit and using the specified number of significant figures.
+   * For example, at the instant when {@code elapsed(NANOSECONDS)} would
+   * return {1234567}, {@code toString(4)} returns {@code "1.235 ms"}.
+   *
+   * @deprecated Use {@link #toString()} instead. This method is scheduled
+   *     to be removed in Guava release 15.0.
+   */
+  @Deprecated
+  public String toString(int significantDigits) {
+    long nanos = elapsedNanos();
+
+    TimeUnit unit = chooseUnit(nanos);
+    double value = (double) nanos / NANOSECONDS.convert(1, unit);
+
+    // Too bad this functionality is not exposed as a regular method call
+    return String.format("%." + significantDigits + "g %s",
+        value, abbreviate(unit));
+  }
+
   private static TimeUnit chooseUnit(long nanos) {
     if (DAYS.convert(nanos, NANOSECONDS) > 0) {
       return DAYS;