avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vincent Massol" <vmas...@octo.com>
Subject RE: new method Configuration.containsAttribute() ?
Date Wed, 12 Dec 2001 20:00:50 GMT

> -----Original Message-----
> From: Berin Loritsch [mailto:bloritsch@apache.org]
> Sent: 12 December 2001 18:13
> To: Avalon Developers List
> Subject: Re: new method Configuration.containsAttribute() ?
> Vincent Massol wrote:
> > Hi,
> >
> > I am using the
> > object in some of my Configurable components and I find that it is
> > very easy to decide whether a Configuration contains an attribute or
> > not. There is a getAtribute() which takes a default value but that's
> > enough.
> >
> > I'm proposing to add a Boolean containsAttribute(String name). What
> > you think ? Should I go ahead a send a patch (in other words, do you
> > agree to include it in the base Avalon framework) ?
> Can you provide a use case for such a thing?  How do you propose to
> the containsAttribute() method?  Why *exactly* is the defaulted
> of getAttribute() not enough?
> I need some more info if I am going to back you on this.

see below.
> > Or is there another that I have missed of doing this ? With the
> > code base I can see 2 ways of doing this :
> > 1/ testing for a ConfigurationException, which does not seem a good
> > 2/ call getAttributeNames() and iterate to find if the attribute
> > which is also not that fine.
> Why do you need to know if it does not exist?
> Also have you considered this:
> String value = configuration.getAttribute( "name", null );
> if ( null == value )
> {
>      // do the processing if it is not here
> }

ah, that's what I was missing. It never occurred to me that it was valid
to pass a null value ! However, it does not seem a very nice way of
doing it as it does not reflect what you're trying to achieve (checking
if an attribute has been defined).

It is the same as if you're saying that whenever you want to check if a
value is in a hashtable you were writing :

if (null == hashtable.get("key")

Instead of 

if (hashtable.containsKey("key"))

Another option is to return the attributes as a Vector, in addition to
an array of strings (but unfortunately we can't use the same method name
as it would be the same signature...), which would let us write :

If (configuration.getAttributesNamesAsVector().contains("attribute

Another option: return a hashtable of attributes :

If (configuration.getAttributes().containsKey("attribute name"))

I personally prefer this last option as it let you benefit from all the
API of a hashtable and you don't have to reproduce its API in the
Configuration API.

So, in conclusion, forget my previous proposition and instead, what
would you think of :

public Hashtable getAttributes();

Thanks Berin

To unsubscribe, e-mail:   <mailto:avalon-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-dev-help@jakarta.apache.org>

View raw message