Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 92467 invoked from network); 7 Mar 2010 02:07:13 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 7 Mar 2010 02:07:13 -0000 Received: (qmail 18782 invoked by uid 500); 7 Mar 2010 02:06:54 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 18481 invoked by uid 500); 7 Mar 2010 02:06:54 -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 18472 invoked by uid 99); 7 Mar 2010 02:06:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 07 Mar 2010 02:06:54 +0000 X-ASF-Spam-Status: No, hits=-2.3 required=10.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of GGregory@seagullsoftware.com designates 216.82.249.243 as permitted sender) Received: from [216.82.249.243] (HELO mail73.messagelabs.com) (216.82.249.243) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 07 Mar 2010 02:06:49 +0000 X-VirusChecked: Checked X-Env-Sender: GGregory@seagullsoftware.com X-Msg-Ref: server-10.tower-73.messagelabs.com!1267927587!40602682!1 X-StarScan-Version: 6.2.4; banners=-,-,- X-Originating-IP: [137.134.240.188] Received: (qmail 16979 invoked from network); 7 Mar 2010 02:06:28 -0000 Received: from unknown (HELO postal.rocketsoftware.com) (137.134.240.188) by server-10.tower-73.messagelabs.com with AES128-SHA encrypted SMTP; 7 Mar 2010 02:06:28 -0000 Received: from NWT-S-MBX1.rocketsoftware.com ([fe80::34fc:6d7f:6837:62b]) by nwt-s-cas1.rocketsoftware.com ([::1]) with mapi; Sat, 6 Mar 2010 21:06:16 -0500 From: Gary Gregory To: Commons Developers List Subject: RE: [lang] LANG-510 Thread-Topic: [lang] LANG-510 Thread-Index: AQHKvEbi8ulFHl8c4EqAJviJgphQzJHltEJw Date: Sun, 7 Mar 2010 02:05:07 +0000 Message-ID: <02AA127CD8DCDE48BC7D2DFB6C87083A0A8256@nwt-s-mbx1.rocketsoftware.com> References: <31cc37361003050132m260425d2sf41a6441539e8653@mail.gmail.com> In-Reply-To: <31cc37361003050132m260425d2sf41a6441539e8653@mail.gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Here is another issue that I find confusing at first glance with Generics. = I redefined defaultIfEmpty in my sandbox as follows: public static T defaultIfEmpty(T str, T defaul= tStr) { return StringUtils.isEmpty(str) ? defaultStr : str; } This is simple enough but I was surprised that this compiled: assertEquals("abc", StringUtils.defaultIfEmpty(new StringBuilder("abc"), "N= ULL")); I thought that all T's should match, but they do not, the compiler works it= s type inference magic to match up the call site to the method, such that b= oth arguments are of type CharSequence. The API as coded can return both a = String and a StringBuilder depending on the value of the input. That's the = confusing part. The question is: Is it worth this potential confusion to allow any CharSequ= ence to be used? In this case, the "" version is the same as: public static CharSequence defaultIfEmpty(CharSequence str, CharSequenc= e defaultStr) { return StringUtils.isEmpty(str) ? defaultStr : str; } Are there cases where the "" version is needed? Gary=20 > -----Original Message----- > From: Henri Yandell [mailto:flamefew@gmail.com] > Sent: Friday, March 05, 2010 01:33 > To: Commons Developers List > Subject: [lang] LANG-510 >=20 > Thinking further on moving StringUtils to CharSequence, I'd like to > take the String left(String, int) method as an example. It depends on > substring(int, int), so is entirely possibly to move over to > subSequence(int, int). >=20 > Hypothetical new method: >=20 > CharSequence left(CharSequence, int) >=20 > The downside here is that users currently storing this in a String are > going to have to cast. Generics to the rescue. >=20 > T left(T, int) >=20 > This hits two problems: >=20 > 1) EMPTY is returned when the int is less than 0; EMPTY is a String and n= ot T. > 2) subSequence returns CharSequence and not T. >=20 > I could add a wrapper method to make Strings nicer: >=20 > public static String left(String str, int len) { > if (str =3D=3D null) { > return null; > } > return left( (CharSequence) str, len).toString(); > } >=20 > But that doesn't help the StringBuffer/StrBuilder/StringBuilder user; > they still get a sucky API. >=20 > Am I missing anything obvious here, or should I give up the ghost on > trying to take these methods to CharSequence APIs? >=20 > Hen >=20 > --------------------------------------------------------------------- > 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