SignalUtil { static String formatMessage(String fmt, Object[] args) { MessageFormat formatter = new MessageFormat(fmt); Format[] formats = formatter.getFormatsByArgumentIndex(); StringBuffer msg = new StringBuffer(); formatter.format(args, msg, null); if (args.length > formats.length) { for (int i = formats.length; i < args.length; i++) { msg.append(i == formats.length ? ": " : ", ") .append(args[i].toString()); } } return msg.toString(); }  static void lock(Lock lock, String callerClass, String callerMethod, Object... args); static Future<T> take(CompletionService<T> cs, String callerClass, String callerMethod, Object... args); static void await(CountDownLatch latch, String callerClass, String callerMethod, Object... args); static T get(Future<T> future, String callerClass, String callerMethod, Object... args); static void aquire(Semaphore sem, String callerClass, String callerMethod, Object... args); static final long SIGNAL_LOG_INTERVAL_SECONDS; static final long SIGNAL_LOG_QUIESCE_TIMEOUT_MINUTES; }
@Test public void testFormatMessage() { String result = SignalUtil.formatMessage("{0}, {1}", new Object[]{"1", "2"}); Assert.assertEquals("1, 2", result); result = SignalUtil.formatMessage("{0}, {1}", new Object[]{"1", "2", "3"}); Assert.assertEquals("1, 2: 3", result); result = SignalUtil.formatMessage("{0}, {1}", new Object[]{"1", "2", "3", "4"}); Assert.assertEquals("1, 2: 3, 4", result); }