Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 91210 invoked from network); 19 Mar 2004 23:21:29 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 19 Mar 2004 23:21:29 -0000 Received: (qmail 74470 invoked by uid 500); 19 Mar 2004 23:21:11 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 74449 invoked by uid 500); 19 Mar 2004 23:21:10 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 74414 invoked from network); 19 Mar 2004 23:21:09 -0000 Received: from unknown (HELO localhost.localdomain) (194.222.212.136) by daedalus.apache.org with SMTP; 19 Mar 2004 23:21:09 -0000 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.12.8/8.12.8) with ESMTP id i2JNLPsA002484 for ; Fri, 19 Mar 2004 23:21:26 GMT Received: (from yan@localhost) by localhost.localdomain (8.12.8/8.12.5/Submit) id i2JNLOcl002482; Fri, 19 Mar 2004 23:21:24 GMT X-Authentication-Warning: localhost.localdomain: yan set sender to yan@studylink.com using -f Subject: Re: [collections] collections size From: Janek Bogucki To: Jakarta Commons Users List In-Reply-To: <405B4974.7030005@apache.org> References: <405B4974.7030005@apache.org> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 (1.0.8-11) Date: 19 Mar 2004 23:21:24 +0000 Message-Id: <1079738484.1818.13.camel@localhost.localdomain> Mime-Version: 1.0 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N On Fri, 2004-03-19 at 19:26, matthew.hawthorne wrote: > I understand the underlying idea behind your suggestion, but I don't > quite get the use case. Why create conditional llogic to get the size > of an arbitrary list, when you'd then have to implement the same > conditional logic to get the items out of the list? > > If your goal is to treat all lists in a similar way, I think you'd be > better of doing something like: > > public static Collection toCollection(Object list) { > if(list instanceof Collection) > return list > else if (list instanceof Map) > return ((Map)list).entrySet() > else > return Arrays.asList(list) > } While I agree with the idea of using a Collection view of the object when you want to do Collection things on the object, there is a precedent for this sort of approach in o.a.c.collections in the form of CollectionUtils.get(Object, int). This could be used to get the items out of the 'list' although performance would suffer in some cases. Edited JavaDoc: Returns the index-th value in object. Supports: Map List Object Array Collection Iterator or Enumeration public static Object get(Object object, int index) -Janek --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org