You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Nathan Beyer <nb...@kc.rr.com> on 2006/06/12 04:54:14 UTC

RE: svn commit: r413531 - /incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/FeatureDescriptor.java

You beat me to this update by hours -- I was holding off because I noticed
that FeatureDescriptorTest was currently an excluded test and got dragged
into that for a bit. In any case, my patch was slightly different. Instead
of using a Vector, I just used the 'enumeration' utility method on
Collections. Like this:

    public Enumeration<String> attributeNames() {
        return Collections.enumeration(values.keySet());
    }

The functionality is obviously equivalent. I just thought I'd comment on the
alternative.

-Nathan

> -----Original Message-----
> From: tellison@apache.org [mailto:tellison@apache.org]
> Sent: Sunday, June 11, 2006 4:16 PM
> To: harmony-commits@incubator.apache.org
> Subject: svn commit: r413531 -
> /incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/jav
> a/beans/FeatureDescriptor.java
> 
> Author: tellison
> Date: Sun Jun 11 14:15:43 2006
> New Revision: 413531
> 
> URL: http://svn.apache.org/viewvc?rev=413531&view=rev
> Log:
> Convert attributeNames to return an enum of strings.
> 
> Modified:
> 
> incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java
> /beans/FeatureDescriptor.java
> 
> Modified:
> incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java
> /beans/FeatureDescriptor.java
> URL:
> http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/mod
> ules/beans/src/main/java/java/beans/FeatureDescriptor.java?rev=413531&r1=4
> 13530&r2=413531&view=diff
> ==========================================================================
> ====
> ---
> incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java
> /beans/FeatureDescriptor.java (original)
> +++
> incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java
> /beans/FeatureDescriptor.java Sun Jun 11 14:15:43 2006
> @@ -24,6 +24,7 @@
>  import java.util.Enumeration;
>  import java.util.Iterator;
>  import java.util.StringTokenizer;
> +import java.util.Vector;
> 
>  /**
>   * @author Maxim V. Berkultsev
> @@ -70,18 +71,10 @@
>      /**
>       * @com.intel.drl.spec_ref
>       */
> -    public Enumeration attributeNames() {
> -        String attributeNamesStr = "";
> -        Iterator i = values.keySet().iterator();
> -        while(i.hasNext()) {
> -            String attributeName = (String) i.next();
> -            if(attributeNamesStr.equals("")) {
> -                attributeNamesStr += attributeName;
> -            } else {
> -                attributeNamesStr += ' ' + attributeName;
> -            }
> -        }
> -        return new StringTokenizer(attributeNamesStr);
> +    public Enumeration<String> attributeNames() {
> +        Vector<String> attribNames = new Vector<String>(values.size());
> +        attribNames.addAll(values.keySet());
> +        return attribNames.elements();
>      }
> 
>      /**


---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: svn commit: r413531 - /incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/FeatureDescriptor.java

Posted by Tim Ellison <t....@gmail.com>.
Nathan Beyer wrote:
>> -----Original Message-----
>> From: Tim Ellison [mailto:t.p.ellison@gmail.com]
<snip>
>> They are not quite equivalent, since the code above enumerates over the
>> actual 'values' keySet.  If code calling attributeNames() removes a
>> value they are removing it from the FeatureDescriptor's private HashMap
>> variable, which is probably not what we want.  Creating a new collection
>> (Vector) of the values protects the code from that.
> 
> The method returns an Enumeration though and there's no method for removing
> items from an Enumeration.

Oops, you are right (I was thinking of an Iterator), but the keySet can
be modified by setValue(String,Object) so copying the keys provides some
stability if callers are setting values while enumerating.

Regards,
Tim

-- 

Tim Ellison (t.p.ellison@gmail.com)
IBM Java technology centre, UK.

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


RE: svn commit: r413531 - /incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/FeatureDescriptor.java

Posted by Nathan Beyer <nb...@kc.rr.com>.
> -----Original Message-----
> From: Tim Ellison [mailto:t.p.ellison@gmail.com]
> 
> Nathan Beyer wrote:
> > You beat me to this update by hours -- I was holding off because I
> noticed
> > that FeatureDescriptorTest was currently an excluded test and got
> dragged
> > into that for a bit.
> 
> Sorry, didn't know that you were looking into it ... I have no emotional
> attachment, just mopping up, so you are free to go for it.
> 
> > In any case, my patch was slightly different. Instead
> > of using a Vector, I just used the 'enumeration' utility method on
> > Collections. Like this:
> >
> >     public Enumeration<String> attributeNames() {
> >         return Collections.enumeration(values.keySet());
> >     }
> >
> > The functionality is obviously equivalent. I just thought I'd comment on
> the
> > alternative.
> 
> They are not quite equivalent, since the code above enumerates over the
> actual 'values' keySet.  If code calling attributeNames() removes a
> value they are removing it from the FeatureDescriptor's private HashMap
> variable, which is probably not what we want.  Creating a new collection
> (Vector) of the values protects the code from that.
> 


The method returns an Enumeration though and there's no method for removing
items from an Enumeration.

> Regards,
> Tim
> 
> 
> >> -----Original Message-----
> >> From: tellison@apache.org [mailto:tellison@apache.org]
> >> Sent: Sunday, June 11, 2006 4:16 PM
> >> To: harmony-commits@incubator.apache.org
> >> Subject: svn commit: r413531 -
> >>
> /incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/jav
> >> a/beans/FeatureDescriptor.java
> >>
> >> Author: tellison
> >> Date: Sun Jun 11 14:15:43 2006
> >> New Revision: 413531
> >>
> >> URL: http://svn.apache.org/viewvc?rev=413531&view=rev
> >> Log:
> >> Convert attributeNames to return an enum of strings.
> >>
> >> Modified:
> >>
> >>
> incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java
> >> /beans/FeatureDescriptor.java
> >>
> >> Modified:
> >>
> incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java
> >> /beans/FeatureDescriptor.java
> >> URL:
> >>
> http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/mod
> >>
> ules/beans/src/main/java/java/beans/FeatureDescriptor.java?rev=413531&r1=4
> >> 13530&r2=413531&view=diff
> >>
> ==========================================================================
> >> ====
> >> ---
> >>
> incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java
> >> /beans/FeatureDescriptor.java (original)
> >> +++
> >>
> incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java
> >> /beans/FeatureDescriptor.java Sun Jun 11 14:15:43 2006
> >> @@ -24,6 +24,7 @@
> >>  import java.util.Enumeration;
> >>  import java.util.Iterator;
> >>  import java.util.StringTokenizer;
> >> +import java.util.Vector;
> >>
> >>  /**
> >>   * @author Maxim V. Berkultsev
> >> @@ -70,18 +71,10 @@
> >>      /**
> >>       * @com.intel.drl.spec_ref
> >>       */
> >> -    public Enumeration attributeNames() {
> >> -        String attributeNamesStr = "";
> >> -        Iterator i = values.keySet().iterator();
> >> -        while(i.hasNext()) {
> >> -            String attributeName = (String) i.next();
> >> -            if(attributeNamesStr.equals("")) {
> >> -                attributeNamesStr += attributeName;
> >> -            } else {
> >> -                attributeNamesStr += ' ' + attributeName;
> >> -            }
> >> -        }
> >> -        return new StringTokenizer(attributeNamesStr);
> >> +    public Enumeration<String> attributeNames() {
> >> +        Vector<String> attribNames = new
> Vector<String>(values.size());
> >> +        attribNames.addAll(values.keySet());
> >> +        return attribNames.elements();
> >>      }
> >>
> >>      /**
> >
> >
> > ---------------------------------------------------------------------
> > Terms of use : http://incubator.apache.org/harmony/mailing.html
> > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> > For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> >
> >
> 
> --
> 
> Tim Ellison (t.p.ellison@gmail.com)
> IBM Java technology centre, UK.
> 
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org


---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Re: svn commit: r413531 - /incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/FeatureDescriptor.java

Posted by Tim Ellison <t....@gmail.com>.
Nathan Beyer wrote:
> You beat me to this update by hours -- I was holding off because I noticed
> that FeatureDescriptorTest was currently an excluded test and got dragged
> into that for a bit.

Sorry, didn't know that you were looking into it ... I have no emotional
attachment, just mopping up, so you are free to go for it.

> In any case, my patch was slightly different. Instead
> of using a Vector, I just used the 'enumeration' utility method on
> Collections. Like this:
> 
>     public Enumeration<String> attributeNames() {
>         return Collections.enumeration(values.keySet());
>     }
> 
> The functionality is obviously equivalent. I just thought I'd comment on the
> alternative.

They are not quite equivalent, since the code above enumerates over the
actual 'values' keySet.  If code calling attributeNames() removes a
value they are removing it from the FeatureDescriptor's private HashMap
variable, which is probably not what we want.  Creating a new collection
(Vector) of the values protects the code from that.

Regards,
Tim


>> -----Original Message-----
>> From: tellison@apache.org [mailto:tellison@apache.org]
>> Sent: Sunday, June 11, 2006 4:16 PM
>> To: harmony-commits@incubator.apache.org
>> Subject: svn commit: r413531 -
>> /incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/jav
>> a/beans/FeatureDescriptor.java
>>
>> Author: tellison
>> Date: Sun Jun 11 14:15:43 2006
>> New Revision: 413531
>>
>> URL: http://svn.apache.org/viewvc?rev=413531&view=rev
>> Log:
>> Convert attributeNames to return an enum of strings.
>>
>> Modified:
>>
>> incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java
>> /beans/FeatureDescriptor.java
>>
>> Modified:
>> incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java
>> /beans/FeatureDescriptor.java
>> URL:
>> http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/mod
>> ules/beans/src/main/java/java/beans/FeatureDescriptor.java?rev=413531&r1=4
>> 13530&r2=413531&view=diff
>> ==========================================================================
>> ====
>> ---
>> incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java
>> /beans/FeatureDescriptor.java (original)
>> +++
>> incubator/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java
>> /beans/FeatureDescriptor.java Sun Jun 11 14:15:43 2006
>> @@ -24,6 +24,7 @@
>>  import java.util.Enumeration;
>>  import java.util.Iterator;
>>  import java.util.StringTokenizer;
>> +import java.util.Vector;
>>
>>  /**
>>   * @author Maxim V. Berkultsev
>> @@ -70,18 +71,10 @@
>>      /**
>>       * @com.intel.drl.spec_ref
>>       */
>> -    public Enumeration attributeNames() {
>> -        String attributeNamesStr = "";
>> -        Iterator i = values.keySet().iterator();
>> -        while(i.hasNext()) {
>> -            String attributeName = (String) i.next();
>> -            if(attributeNamesStr.equals("")) {
>> -                attributeNamesStr += attributeName;
>> -            } else {
>> -                attributeNamesStr += ' ' + attributeName;
>> -            }
>> -        }
>> -        return new StringTokenizer(attributeNamesStr);
>> +    public Enumeration<String> attributeNames() {
>> +        Vector<String> attribNames = new Vector<String>(values.size());
>> +        attribNames.addAll(values.keySet());
>> +        return attribNames.elements();
>>      }
>>
>>      /**
> 
> 
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> 
> 

-- 

Tim Ellison (t.p.ellison@gmail.com)
IBM Java technology centre, UK.

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org