151 |
|
return d * m; |
152 |
|
} |
153 |
|
|
154 |
+ |
// To maintain full signature compatibility with 1.5, method |
155 |
+ |
// convert etc are not declared abstract but otherwise act as |
156 |
+ |
// abstract methods. |
157 |
+ |
|
158 |
|
/** |
159 |
|
* Convert the given time duration in the given unit to this |
160 |
|
* unit. Conversions from finer to coarser granularities |
164 |
|
* with arguments that would numerically overflow saturate to |
165 |
|
* <tt>Long.MIN_VALUE</tt> if negative or <tt>Long.MAX_VALUE</tt> |
166 |
|
* if positive. |
167 |
+ |
* <p> |
168 |
+ |
* For example, to convert 10 minutes to milliseconds, use: |
169 |
+ |
* <tt>TimeUnit.MILLISECONDS.convert(10L, TimeUnit.MINUTES)</tt> |
170 |
|
* |
171 |
< |
* @param duration the time duration in the given <tt>unit</tt> |
172 |
< |
* @param unit the unit of the <tt>duration</tt> argument |
171 |
> |
* @param sourceDuration the time duration in the given <tt>unit</tt> |
172 |
> |
* @param sourceUnit the unit of the <tt>sourceDuration</tt> argument |
173 |
|
* @return the converted duration in this unit, |
174 |
|
* or <tt>Long.MIN_VALUE</tt> if conversion would negatively |
175 |
|
* overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow. |
176 |
|
*/ |
177 |
< |
public abstract long convert(long duration, TimeUnit unit); |
177 |
> |
public long convert(long sourceDuration, TimeUnit sourceUnit) { |
178 |
> |
throw new AbstractMethodError(); |
179 |
> |
} |
180 |
|
|
181 |
|
/** |
182 |
|
* Equivalent to <tt>NANOSECONDS.convert(duration, this)</tt>. |
186 |
|
* overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow. |
187 |
|
* @see #convert |
188 |
|
*/ |
189 |
< |
public abstract long toNanos(long duration); |
189 |
> |
public long toNanos(long duration) { |
190 |
> |
throw new AbstractMethodError(); |
191 |
> |
} |
192 |
|
|
193 |
|
/** |
194 |
|
* Equivalent to <tt>MICROSECONDS.convert(duration, this)</tt>. |
198 |
|
* overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow. |
199 |
|
* @see #convert |
200 |
|
*/ |
201 |
< |
public abstract long toMicros(long duration); |
201 |
> |
public long toMicros(long duration) { |
202 |
> |
throw new AbstractMethodError(); |
203 |
> |
} |
204 |
|
|
205 |
|
/** |
206 |
|
* Equivalent to <tt>MILLISECONDS.convert(duration, this)</tt>. |
210 |
|
* overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow. |
211 |
|
* @see #convert |
212 |
|
*/ |
213 |
< |
public abstract long toMillis(long duration); |
213 |
> |
public long toMillis(long duration) { |
214 |
> |
throw new AbstractMethodError(); |
215 |
> |
} |
216 |
|
|
217 |
|
/** |
218 |
|
* Equivalent to <tt>SECONDS.convert(duration, this)</tt>. |
222 |
|
* overflow, or <tt>Long.MAX_VALUE</tt> if it would positively overflow. |
223 |
|
* @see #convert |
224 |
|
*/ |
225 |
< |
public abstract long toSeconds(long duration); |
225 |
> |
public long toSeconds(long duration) { |
226 |
> |
throw new AbstractMethodError(); |
227 |
> |
} |
228 |
|
|
229 |
|
/** |
230 |
|
* Equivalent to <tt>MINUTES.convert(duration, this)</tt>. |
235 |
|
* @see #convert |
236 |
|
* @since 1.6 |
237 |
|
*/ |
238 |
< |
public abstract long toMinutes(long duration); |
238 |
> |
public long toMinutes(long duration) { |
239 |
> |
throw new AbstractMethodError(); |
240 |
> |
} |
241 |
|
|
242 |
|
/** |
243 |
|
* Equivalent to <tt>HOURS.convert(duration, this)</tt>. |
248 |
|
* @see #convert |
249 |
|
* @since 1.6 |
250 |
|
*/ |
251 |
< |
public abstract long toHours(long duration); |
251 |
> |
public long toHours(long duration) { |
252 |
> |
throw new AbstractMethodError(); |
253 |
> |
} |
254 |
|
|
255 |
|
/** |
256 |
|
* Equivalent to <tt>DAYS.convert(duration, this)</tt>. |
259 |
|
* @see #convert |
260 |
|
* @since 1.6 |
261 |
|
*/ |
262 |
< |
public abstract long toDays(long duration); |
262 |
> |
public long toDays(long duration) { |
263 |
> |
throw new AbstractMethodError(); |
264 |
> |
} |
265 |
|
|
266 |
|
/** |
267 |
|
* Utility to compute the excess-nanosecond argument to wait, |