ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/TimeUnit.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/TimeUnit.java (file contents):
Revision 1.11 by dl, Sat Aug 30 14:59:27 2003 UTC vs.
Revision 1.12 by dl, Sun Aug 31 13:33:14 2003 UTC

# Line 15 | Line 15 | package java.util.concurrent;
15   * use time representations that may be maintained separately across
16   * various contexts.
17   *
18 < * <p>The <tt>TimeUnit</tt> class cannot be directly instantiated.
19 < * Use the {@link #SECONDS}, {@link #MILLISECONDS}, {@link #MICROSECONDS},
20 < * and {@link #NANOSECONDS} static instances that provide predefined
21 < * units of precision. If you use these frequently, consider
22 < * statically importing this class.
18 > * <p>This class cannot be directly instantiated.  Use the {@link
19 > * #SECONDS}, {@link #MILLISECONDS}, {@link #MICROSECONDS}, and {@link
20 > * #NANOSECONDS} static instances that provide predefined units of
21 > * precision. If you use these frequently, consider statically
22 > * importing this class.
23   *
24   * <p>A <tt>TimeUnit</tt> is mainly used to inform blocking methods which
25   * can timeout, how the timeout parameter should be interpreted. For example,
# Line 38 | Line 38 | package java.util.concurrent;
38   * as the given <tt>TimeUnit</tt>.
39   *
40   * @since 1.5
41 * @spec JSR-166
42 * @revised $Date$
43 * @editor $Author$
41   * @author Doug Lea
42   */
43   public final class TimeUnit implements java.io.Serializable {
# Line 60 | Line 57 | public final class TimeUnit implements j
57       * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
58       */
59      public long convert(long duration, TimeUnit unit) {
60 <        if (unit == this)
60 >        int i = unit.index - index;
61 >        if (i == 0)
62              return duration;
63 <        else if (index > unit.index)
64 <            return duration / multipliers[index - unit.index];
65 <        else {
66 <            int i = unit.index - index;
67 <            if (duration > overflows[i])
68 <                return Long.MAX_VALUE;
69 <            if (duration < -overflows[i])
72 <                return Long.MIN_VALUE;
73 <            return duration * multipliers[i];
74 <        }
63 >        if (i < 0)
64 >            return duration / multipliers[-i];
65 >        if (duration > overflows[i])
66 >            return Long.MAX_VALUE;
67 >        if (duration < -overflows[i])
68 >            return Long.MIN_VALUE;
69 >        return duration * multipliers[i];
70      }
71  
72      /**
73 <     * Equivalent to <code>NANOSECONDS.convert(duration, this)</code>.
73 >     * Equivalent to <tt>NANOSECONDS.convert(duration, this)</tt>.
74       * @param duration the duration
75       * @return the converted duration.
76       * or <tt>Long.MIN_VALUE</tt> if conversion would negatively

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines