Hi Henning, you're quite right that this is a bug--thanks for the
detailed description and sample code. :)
The existing values() method should be removed (an implementation of
it already exists in Hashtable), and a cheaper method which is in line
with the existing java.util.Map interface:
public Set keySet()
{
return new HashSet(keySequence);
}
You'll need to import HashSet.
Dan
"Henning P. Schmiedehausen" <[EMAIL PROTECTED]> writes:
> Hi,
>
> I might be wrong, but this looks bogus to me in SequencedHashtable.
>
> /**
> * Slightly cheaper implementation of <code>values()</code> method.
> */
> public Collection values ()
> {
> return keySequence;
> }
>
> because in keySequence are the keys stored. This would be some sort
> of
>
> public List keyList()
> {
> return keySequence;
> }
>
>
> A demo program seems to confirm this:
>
> --- cut ---
> import java.util.Hashtable;
> import java.util.Iterator;
>
> import org.apache.turbine.util.SequencedHashtable;
>
> public class sequencetest
> {
> public static void main(String[] args)
> {
> Hashtable ht = new Hashtable();
> SequencedHashtable sht = new SequencedHashtable();
>
> for(int i = 0; i < 10; i++)
> {
> ht.put("Key "+Integer.toString(i), "Value "+Integer.toString(i));
> sht.put("Key "+Integer.toString(i), "Value "+Integer.toString(i));
> }
>
> Iterator it;
>
> System.out.println("Hashtable:");
> it = ht.values().iterator();
>
> while(it.hasNext())
> System.out.println(it.next());
>
> System.out.println("Seq.Hashtable:");
> it = sht.values().iterator();
>
> while(it.hasNext())
> System.out.println(it.next());
> }
> }
> --- cut ---
>
> Hashtable:
> Value 4
> Value 3
> Value 2
> Value 1
> Value 0
> Value 9
> Value 8
> Value 7
> Value 6
> Value 5
>
> Seq.Hashtable:
> Key 0
> Key 1
> Key 2
> Key 3
> Key 4
> Key 5
> Key 6
> Key 7
> Key 8
> Key 9
>
> Not the same. Patch attached. I thought about deprecation but removing
> the values() method makes the original method from Hashtable visible
> again which is a good thing.
>
> By applying this patch, the whole SequencedHashtable shebang suddently
> gets usable for me to replace lots of "keep list and hashtable around"
> situations. ;-)
>
> Regards
> Henning
>
> Index: SequencedHashtable.java
> ===================================================================
> RCS file:
>/home/cvspublic/jakarta-turbine/src/java/org/apache/turbine/util/SequencedHashtable.java,v
> retrieving revision 1.4
> diff -u -r1.4 SequencedHashtable.java
> --- SequencedHashtable.java 2001/05/20 02:38:52 1.4
> +++ SequencedHashtable.java 2001/06/01 14:18:09
> @@ -57,6 +57,7 @@
> import java.util.Collection;
> import java.util.Hashtable;
> import java.util.Iterator;
> +import java.util.List;
> import java.util.LinkedList;
> import java.util.Map;
> import java.util.Set;
> @@ -73,6 +74,7 @@
> * the use of a list of <code>Map.Entry</code> objects.
> *
> * @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
> + * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
> * @version $Id: SequencedHashtable.java,v 1.4 2001/05/20 02:38:52 dlr Exp $
> */
> public class SequencedHashtable extends Hashtable
> @@ -261,10 +263,14 @@
> }
>
> /**
> - * Slightly cheaper implementation of <code>values()</code> method.
> + * Returns the keys in the table as a List.
> + *
> + * @return List of all keys
> */
> - public Collection values ()
> +
> + public List keyList()
> {
> return keySequence;
> }
> +
> }
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]