[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cp-patches] Patch: javax.print.attribute.HashAttributeSet fixlets
From: |
Mark Wielaard |
Subject: |
Re: [cp-patches] Patch: javax.print.attribute.HashAttributeSet fixlets |
Date: |
Mon, 14 Nov 2005 03:11:37 +0100 |
Hi Wolfgang,
On Sun, 2005-11-13 at 20:58 +0100, Wolfgang Baer wrote:
> 2005-11-13 Wolfgang Baer <address@hidden>
>
> * javax/print/attribute/HashAttributeSet.java:
> Added api docs to class and clarified method documentation.
> (toArray): Use iterator from values instead of entries.
> (hashCode): Compute hashcode according to specification.
> (get): Throw NullPointerException if category is null.
> (HashAttributeSet(Attribute[], Class)): Changed to allow
> Attribute[] to be null.
Should a HashAttributeSet be thread-safe? In that case you will have to
synchronize on the attributeMap while manipulating it or iterating over
it.
> /**
> - * Returns the hashcode for this object.
> - *
> - * @return the hashcode
> + * Returns the hashcode value. The hashcode value is the sum of all
> hashcodes
> + * of the attributes contained in this set.
> + *
> + * @return The hashcode for this attribute set.
> */
> public int hashCode()
> {
> - return attributeMap.hashCode() + interfaceName.hashCode();
> + int hashcode = 0;
> + Iterator it = attributeMap.values().iterator();
> + while (it.hasNext())
> + hashcode = hashcode + it.next().hashCode();
> +
> + return hashcode;
> }
It would be better to xor (^) the hashCode() values unless this
computation of the hashcode has been specified to use addition of
course. (Note the thread-safety issue above if there is a possibility
that some other thread adds or removes an attribute then this Iterator
could throw ConcurrentModificationException.)
> OK to commit ?
Yes if you can look at/answer the above two observations/questions.
Thanks,
Mark
signature.asc
Description: This is a digitally signed message part