Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 5225 invoked from network); 11 Apr 2011 16:20:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 11 Apr 2011 16:20:09 -0000 Received: (qmail 18297 invoked by uid 500); 11 Apr 2011 16:20:09 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 18211 invoked by uid 500); 11 Apr 2011 16:20:09 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 18203 invoked by uid 99); 11 Apr 2011 16:20:09 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Apr 2011 16:20:09 +0000 X-ASF-Spam-Status: No, hits=0.7 required=5.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [173.236.76.174] (HELO serv01.siteground309.com) (173.236.76.174) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Apr 2011 16:20:04 +0000 Received: from [96.247.3.234] (port=1234 helo=[192.168.1.2]) by serv01.siteground309.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1Q9Jq0-0005Nh-M1 for dev@commons.apache.org; Mon, 11 Apr 2011 11:19:40 -0500 Message-ID: <4DA32A1D.4020201@sandglass-software.com> Date: Mon, 11 Apr 2011 09:19:41 -0700 From: Adrian Crum Organization: Sandglass Software User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Lightning/1.0b2 Thunderbird/3.1.9 MIME-Version: 1.0 To: Commons Developers List Subject: Re: [Lang] Pair toString References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - serv01.siteground309.com X-AntiAbuse: Original Domain - commons.apache.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - sandglass-software.com Delegating is trivial in Eclipse - it will write the code for you. As for delegating versus "rolling your own" - delegating leverages the code maturity and unit tests of the delegate. -Adrian On 4/11/2011 9:16 AM, Gary Gregory wrote: > On Mon, Apr 11, 2011 at 10:12 AM, Matt Benson wrote: > >> On Mon, Apr 11, 2011 at 9:00 AM, Gary Gregory >> wrote: >>> Hi All: >>> >>> I added a test to verify the default Pair toString behavior. >>> >>> For me to replace our custom Pair class at work, I need to customize the >> to >>> String behavior. >>> >>> Subclassing ImmutablePair and MutablePair to override toString smells >> nasty. >>> What about adding a formatString ivar which will be used with the >>> String.format API? >>> >> If we must do anything like this it would seem that by the laws of dog >> food we would accept Builder. That said, I'm finding it >> difficult to see a way to do this that doesn't seem equally offensive >> as the subclassing approach you've rejected. For a different >> subclassing approach you could implement toString() at a single >> point--a direct Pair subclass--and then reimplement mutable and >> immutable versions if you really needed both. Or if your toString() >> needs are nonspecific enough, maybe we can just use them--I'm not >> unduly attached to the current format. >> > Brrrr. struggling with this one. > > The subclassing approach seems messy. Delegating is not much better. Pair is > simple enough that (gasp) duplicating maybe less smelly, but that is what I > have now, my own Pair kind of class with the additional feature that > toString is customizable, sometimes I use ": ", "=", or " => " as the > separator (no class name, no parens). > > When I think about a Map or List string dump in the current format, it will > look noisy. This is why allowing a pluggable toString makes sense. > > Again: What about adding a formatString ivar which will be used with the > String.format API? Or something that will let me use Pair as is and plugin a > formatter? I fear subclassing or delegation might be the required hack for > me :( But why bother then, I'd be better off not using Pair :( for my use > cases that need to be toString'd. > > Thank you, > Gary > > >> Matt >> >>> -- >>> Thank you, >>> Gary >>> >>> http://garygregory.wordpress.com/ >>> http://garygregory.com/ >>> http://people.apache.org/~ggregory/ >>> http://twitter.com/GaryGregory >>> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org >> For additional commands, e-mail: dev-help@commons.apache.org >> >> > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org