class TimeoutHelper {

  static int toMillis(long timeout, TimeUnit unit) {
    if (timeout == 0) {
      return 0;
    }
    int millisecs = (int) unit.toMillis(timeout);
    if ((millisecs == 0)) {
      return 1;
    }
    if (millisecs < 0) {
      return Integer.MAX_VALUE;
    }
    return millisecs;
  }

}