commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantin Kolinko <knst.koli...@gmail.com>
Subject Re: [lang] - Request to add a wrapper class for StringBuilder to handle the adding of suffixes and prefixes in output strings in certain cases.
Date Wed, 21 Dec 2011 06:08:52 GMT
2011/12/15 Darryl Smith <Darryl.Smith@vcontractor.co.za>:
> The intended purpose is to be able to format Strings with text intermixed
> with variable String values that conform to correct punctuation.
>
>
>
> i.e.
>
>
>
> Building up the correct display String depending on which variables are
> correctly entered.
>
> “Please specify the following: “ followed by a comma delimited listing of
> the required values [Name | Cell | Email Address] terminated by a fullstop.

Arrays.asList("Name", "Cell", "Email Address").toString(),

Or maybe use some configurable join() method for a collection?

>From quick look there are similar things in o.a.commons.lang3.builder:
ToStringBuilder, ToStringStyle, StandardToStringStyle.

ToStringBuilder says you should not create it without an object, but
you can use ToStringStyle.append(Object[]) directly on a StringBuffer.


>
>
>
> EnhancedBuilder allows us to easily specify the logic to build such a
> String.
>
>
>
>                 EnhancedBuilder eb = new EnhancedBuilder();
>
>                                 eb.setFirstSuffix(": \n")
>
>                                 .setSuffix(",\n")
>
>                                 .setPrefix(" -")
>
>                                 .setLastSuffix(".")
>
>                                 .setSkipFirstPrefix(true);
>
>                                 System.out.println(eb.append("Please
specify
> the following
> arguments").append("Username").append("Cell").append("Email").toString());
>

Best regards,
Konstantin Kolinko

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


Mime
View raw message