From 5a8b9e14dbf4574c8ff005fa7f83c38a58a31910 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Mon, 11 Sep 2006 22:16:01 +0000 Subject: [PATCH] Lovely varargs, like MessageUtil in samskivert. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4368 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/util/MessageBundle.java | 140 ++++-------------- 1 file changed, 27 insertions(+), 113 deletions(-) diff --git a/src/java/com/threerings/util/MessageBundle.java b/src/java/com/threerings/util/MessageBundle.java index 09e8b1d0c..d65e29e38 100644 --- a/src/java/com/threerings/util/MessageBundle.java +++ b/src/java/com/threerings/util/MessageBundle.java @@ -56,69 +56,18 @@ public class MessageBundle * Composes a message key with an array of arguments. The message can * subsequently be translated in a single call using {@link #xlate}. */ - public static String compose (String key, Object[] args) + public static String compose (String key, Object... args) { return MessageUtil.compose(key, args); } /** - * A convenience method for calling {@link #compose(String,Object[])} - * with a single argument. + * Composes a message key with an array of arguments. The message can + * subsequently be translated in a single call using {@link #xlate}. */ - public static String compose (String key, Object arg) + public static String compose (String key, String... args) { - return compose(key, new Object[] { arg }); - } - - /** - * A convenience method for calling {@link #compose(String,Object[])} - * with two arguments. - */ - public static String compose (String key, Object arg1, Object arg2) - { - return compose(key, new Object[] { arg1, arg2 }); - } - - /** - * A convenience method for calling {@link #compose(String,Object[])} - * with three arguments. - */ - public static String compose ( - String key, Object arg1, Object arg2, Object arg3) - { - return compose(key, new Object[] { arg1, arg2, arg3 }); - } - - /** - * A convenience method for calling {@link #compose(String,Object[])} - * with a single argument that will be automatically tainted (see - * {@link #taint}). - */ - public static String tcompose (String key, Object arg) - { - return compose(key, new Object[] { taint(arg) }); - } - - /** - * A convenience method for calling {@link #compose(String,Object[])} - * with two arguments that will be automatically tainted (see {@link - * #taint}). - */ - public static String tcompose (String key, Object arg1, Object arg2) - { - return compose(key, new Object[] { taint(arg1), taint(arg2) }); - } - - /** - * A convenience method for calling {@link #compose(String,Object[])} - * with three arguments that will be automatically tainted (see {@link - * #taint}). - */ - public static String tcompose ( - String key, Object arg1, Object arg2, Object arg3) - { - return compose(key, new Object[] { - taint(arg1), taint(arg2), taint(arg3) }); + return MessageUtil.compose(key, args); } /** @@ -126,7 +75,17 @@ public class MessageBundle * with an array of arguments that will be automatically tainted (see * {@link #taint}). */ - public static String tcompose (String key, Object[] args) + public static String tcompose (String key, Object... args) + { + return MessageUtil.tcompose(key, args); + } + + /** + * A convenience method for calling {@link #compose(String,String[])} + * with an array of arguments that will be automatically tainted (see + * {@link #taint}). + */ + public static String tcompose (String key, String... args) { return MessageUtil.tcompose(key, args); } @@ -271,60 +230,6 @@ public class MessageBundle return null; } - /** - * Obtains the translation for the specified message key. The - * specified argument is substituted into the translated string. - * - *

See {@link #get(String,Object[])} for notes on handling - * plurals. - * - *

See {@link MessageFormat} for more information on how the - * substitution is performed. If a translation message does not exist - * for the specified key, an error is logged and the key itself (plus - * the argument) is returned so that the caller need not worry about - * handling a null response. - */ - public String get (String key, Object arg1) - { - return get(key, new Object[] { arg1 }); - } - - /** - * Obtains the translation for the specified message key. The - * specified arguments are substituted into the translated string. - * - *

See {@link #get(String,Object[])} for notes on handling - * plurals. - * - *

See {@link MessageFormat} for more information on how the - * substitution is performed. If a translation message does not exist - * for the specified key, an error is logged and the key itself (plus - * the arguments) is returned so that the caller need not worry about - * handling a null response. - */ - public String get (String key, Object arg1, Object arg2) - { - return get(key, new Object[] { arg1, arg2 }); - } - - /** - * Obtains the translation for the specified message key. The - * specified arguments are substituted into the translated string. - * - *

See {@link #get(String,Object[])} for notes on handling - * plurals. - * - *

See {@link MessageFormat} for more information on how the - * substitution is performed. If a translation message does not exist - * for the specified key, an error is logged and the key itself (plus - * the arguments) is returned so that the caller need not worry about - * handling a null response. - */ - public String get (String key, Object arg1, Object arg2, Object arg3) - { - return get(key, new Object[] { arg1, arg2, arg3 }); - } - /** * Obtains the translation for the specified message key. The * specified arguments are substituted into the translated string. @@ -356,7 +261,7 @@ public class MessageBundle * the arguments) is returned so that the caller need not worry about * handling a null response. */ - public String get (String key, Object[] args) + public String get (String key, Object... args) { // if this is a qualified key, we need to pass the buck to the // appropriate message bundle @@ -400,6 +305,15 @@ public class MessageBundle : (key + StringUtil.toString(args)); } + /** + * Obtains the translation for the specified message key. The + * specified arguments are substituted into the translated string. + */ + public String get (String key, String... args) + { + return get(key, (Object[]) args); + } + /** * A helper function for {@link #get(String,Object[])} that allows us * to automatically perform plurality processing if our first argument @@ -460,7 +374,7 @@ public class MessageBundle args[i] = xlate(MessageUtil.unescape(args[i])); } } - return get(key, args); + return get(key, (Object[]) args); } }