Java Code Examples for java.util.concurrent.TimeUnit.name()

The following are Jave code examples for showing how to use name() of the java.util.concurrent.TimeUnit class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: n4js   File: SimpleTimeFormat.java   View Source Code Vote up 6 votes
private static String abbreviate(TimeUnit unit) {
	switch (unit) {
	case NANOSECONDS:
		return "ns";
	case MICROSECONDS:
		return "μs";
	case MILLISECONDS:
		return "ms";
	case SECONDS:
		return "s";
	case MINUTES:
		return "min";
	case HOURS:
		return "h";
	case DAYS:
		return "d";
	default:
		throw new RuntimeException("Unsupported unit " + unit.name());
	}
}
 
Example 2
Project: ditb   File: RateLimiter.java   View Source Code Vote up 6 votes
/**
 * Set the RateLimiter max available resources and refill period.
 * @param limit The max value available resource units can be refilled to.
 * @param timeUnit Timeunit factor for translating to ms.
 */
public synchronized void set(final long limit, final TimeUnit timeUnit) {
  switch (timeUnit) {
  case MILLISECONDS:
    tunit = 1;
    break;
  case SECONDS:
    tunit = 1000;
    break;
  case MINUTES:
    tunit = 60 * 1000;
    break;
  case HOURS:
    tunit = 60 * 60 * 1000;
    break;
  case DAYS:
    tunit = 24 * 60 * 60 * 1000;
    break;
  default:
    throw new RuntimeException("Unsupported " + timeUnit.name() + " TimeUnit.");
  }
  this.limit = limit;
  this.avail = limit;
}