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.27 by dl, Tue Mar 8 12:27:11 2005 UTC vs.
Revision 1.33 by jsr166, Sat Jun 18 19:36:25 2005 UTC

# Line 117 | Line 117 | public enum TimeUnit {
117          public long convert(long d, TimeUnit u) { return u.toDays(d); }
118          int excessNanos(long d, long m) { return 0; }
119      };
120 <    
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 <    
127 >
128      /** Internal constructor */
129      TimeUnit(int index) {
130          this.index = index;
131      }
132 <    
132 >
133      // Handy constants for conversion methods
134      static final long C0 = 1L;
135      static final long C1 = C0 * 1000L;
# Line 138 | Line 138 | public enum TimeUnit {
138      static final long C4 = C3 * 60L;
139      static final long C5 = C4 * 60L;
140      static final long C6 = C5 * 24L;
141 <    
141 >
142      static final long MAX = Long.MAX_VALUE;
143 <    
143 >
144      /**
145       * Scale d by m, checking for overflow.
146       * This has a short name to make above code more readable.
# Line 150 | Line 150 | public enum TimeUnit {
150          if (d < -over) return Long.MIN_VALUE;
151          return d * m;
152      }
153 <    
153 >
154 >    // To maintain full signature compatibility with 1.5, and to improve the
155 >    // clarity of the generated javadoc (see 6287639: Abstract methods in
156 >    // enum classes should not be listed as abstract), method convert
157 >    // etc. are not declared abstract but otherwise act as abstract methods.
158 >
159      /**
160       * Convert the given time duration in the given unit to this
161       * unit.  Conversions from finer to coarser granularities
# Line 161 | Line 166 | public enum TimeUnit {
166       * <tt>Long.MIN_VALUE</tt> if negative or <tt>Long.MAX_VALUE</tt>
167       * if positive.
168       *
169 <     * @param duration the time duration in the given <tt>unit</tt>
170 <     * @param unit the unit of the <tt>duration</tt> argument
169 >     * <p>For example, to convert 10 minutes to milliseconds, use:
170 >     * <tt>TimeUnit.MILLISECONDS.convert(10L, TimeUnit.MINUTES)</tt>
171 >     *
172 >     * @param sourceDuration the time duration in the given <tt>sourceUnit</tt>
173 >     * @param sourceUnit the unit of the <tt>sourceDuration</tt> argument
174       * @return the converted duration in this unit,
175       * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
176       * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
177       */
178 <    public abstract long convert(long duration, TimeUnit unit);
179 <    
178 >    public long convert(long sourceDuration, TimeUnit sourceUnit) {
179 >        throw new AbstractMethodError();
180 >    }
181 >
182      /**
183       * Equivalent to <tt>NANOSECONDS.convert(duration, this)</tt>.
184       * @param duration the duration
# Line 177 | Line 187 | public enum TimeUnit {
187       * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
188       * @see #convert
189       */
190 <    public abstract long toNanos(long duration);
191 <    
190 >    public long toNanos(long duration) {
191 >        throw new AbstractMethodError();
192 >    }
193 >
194      /**
195       * Equivalent to <tt>MICROSECONDS.convert(duration, this)</tt>.
196       * @param duration the duration
# Line 187 | Line 199 | public enum TimeUnit {
199       * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
200       * @see #convert
201       */
202 <    public abstract long toMicros(long duration);
203 <    
202 >    public long toMicros(long duration) {
203 >        throw new AbstractMethodError();
204 >    }
205 >
206      /**
207       * Equivalent to <tt>MILLISECONDS.convert(duration, this)</tt>.
208       * @param duration the duration
# Line 197 | Line 211 | public enum TimeUnit {
211       * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
212       * @see #convert
213       */
214 <    public abstract long toMillis(long duration);
215 <    
214 >    public long toMillis(long duration) {
215 >        throw new AbstractMethodError();
216 >    }
217 >
218      /**
219       * Equivalent to <tt>SECONDS.convert(duration, this)</tt>.
220       * @param duration the duration
# Line 207 | Line 223 | public enum TimeUnit {
223       * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
224       * @see #convert
225       */
226 <    public abstract long toSeconds(long duration);
227 <    
226 >    public long toSeconds(long duration) {
227 >        throw new AbstractMethodError();
228 >    }
229 >
230      /**
231       * Equivalent to <tt>MINUTES.convert(duration, this)</tt>.
232       * @param duration the duration
# Line 216 | Line 234 | public enum TimeUnit {
234       * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
235       * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
236       * @see #convert
237 +     * @since 1.6
238       */
239 <    public abstract long toMinutes(long duration);
240 <    
239 >    public long toMinutes(long duration) {
240 >        throw new AbstractMethodError();
241 >    }
242 >
243      /**
244       * Equivalent to <tt>HOURS.convert(duration, this)</tt>.
245       * @param duration the duration
# Line 226 | Line 247 | public enum TimeUnit {
247       * or <tt>Long.MIN_VALUE</tt> if conversion would negatively
248       * overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow.
249       * @see #convert
250 +     * @since 1.6
251       */
252 <    public abstract long toHours(long duration);
253 <    
252 >    public long toHours(long duration) {
253 >        throw new AbstractMethodError();
254 >    }
255 >
256      /**
257       * Equivalent to <tt>DAYS.convert(duration, this)</tt>.
258       * @param duration the duration
259       * @return the converted duration
260       * @see #convert
261 +     * @since 1.6
262       */
263 <    public abstract long toDays(long duration);
264 <    
263 >    public long toDays(long duration) {
264 >        throw new AbstractMethodError();
265 >    }
266 >
267      /**
268       * Utility to compute the excess-nanosecond argument to wait,
269       * sleep, join.
# Line 245 | Line 272 | public enum TimeUnit {
272       * @return the number of nanoseconds
273       */
274      abstract int excessNanos(long d, long m);
275 <    
275 >
276      /**
277 <     * Perform a timed <tt>Object.wait</tt> using this time unit.
277 >     * Performs a timed <tt>Object.wait</tt> using this time unit.
278       * This is a convenience method that converts timeout arguments
279       * into the form required by the <tt>Object.wait</tt> method.
280       *
# Line 255 | Line 282 | public enum TimeUnit {
282       * method (see {@link BlockingQueue#poll BlockingQueue.poll})
283       * using:
284       *
285 <     * <pre>  public synchronized  Object poll(long timeout, TimeUnit unit) throws InterruptedException {
285 >     * <pre>  public synchronized Object poll(long timeout, TimeUnit unit) throws InterruptedException {
286       *    while (empty) {
287       *      unit.timedWait(this, timeout);
288       *      ...
# Line 263 | Line 290 | public enum TimeUnit {
290       *  }</pre>
291       *
292       * @param obj the object to wait on
293 <     * @param timeout the maximum time to wait.
293 >     * @param timeout the maximum time to wait. If less than
294 >     * or equal to zero, do not wait at all.
295       * @throws InterruptedException if interrupted while waiting.
296       * @see Object#wait(long, int)
297       */
# Line 275 | Line 303 | public enum TimeUnit {
303              obj.wait(ms, ns);
304          }
305      }
306 <    
306 >
307      /**
308 <     * Perform a timed <tt>Thread.join</tt> using this time unit.
308 >     * Performs a timed <tt>Thread.join</tt> using this time unit.
309       * This is a convenience method that converts time arguments into the
310       * form required by the <tt>Thread.join</tt> method.
311       * @param thread the thread to wait for
312 <     * @param timeout the maximum time to wait
312 >     * @param timeout the maximum time to wait. If less than
313 >     * or equal to zero, do not wait at all.
314       * @throws InterruptedException if interrupted while waiting.
315       * @see Thread#join(long, int)
316       */
# Line 293 | Line 322 | public enum TimeUnit {
322              thread.join(ms, ns);
323          }
324      }
325 <    
325 >
326      /**
327 <     * Perform a <tt>Thread.sleep</tt> using this unit.
327 >     * Performs a <tt>Thread.sleep</tt> using this unit.
328       * This is a convenience method that converts time arguments into the
329       * form required by the <tt>Thread.sleep</tt> method.
330 <     * @param timeout the minimum time to sleep
330 >     * @param timeout the minimum time to sleep. If less than
331 >     * or equal to zero, do not sleep at all.
332       * @throws InterruptedException if interrupted while sleeping.
333       * @see Thread#sleep
334       */
# Line 309 | Line 339 | public enum TimeUnit {
339              Thread.sleep(ms, ns);
340          }
341      }
342 <    
342 >
343   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines