Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 75420 invoked from network); 23 Oct 2002 17:43:41 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 23 Oct 2002 17:43:41 -0000 Received: (qmail 18823 invoked by uid 97); 23 Oct 2002 17:44:29 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 18762 invoked by uid 97); 23 Oct 2002 17:44:28 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 18748 invoked by uid 98); 23 Oct 2002 17:44:28 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Message-ID: <00ed01c27abb$c27de9e0$715922d9@oemcomputer> From: "Stephen Colebourne" To: "Jakarta Commons Developers List" References: <20021023033523.5020.qmail@icarus.apache.org> <3DB621D0.4070800@apache.org> Subject: Re: cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections ClassMap.java Date: Wed, 23 Oct 2002 18:43:55 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Much of the code for getting all the superclasses and superinterfaces of a class is coded in the upcoming [lang] reflection code. Maybe the next collections release should depend on [lang]? Stephen ----- Original Message ----- From: "Michael A. Smith" To: "Jakarta Commons Developers List" Sent: Wednesday, October 23, 2002 5:13 AM Subject: Re: cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections ClassMap.java > bayard@apache.org wrote: > > bayard 2002/10/22 20:35:23 > > > > Added: collections/src/test/org/apache/commons/collections > > TestClassMap.java > > collections/src/java/org/apache/commons/collections > > ClassMap.java > > Log: > > Uses inheritence in the get() value lookup to decide which value to return. > > I find this very useful when implementing registries of which Class acts > > upon which value. So in a ConvertUtils class, a ClassMap would handle the > > many Converters, deciding which Converter to use on which value. > > 1.1 jakarta-commons/collections/src/java/org/apache/commons/collections/ClassMap .java > > > > Index: ClassMap.java > > [snip] > > ClassMap looks like it needs more documentation describing the selection > process if more than one superclass/interface matches the requested > class passed to get. More specifically... > > > public Object get(Object key) { > > if(key == null) { > > return null; > > } > > Class clss = null; > > > > if(key instanceof Class) { > > clss = (Class)key; > > } else { > > clss = key.getClass(); > > } > > > > Object obj = super.get(clss); > > > > if(obj == null) { > > > > // if this is null, let's go up the inheritence tree > > obj = getInterfaces(clss); > > ... should document that interfaces have a higher priority for matching > than superclasses. > > > if(obj == null) { > > obj = getSuperclass(clss); > > } > > } > > > > return obj; > > } > > > > private Object getInterfaces(Class clss) { > > if(clss == null) { > > return null; > > } > > Object obj = null; > > Class[] interfaces = clss.getInterfaces(); > > for(int i=0; i > obj = (Object)super.get(interfaces[i]); > > ... and that the interfaces are checked in the order in which they are > declared in the "implements" clause of the class. > > > if(obj != null) { > > return obj; > > } > > ... and that interfaces that implement other interfaces for a declared > interface are checked before the next declared interface. > > > obj = getInterfaces(interfaces[i]); > > if(obj != null) { > > return obj; > > } > > .. followed by super interfaces to a declared interface > > > obj = getSuperclass(interfaces[i]); > > if(obj != null) { > > return obj; > > } > > } > > return null; > > } > > in other words, the semantics of the interface selection stuff is pretty > unclear without looking at the code, and even then, can be a bit confusing. > > > private Object getSuperclass(Class clss) { > > if(clss == null) { > > return null; > > } > > Object obj = null; > > Class superclass = clss.getSuperclass(); > > obj = (Object)super.get(superclass); > > if(obj != null) { > > return obj; > > } > > obj = getInterfaces(superclass); > > especially when you add in the interfaces of super classse > > > if(obj != null) { > > return obj; > > > > obj = getSuperclass(superclass); > > and super-super classes. > > > if(obj != null) { > > return obj; > > } > > return null; > > } > > > :) > > michael > -- > Michael A. Smith > mas@apache.org > > > > -- > To unsubscribe, e-mail: > For additional commands, e-mail: > -- To unsubscribe, e-mail: For additional commands, e-mail: