Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 6930 invoked from network); 18 Oct 2009 20:33:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Oct 2009 20:33:22 -0000 Received: (qmail 67311 invoked by uid 500); 18 Oct 2009 20:33:21 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 67184 invoked by uid 500); 18 Oct 2009 20:33:21 -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 67174 invoked by uid 99); 18 Oct 2009 20:33:21 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Oct 2009 20:33:21 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00 X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of flamefew@gmail.com designates 209.85.221.183 as permitted sender) Received: from [209.85.221.183] (HELO mail-qy0-f183.google.com) (209.85.221.183) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Oct 2009 20:33:19 +0000 Received: by qyk13 with SMTP id 13so778894qyk.27 for ; Sun, 18 Oct 2009 13:32:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=5lgAv017R8aWNXRbnkTMLStpY3IKA4lIPiWiYN3cOQo=; b=abbMGvhaDn2woNy+hK91E3ngN6RwWvl65afnRzRE7wF+M2M99Z0W8qRWnPmS3IYKLW Xpr9aUJZSieCVztlQMoRlePbF4iwDpqGCcs2a/jDxLukEDq9Di6oEle2TUl+FgsPu16D G8xoSJdV/C0t5nNJUhV3G6zOgsclnvBpvHVUc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=fcROsP+rAb8z9UvLRdbUTZjKZ9Mie5EKz4V8qkbcGVBJuC/eQJja86fYawi6GQv19o mXI+Ly70M891aZQCxXjzMI5jCVc2Qt0enoy3NaEYvnvvhf4UL5JNDwiA2BXB4Q8opopQ CsXVwaMcx1lidj5ZBLioII1pmf9jCseeMD56g= MIME-Version: 1.0 Received: by 10.229.92.211 with SMTP id s19mr587463qcm.46.1255897978185; Sun, 18 Oct 2009 13:32:58 -0700 (PDT) In-Reply-To: <31cc37360910181321r6d4c9d2ar33fecacaaf7f4e86@mail.gmail.com> References: <20091018072600.884C62388904@eris.apache.org> <25aac9fc0910180428s6e670f60x14f4a24e30391533@mail.gmail.com> <31cc37360910181249n4059e101ifa22594003c2b3a4@mail.gmail.com> <31cc37360910181304x2bf429a8hb445af2aec961e4f@mail.gmail.com> <31cc37360910181321r6d4c9d2ar33fecacaaf7f4e86@mail.gmail.com> Date: Sun, 18 Oct 2009 13:32:58 -0700 Message-ID: <31cc37360910181332p37f431een5b656279240b784e@mail.gmail.com> Subject: Re: svn commit: r826370 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/text/translate/UnicodeUnescaper.java test/org/apache/commons/lang/text/translate/UnicodeUnescaperTest.java From: Henri Yandell To: Commons Developers List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Walked away. Pondered. Came back. s/Param/Option on the below. A Parameter is a user supplied value; an Option is a user supplied choice. I'm talking about the latter. On Sun, Oct 18, 2009 at 1:21 PM, Henri Yandell wrote: > Which ended up looking like: > > =A0 =A0public static enum PARAM { escapePlus }; > > =A0 =A0private EnumSet params; > > =A0 =A0public UnicodeUnescaper(PARAM... params) { > =A0 =A0 =A0 =A0if(params.length > 0) { > =A0 =A0 =A0 =A0 =A0 =A0this.params =3D EnumSet.copyOf(Arrays.asList(param= s)); > =A0 =A0 =A0 =A0} > =A0 =A0} > > =A0 =A0public boolean isSet(PARAM p) { > =A0 =A0 =A0 =A0return (params =3D=3D null) ? false : params.contains(p); > =A0 =A0} > > Opinions very, very much desired. Tempted to extend EnumSet to > simplify a little of the null protection etc. ParamSet

and > protecting against empty arrays and null params. Maybe looking like: > > =A0 =A0public static enum PARAM { escapePlus }; > > =A0 =A0private ParamSet params =3D new ParamSet(); > > =A0 =A0public UnicodeUnescaper(PARAM... parameters) { > =A0 =A0 =A0 =A0 =A0 =A0this.params.add(parameters); > =A0 =A0} > > =A0 =A0public boolean isSet(PARAM p) { > =A0 =A0 =A0 =A0return params.contains(p); > =A0 =A0} > > To a user this looks like: > > =A0 =A0 =A0 =A0uu =3D new UnicodeUnescaper(UnicodeUnescaper.PARAM.escapeP= lus); > > with the advantage for us being that we can add options to a class > without API problems. > > Hen > > On Sun, Oct 18, 2009 at 1:04 PM, Henri Yandell wrote= : >> On Sun, Oct 18, 2009 at 12:49 PM, Henri Yandell wro= te: >> >>> Fair enough on the threading though. I'll move to constructor as I >>> can't think of anything better. >> >> Rambling out loud. >> >> Better (for API scaling): >> >> enum FooParam { various PARAM options} >> >> constructor: =A0Foo(FooParam... fp) { =A0this.options =3D >> EnumSet.copyOf(Collections.asList(fp)); } >> >> That would work quite nicely to replace all the painful boolean >> constructor parameters. That leaves us then needing a way to scale >> this for a single initial parameter: >> >> With a recompile, you could have an Object called PARAM and replace it >> with a FooParam.PARAM later on of type enum:FooParam, but I'm assuming >> that would be an error at runtime. So for runtime API scaling you >> would need to set the enum up from the start. Ideally it wants to be >> in the same class/file though, which means an inner class so you can >> make it public. So: >> >> new Foo(Foo.PARAM.escapingPlus) >> >> You could also have a single argument constructor to start with, but >> again runtime is probably unhappy when you switch (or overload - >> compile error?) with varargs. >> >> Is it a worthwhile pattern to avoid rampant booleanism in a minority >> of classes? Not convinced. >> >> Hen >> > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org