ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kev Jackson <kevin.jack...@it.fts-vn.com>
Subject Adding a methof to StringUtils
Date Wed, 19 Apr 2006 09:11:39 GMT
Hi,

As I've been hacking away today, I've been swapping a load of "" + "" + 
"" style code over to use StringBuffers.  I thought that perhaps there's 
a potential use of a static method in StringUtils to construct these 
strings from an array

StringUtils.messageAppender
  /**
     * Creates log messages using a StringBuffer
     * Example:
     * <code>
     * String[] args = {"1", "2", "3"}
     * log(StringUtils.messageAppender(args), Project.MSG_VERBOSE);
     * </code>
     * @param args the message fragments
     * @return the message
     * @since ant 1.7
     */
    public static String messageAppender(final Object[] args) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < args.length; i++) {
            sb.append(args[i]);
        }
        return sb.toString();
    }

In use Delete.java

if (dirCount > 0) {
  String[] args = {"Deleted ", ""+dirCount, " director", (dirCount == 1 
? "y" : "ies"), " from ", d.getAbsolutePath()};
  log(StringUtils.messageAppender(args), quiet ? Project.MSG_VERBOSE : 
verbosity);
}

Before I go ahead and commit any of this, what do people think (thumbs 
up/down on the idea of doing something about the string concatenation in 
logging, thumbs up/down to this static methof of StringUtils)?

Thanks
Kev

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message