View Javadoc

1   package cz.cuni.amis.utils;
2   
3   import java.util.concurrent.TimeUnit;
4   
5   public class TimeUnitToMillis {
6   	
7   	public static long toMillis(long timeout, TimeUnit unit) {
8   		switch(unit) {
9   		case DAYS: return timeout * 24 * 60 * 60 * 1000;
10  		case HOURS: return timeout * 60 * 60 * 1000;
11  		case MINUTES: return timeout * 60 * 1000;
12  		case SECONDS: return timeout * 1000;
13  		case MILLISECONDS: return timeout;
14  		case MICROSECONDS: return (long) Math.ceil(((double)timeout) / 1000);
15  		case NANOSECONDS: return (long) Math.ceil(((double)timeout) / 1000000);
16  		default: throw new IllegalArgumentException("unhandled time unit: " + unit);
17  		}
18  	}
19  
20  }