tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r501108 - in /tapestry/tapestry5/tapestry-core/trunk/src: main/java/org/apache/tapestry/DefaultPrimaryKeyEncoder.java test/java/org/apache/tapestry/DefaultPrimaryKeyEncoderTest.java
Date Mon, 29 Jan 2007 17:01:35 GMT
Author: hlship
Date: Mon Jan 29 09:01:34 2007
New Revision: 501108

URL: http://svn.apache.org/viewvc?view=rev&rev=501108
Log:
Change implementation of DefaultPrimaryKeyEncoder to make use of LinkedHashMap.

Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/DefaultPrimaryKeyEncoder.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/DefaultPrimaryKeyEncoderTest.java

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/DefaultPrimaryKeyEncoder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/DefaultPrimaryKeyEncoder.java?view=diff&rev=501108&r1=501107&r2=501108
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/DefaultPrimaryKeyEncoder.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/DefaultPrimaryKeyEncoder.java
Mon Jan 29 09:01:34 2007
@@ -19,6 +19,7 @@
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newSet;
 
 import java.io.Serializable;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -39,12 +40,10 @@
  */
 public class DefaultPrimaryKeyEncoder<K extends Serializable, V> implements PrimaryKeyEncoder<K,
V>
 {
-    private final Map<K, V> _keyToValue = newMap();
+    private final Map<K, V> _keyToValue = new LinkedHashMap<K, V>();
 
     private final Map<V, K> _valueToKey = newMap();
 
-    private final List<K> _orderedKeys = newList();
-
     private Set<K> _deletedKeys;
 
     private K _currentKey;
@@ -60,7 +59,6 @@
             throw new IllegalArgumentException(TapestryMessages.duplicateKey(key, value,
existing));
 
         _keyToValue.put(key, value);
-        _orderedKeys.add(key);
 
         // TODO: Ensure that the value is unique?
 
@@ -93,12 +91,13 @@
 
         List<V> result = newList();
 
-        for (K key : _orderedKeys)
+        for (Map.Entry<K, V> entry : _keyToValue.entrySet())
         {
-            if (keySet.contains(key))
+
+            if (keySet.contains(entry.getKey()))
                 continue;
 
-            result.add(_keyToValue.get(key));
+            result.add(entry.getValue());
         }
 
         return result;
@@ -108,9 +107,9 @@
     {
         List<V> result = newList();
 
-        for (K key : _orderedKeys)
+        for (Map.Entry<K, V> entry : _keyToValue.entrySet())
         {
-            result.add(_keyToValue.get(key));
+            result.add(entry.getValue());
         }
 
         return result;

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/DefaultPrimaryKeyEncoderTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/DefaultPrimaryKeyEncoderTest.java?view=diff&rev=501108&r1=501107&r2=501108
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/DefaultPrimaryKeyEncoderTest.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/DefaultPrimaryKeyEncoderTest.java
Mon Jan 29 09:01:34 2007
@@ -83,7 +83,7 @@
     }
 
     @Test
-    public void value_ordered_maintained()
+    public void value_orderer_maintained()
     {
         IntStringEncoder encoder = newEncoder();
 



Mime
View raw message