Here you can find the source of toMillis(final long interval, final TimeUnit tu)
Parameter | Description |
---|---|
interval | a parameter |
tu | a parameter |
private static long toMillis(final long interval, final TimeUnit tu)
//package com.java2s; //License from project: Open Source License import java.util.concurrent.TimeUnit; public class Main { /**//from w ww . ja v a 2s . c o m * Convert time interval to milliseconds. * * @param interval * @param tu * * @return Interval in milliseconds */ private static long toMillis(final long interval, final TimeUnit tu) { if (interval < 0L) { throw new IllegalArgumentException("SleepUtilities.toMillis " + "Negative interval"); } long millis = 0L; switch (tu) { // case DAYS: Wait for 1.6 // case HOURS: // case MINUTES: case SECONDS: millis = tu.toMillis(interval); break; case MILLISECONDS: millis = interval; break; case MICROSECONDS: millis = (interval + 500L) / 1000L; break; case NANOSECONDS: millis = (interval + 500000L) / 1000000L; break; default: throw new IllegalArgumentException("SleepUtilities.toMillis " + "Unknown TimeUnit: " + tu); } if ((interval > 0L) && (millis == 0L)) { // Don't underflow millis = 1L; } return millis; } }