Use varargs instead of having a few different overloaded versions of the

same methods. But then I went ahead and added String varargs versions,
otherwise any old code that passes a String[] would have to cast to
Object[] to avoid compiler warnings. (Because the args don't quite match,
the compiler is unsure whether you want your String[] to be the first Object
arg or whether the whole String[] should be cast to the Object[].)


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1901 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
ray
2006-09-11 22:15:46 +00:00
parent 1b16a084bb
commit bb500f938e
+24 -63
View File
@@ -38,7 +38,7 @@ public class MessageUtil
* subsequently be decomposed and translated without prior knowledge
* of how many arguments were provided.
*/
public static String compose (String key, Object[] args)
public static String compose (String key, Object... args)
{
StringBuilder buf = new StringBuilder();
buf.append(key);
@@ -64,6 +64,15 @@ public class MessageUtil
return buf.toString();
}
/**
* Compose a message with String args. This is just a convenience so
* callers do not have to cast their String[] to an Object[].
*/
public static String compose (String key, String... args)
{
return compose(key, (Object[]) args);
}
/**
* Used to escape single quotes so that they are not interpreted by
* {@link MessageFormat}. As we assume all single quotes are to be
@@ -105,79 +114,31 @@ public class MessageUtil
return buf.toString();
}
/**
* A convenience method for calling {@link #compose(String,Object[])}
* with a single argument.
*/
public static String compose (String key, Object arg)
{
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) });
}
/**
* A convenience method for calling {@link #compose(String,Object[])}
* 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)
{
int acount = args.length;
String[] targs = new String[acount];
for (int ii = 0; ii < acount; ii++) {
targs[ii] = taint(args[ii]);
}
return compose(key, targs);
return compose(key, (Object[]) targs);
}
/**
* A convenience method for calling {@link #compose(String,String[])}
* with an array of argument that will be automatically tainted.
*/
public static String tcompose (String key, String... args)
{
for (int ii = 0, nn = args.length; ii < nn; ii++) {
args[ii] = taint(args[ii]);
}
return compose(key, args);
}
/**