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.33 by jsr166, Sat Jun 18 19:36:25 2005 UTC vs.
Revision 1.34 by dl, Thu Dec 15 17:38:06 2005 UTC

# Line 40 | Line 40 | package java.util.concurrent;
40   * @author Doug Lea
41   */
42   public enum TimeUnit {
43 <    NANOSECONDS (0) {
43 >    NANOSECONDS {
44          public long toNanos(long d)   { return d; }
45          public long toMicros(long d)  { return d/(C1/C0); }
46          public long toMillis(long d)  { return d/(C2/C0); }
# Line 51 | Line 51 | public enum TimeUnit {
51          public long convert(long d, TimeUnit u) { return u.toNanos(d); }
52          int excessNanos(long d, long m) { return (int)(d - (m*C2)); }
53      },
54 <    MICROSECONDS (1) {
54 >    MICROSECONDS {
55          public long toNanos(long d)   { return x(d, C1/C0, MAX/(C1/C0)); }
56          public long toMicros(long d)  { return d; }
57          public long toMillis(long d)  { return d/(C2/C1); }
# Line 62 | Line 62 | public enum TimeUnit {
62          public long convert(long d, TimeUnit u) { return u.toMicros(d); }
63          int excessNanos(long d, long m) { return (int)((d*C1) - (m*C2)); }
64      },
65 <    MILLISECONDS (2) {
65 >    MILLISECONDS {
66          public long toNanos(long d)   { return x(d, C2/C0, MAX/(C2/C0)); }
67          public long toMicros(long d)  { return x(d, C2/C1, MAX/(C2/C1)); }
68          public long toMillis(long d)  { return d; }
# Line 73 | Line 73 | public enum TimeUnit {
73          public long convert(long d, TimeUnit u) { return u.toMillis(d); }
74          int excessNanos(long d, long m) { return 0; }
75      },
76 <    SECONDS (3) {
76 >    SECONDS {
77          public long toNanos(long d)   { return x(d, C3/C0, MAX/(C3/C0)); }
78          public long toMicros(long d)  { return x(d, C3/C1, MAX/(C3/C1)); }
79          public long toMillis(long d)  { return x(d, C3/C2, MAX/(C3/C2)); }
# Line 84 | Line 84 | public enum TimeUnit {
84          public long convert(long d, TimeUnit u) { return u.toSeconds(d); }
85          int excessNanos(long d, long m) { return 0; }
86      },
87 <    MINUTES (4) {
87 >    MINUTES {
88          public long toNanos(long d)   { return x(d, C4/C0, MAX/(C4/C0)); }
89          public long toMicros(long d)  { return x(d, C4/C1, MAX/(C4/C1)); }
90          public long toMillis(long d)  { return x(d, C4/C2, MAX/(C4/C2)); }
# Line 95 | Line 95 | public enum TimeUnit {
95          public long convert(long d, TimeUnit u) { return u.toMinutes(d); }
96          int excessNanos(long d, long m) { return 0; }
97      },
98 <    HOURS (5) {
98 >    HOURS {
99          public long toNanos(long d)   { return x(d, C5/C0, MAX/(C5/C0)); }
100          public long toMicros(long d)  { return x(d, C5/C1, MAX/(C5/C1)); }
101          public long toMillis(long d)  { return x(d, C5/C2, MAX/(C5/C2)); }
# Line 106 | Line 106 | public enum TimeUnit {
106          public long convert(long d, TimeUnit u) { return u.toHours(d); }
107          int excessNanos(long d, long m) { return 0; }
108      },
109 <    DAYS (6) {
109 >    DAYS {
110          public long toNanos(long d)   { return x(d, C6/C0, MAX/(C6/C0)); }
111          public long toMicros(long d)  { return x(d, C6/C1, MAX/(C6/C1)); }
112          public long toMillis(long d)  { return x(d, C6/C2, MAX/(C6/C2)); }
# Line 118 | Line 118 | public enum TimeUnit {
118          int excessNanos(long d, long m) { return 0; }
119      };
120  
121    /**
122     * The index of this unit. This value is no longer used in this
123     * version of this class, but is retained for serialization
124     * compatibility with previous version.
125     */
126    private final int index;
127
128    /** Internal constructor */
129    TimeUnit(int index) {
130        this.index = index;
131    }
132
121      // Handy constants for conversion methods
122      static final long C0 = 1L;
123      static final long C1 = C0 * 1000L;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines