+1 very well thought, Gary! even if StrBuilder would look like java.util.Formatter, I think that this is a nice addition.
best, -Simo http://people.apache.org/~simonetripodi/ http://simonetripodi.livejournal.com/ http://twitter.com/simonetripodi http://www.99soft.org/ On Thu, Sep 20, 2012 at 11:12 PM, Gary Gregory <garydgreg...@gmail.com> wrote: > I just wrote this up for a different project and it seems like a nice add > for StrBuilder: > > @Test > public void testAppendFormatted_Object() { > StrBuilder sb; > > sb = new StrBuilder(); > sb.append("Hi", "Alice"); > assertEquals("Hi", sb.toString()); > > sb = new StrBuilder(); > sb.append("Hi %s", "Alice"); > assertEquals("Hi Alice", sb.toString()); > > sb = new StrBuilder(); > sb.append("Hi %s %,d", "Alice", 5000); > assertEquals("Hi Alice 5,000", sb.toString()); > } > > /** > * Appends an formatted string to this string builder. > * Appending null will call {@link #appendNull()}. > * > * @param format the format string, see {@link String#format(String, > Object...)} > * @param objs the objects to use in the format string > * @return this, to enable chaining > */ > public StrBuilder append(String format, Object... objs) { > if (objs == null) { > return appendNull(); > } > return append(String.format(format, objs)); > } > > Thoughts? > > > -- > E-Mail: garydgreg...@gmail.com | ggreg...@apache.org > JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0 > Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK > Blog: http://garygregory.wordpress.com > Home: http://garygregory.com/ > Tweet! http://twitter.com/GaryGregory --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org