You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/08/25 16:31:14 UTC

svn commit: r807650 - in /incubator/pivot/trunk/core: src/org/apache/pivot/collections/ src/org/apache/pivot/collections/adapter/ src/org/apache/pivot/collections/concurrent/ src/org/apache/pivot/collections/immutable/ test/org/apache/pivot/collections...

Author: gbrown
Date: Tue Aug 25 14:31:13 2009
New Revision: 807650

URL: http://svn.apache.org/viewvc?rev=807650&view=rev
Log:
Add a List.ItemIterator interface; implement ItemIterator in ArrayList and LinkedList; fix some bugs in LinkedList; update HashMap to use LinkedLists for buckets; rename count() in Set to getCount().

Modified:
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/EnumMap.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/EnumSet.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/HashMap.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/HashSet.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/LinkedList.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/List.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/Set.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/adapter/SetAdapter.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedSet.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/immutable/ImmutableSet.java
    incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/HashMapTest.java
    incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/HashSetTest.java

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java?rev=807650&r1=807649&r2=807650&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java Tue Aug 25 14:31:13 2009
@@ -25,7 +25,6 @@
 
 import org.apache.pivot.util.ListenerList;
 
-
 /**
  * Implementation of the {@link List} interface that is backed by an
  * array.
@@ -34,16 +33,16 @@
  * {@link org.apache.pivot.collections.concurrent.SynchronizedList}.
  */
 public class ArrayList<T> implements List<T>, Serializable {
-    private class ItemIterator implements Iterator<T> {
+    private class ArrayListItemIterator implements ItemIterator<T> {
         private int index = 0;
         private int length;
 
-        public ItemIterator() {
+        public ArrayListItemIterator() {
             length = ArrayList.this.length;
         }
 
         public boolean hasNext() {
-            return index < getLength();
+            return (index < getLength());
         }
 
         public T next() {
@@ -58,8 +57,49 @@
             return get(index++);
         }
 
+        public boolean hasPrevious() {
+            return (index >= 0);
+        }
+
+        public T previous() {
+            if (!hasPrevious()) {
+                throw new NoSuchElementException();
+            }
+
+            if (length != ArrayList.this.length) {
+                throw new ConcurrentModificationException();
+            }
+
+            return get(index--);
+        }
+
+        public void insert(T item) {
+            if (index < 0
+                || index >= ArrayList.this.length) {
+                throw new IllegalStateException();
+            }
+
+            ArrayList.this.insert(item, index);
+            length++;
+        }
+
+        public void update(T item) {
+            if (index < 0
+                || index >= ArrayList.this.length) {
+                throw new IllegalStateException();
+            }
+
+            ArrayList.this.update(index, item);
+        }
+
         public void remove() {
-            throw new UnsupportedOperationException();
+            if (index < 0
+                || index >= ArrayList.this.length) {
+                throw new IllegalStateException();
+            }
+
+            ArrayList.this.remove(index, 1);
+            length--;
         }
     }
 
@@ -356,8 +396,8 @@
         }
     }
 
-    public Iterator<T> iterator() {
-        return new ItemIterator();
+    public ItemIterator<T> iterator() {
+        return new ArrayListItemIterator();
     }
 
     public ListenerList<ListListener<T>> getListListeners() {
@@ -403,14 +443,16 @@
         sb.append(getClass().getName());
         sb.append(" [");
 
-        int i = 0;
-        for (T item : this) {
-            if (i > 0) {
-                sb.append(", ");
-            }
+        if (getLength() > 0) {
+            int i = 0;
+            for (T item : this) {
+                if (i > 0) {
+                    sb.append(", ");
+                }
 
-            sb.append(item);
-            i++;
+                sb.append(item);
+                i++;
+            }
         }
 
         sb.append("]");

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/EnumMap.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/EnumMap.java?rev=807650&r1=807649&r2=807650&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/EnumMap.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/EnumMap.java Tue Aug 25 14:31:13 2009
@@ -106,7 +106,7 @@
     }
 
     public int getCount() {
-        return keySet.count();
+        return keySet.getCount();
     }
 
     public Comparator<E> getComparator() {

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/EnumSet.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/EnumSet.java?rev=807650&r1=807649&r2=807650&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/EnumSet.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/EnumSet.java Tue Aug 25 14:31:13 2009
@@ -133,7 +133,7 @@
         return count == 0;
     }
 
-    public int count() {
+    public int getCount() {
         return count;
     }
 

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/HashMap.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/HashMap.java?rev=807650&r1=807649&r2=807650&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/HashMap.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/HashMap.java Tue Aug 25 14:31:13 2009
@@ -28,30 +28,29 @@
 /**
  * Implementation of the {@link Map} interface that is backed by a
  * hash table.
- * <p>
- * TODO Optimize bucket management when a comparator is applied by using binary search to
- * sort bucket contents and locate pairs.
  */
 public class HashMap<K, V> implements Map<K, V>, Serializable {
     private class KeyIterator implements Iterator<K> {
-        private int bucketIndex = 0;
-        private int pairIndex = 0;
+        private int bucketIndex;
+        private Iterator<Pair<K, V>> entryIterator;
         private int count;
 
         public KeyIterator() {
+            bucketIndex = 0;
+            entryIterator = buckets.get(bucketIndex).iterator();
+
             count = HashMap.this.count;
         }
 
         public boolean hasNext() {
-            // Locate the next pair
-            while (bucketIndex < buckets.getLength()
-                && pairIndex == buckets.get(bucketIndex).getLength()) {
-                bucketIndex++;
-                pairIndex = 0;
+            // Move to the next bucket
+            while (entryIterator != null
+                && !entryIterator.hasNext()) {
+                entryIterator = (bucketIndex < buckets.getLength()) ?
+                    buckets.get(bucketIndex++).iterator() : null;
             }
 
-            return (bucketIndex < buckets.getLength()
-                && pairIndex < buckets.get(bucketIndex).getLength());
+            return (entryIterator != null);
         }
 
         public K next() {
@@ -63,11 +62,9 @@
                 throw new ConcurrentModificationException();
             }
 
-            // Return the current pair
-            ArrayList<Pair<K, V>> bucket = buckets.get(bucketIndex);
-            Pair<K, V> pair = bucket.get(pairIndex++);
+            Pair<K, V> entry = entryIterator.next();
 
-            return pair.key;
+            return entry.key;
         }
 
         public void remove() {
@@ -77,7 +74,7 @@
 
     private static final long serialVersionUID = 0;
 
-    private ArrayList<ArrayList<Pair<K, V>>> buckets;
+    private ArrayList<LinkedList<Pair<K, V>>> buckets;
     private float loadFactor;
 
     private int count = 0;
@@ -102,12 +99,12 @@
         rehash(capacity);
     }
 
-    public HashMap(Pair<K, V>... pairs) {
-        this(Math.max((int)((float)pairs.length / DEFAULT_LOAD_FACTOR) + 1, DEFAULT_CAPACITY));
+    public HashMap(Pair<K, V>... entries) {
+        this(Math.max((int)((float)entries.length / DEFAULT_LOAD_FACTOR) + 1, DEFAULT_CAPACITY));
 
-        for (int i = 0; i < pairs.length; i++) {
-            Pair<K, V> pair = pairs[i];
-            put(pair.key, pair.value);
+        for (int i = 0; i < entries.length; i++) {
+            Pair<K, V> entry = entries[i];
+            put(entry.key, entry.value);
         }
     }
 
@@ -130,20 +127,18 @@
     public V get(K key) {
         V value = null;
 
-        // Locate the pair
+        // Locate the entry
         int bucketIndex = getBucketIndex(key);
-        ArrayList<Pair<K, V>> bucket = buckets.get(bucketIndex);
-
-        int n = bucket.getLength();
-        int i = 0;
+        LinkedList<Pair<K, V>> bucket = buckets.get(bucketIndex);
 
-        while (i < n
-            && !bucket.get(i).key.equals(key)) {
-            i++;
-        }
-
-        if (i < n) {
-            value = bucket.get(i).value;
+        List.ItemIterator<Pair<K, V>> iterator = bucket.iterator();
+        while (iterator.hasNext()) {
+            Pair<K, V> entry = iterator.next();
+
+            if (entry.key.equals(key)) {
+                value = entry.value;
+                break;
+            }
         }
 
         return value;
@@ -152,30 +147,37 @@
     public V put(K key, V value) {
         V previousValue = null;
 
-        // Locate the pair
+        // Locate the entry
         int bucketIndex = getBucketIndex(key);
-        ArrayList<Pair<K, V>> bucket = buckets.get(bucketIndex);
+        LinkedList<Pair<K, V>> bucket = buckets.get(bucketIndex);
 
-        int n = bucket.getLength();
         int i = 0;
+        List.ItemIterator<Pair<K, V>> iterator = bucket.iterator();
+        while (iterator.hasNext()) {
+            Pair<K, V> entry = iterator.next();
+
+            if (entry.key.equals(key)) {
+                // Update the entry
+                previousValue = entry.value;
+                iterator.update(new Pair<K, V>(key, value));
+
+                mapListeners.valueUpdated(this, key, previousValue);
+
+                break;
+            }
 
-        while (i < n
-            && !bucket.get(i).key.equals(key)) {
             i++;
         }
 
-        if (i < n) {
-            // Update the pair
-            previousValue = bucket.update(i, new Pair<K, V>(key, value)).value;
-            mapListeners.valueUpdated(this, key, previousValue);
-        } else {
-            // Add the pair
+        if (i == bucket.getLength()) {
+            // Add the entry
             bucket.add(new Pair<K, V>(key, value));
 
             if (keys != null) {
                 keys.add(key);
             }
 
+            // Increment the count
             count++;
 
             int capacity = getCapacity();
@@ -192,30 +194,30 @@
     public V remove(K key) {
         V value = null;
 
-        // Locate the pair
+        // Locate the entry
         int bucketIndex = getBucketIndex(key);
-        ArrayList<Pair<K, V>> bucket = buckets.get(bucketIndex);
-
-        int n = bucket.getLength();
-        int i = 0;
+        LinkedList<Pair<K, V>> bucket = buckets.get(bucketIndex);
 
-        while (i < n
-            && !bucket.get(i).key.equals(key)) {
-            i++;
-        }
+        List.ItemIterator<Pair<K, V>> iterator = bucket.iterator();
+        while (iterator.hasNext()) {
+            Pair<K, V> entry = iterator.next();
+
+            if (entry.key.equals(key)) {
+                // Remove the entry
+                value = entry.value;
+                iterator.remove();
 
-        if (i < n) {
-            // Remove the pair
-            Sequence<Pair<K, V>> removed = bucket.remove(i, 1);
-            value = removed.get(0).value;
+                if (keys != null) {
+                    keys.remove(key);
+                }
 
-            if (keys != null) {
-                keys.remove(key);
-            }
+                // Decrement the count
+                count--;
 
-            count--;
+                mapListeners.valueRemoved(this, key, value);
 
-            mapListeners.valueRemoved(this, key, value);
+                break;
+            }
         }
 
         return value;
@@ -223,7 +225,8 @@
 
     public void clear() {
         if (count > 0) {
-            for (ArrayList<Pair<K, V>> bucket : buckets) {
+            // Remove all entries
+            for (LinkedList<Pair<K, V>> bucket : buckets) {
                 bucket.clear();
             }
 
@@ -231,6 +234,7 @@
                 keys.clear();
             }
 
+            // Clear the count
             count = 0;
 
             mapListeners.mapCleared(this);
@@ -238,19 +242,23 @@
     }
 
     public boolean containsKey(K key) {
-        // Locate the pair
+        // Locate the entry
         int bucketIndex = getBucketIndex(key);
-        ArrayList<Pair<K, V>> bucket = buckets.get(bucketIndex);
+        LinkedList<Pair<K, V>> bucket = buckets.get(bucketIndex);
 
-        int n = bucket.getLength();
         int i = 0;
+        List.ItemIterator<Pair<K, V>> iterator = bucket.iterator();
+        while (iterator.hasNext()) {
+            Pair<K, V> entry = iterator.next();
+
+            if (entry.key.equals(key)) {
+                break;
+            }
 
-        while (i < n
-            && !bucket.get(i).key.equals(key)) {
             i++;
         }
 
-        return (i < n);
+        return (i < bucket.getLength());
     }
 
     public boolean isEmpty() {
@@ -265,21 +273,40 @@
         return buckets.getLength();
     }
 
+    private static int rehashCount = 0;
+    private static long rehashTime = 0;
+
     private void rehash(int capacity) {
-        ArrayList<ArrayList<Pair<K, V>>> previousBuckets = this.buckets;
-        buckets = new ArrayList<ArrayList<Pair<K, V>>>(capacity);
+        long t0 = System.currentTimeMillis();
+
+        ArrayList<LinkedList<Pair<K, V>>> previousBuckets = this.buckets;
+        buckets = new ArrayList<LinkedList<Pair<K, V>>>(capacity);
 
         for (int i = 0; i < capacity; i++) {
-            buckets.add(new ArrayList<Pair<K, V>>());
+            buckets.add(new LinkedList<Pair<K, V>>());
         }
 
+        long t1 = System.currentTimeMillis();
+
         if (previousBuckets != null) {
-            for (ArrayList<Pair<K, V>> bucket : previousBuckets) {
-                for (Pair<K, V> pair : bucket) {
-                    put(pair.key, pair.value);
+            for (LinkedList<Pair<K, V>> bucket : previousBuckets) {
+                for (Pair<K, V> entry : bucket) {
+                    put(entry.key, entry.value);
                 }
             }
         }
+
+        rehashTime += (t1 - t0);
+        rehashCount++;
+    }
+
+    public static void clearRehashTime() {
+        rehashCount = 0;
+        rehashTime = 0;
+    }
+
+    public static void dumpRehashTime() {
+        System.out.println("Rehash time/count: " + rehashTime + "ms/" + rehashCount);
     }
 
     private int getBucketIndex(K key) {
@@ -329,14 +356,16 @@
         sb.append(getClass().getName());
         sb.append(" {");
 
-        int i = 0;
-        for (K key : this) {
-            if (i > 0) {
-                sb.append(", ");
-            }
+        if (getCount() > 0) {
+            int i = 0;
+            for (K key : this) {
+                if (i > 0) {
+                    sb.append(", ");
+                }
 
-            sb.append(key + ":" + get(key));
-            i++;
+                sb.append(key + ":" + get(key));
+                i++;
+            }
         }
 
         sb.append("}");

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/HashSet.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/HashSet.java?rev=807650&r1=807649&r2=807650&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/HashSet.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/HashSet.java Tue Aug 25 14:31:13 2009
@@ -94,7 +94,7 @@
         return hashMap.isEmpty();
     }
 
-    public int count() {
+    public int getCount() {
         return hashMap.getCount();
     }
 
@@ -113,4 +113,27 @@
     public ListenerList<SetListener<E>> getSetListeners() {
         return setListeners;
     }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append(getClass().getName());
+        sb.append(" (");
+
+        if (getCount() > 0) {
+            int i = 0;
+            for (E element : this) {
+                if (i > 0) {
+                    sb.append(", ");
+                }
+
+                sb.append(element);
+                i++;
+            }
+        }
+
+        sb.append(")");
+
+        return sb.toString();
+    }
 }

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/LinkedList.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/LinkedList.java?rev=807650&r1=807649&r2=807650&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/LinkedList.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/LinkedList.java Tue Aug 25 14:31:13 2009
@@ -24,7 +24,6 @@
 
 import org.apache.pivot.util.ListenerList;
 
-
 /**
  * Implementation of the {@link List} interface that is backed by a linked
  * list.
@@ -33,7 +32,6 @@
  * {@link org.apache.pivot.collections.concurrent.SynchronizedList}.
  */
 public class LinkedList<T> implements List<T>, Serializable {
-    // Node containing an item in the list
     private static class Node<T> implements Serializable {
         private static final long serialVersionUID = 0;
         private Node<T> previous;
@@ -47,16 +45,24 @@
         }
     }
 
-    // Node iterator
-    private class NodeIterator implements Iterator<T> {
-        private Node<T> node;
+    private class LinkedListItemIterator implements ItemIterator<T> {
+        private boolean reverse;
+        private Node<T> current;
+        private Node<T> next;
+
+        public LinkedListItemIterator() {
+            this(false);
+        }
+
+        public LinkedListItemIterator(boolean reverse) {
+            this.reverse = reverse;
 
-        public NodeIterator() {
-            this.node = first;
+            current = null;
+            next = (reverse) ? last : first;
         }
 
         public boolean hasNext() {
-            return (node != null);
+            return (next != null);
         }
 
         public T next() {
@@ -64,21 +70,75 @@
                 throw new NoSuchElementException();
             }
 
-            T item = node.item;
-            node = node.next;
+            T item = next.item;
+            current = next;
+            next = (reverse) ? next.previous : next.next;
+
+            return item;
+        }
+
+        public boolean hasPrevious() {
+            return (next != null);
+        }
+
+        public T previous() {
+            if (!hasPrevious()) {
+                throw new NoSuchElementException();
+            }
+
+            T item = next.item;
+            current = next;
+            next = (reverse) ? next.next: next.previous;
 
             return item;
         }
 
+        public void insert(T item) {
+            if (current == null) {
+                throw new IllegalStateException();
+            }
+
+            // Insert a new node immediately prior to the current node
+            Node<T> node = new Node<T>(current.previous, current, item);
+
+            if (current.previous == null) {
+                first = node;
+            } else {
+                current.previous.next = node;
+            }
+
+            current.previous = node;
+
+            length++;
+        }
+
+        public void update(T item) {
+            if (current == null) {
+                throw new IllegalStateException();
+            }
+
+            current.item = item;
+        }
+
         public void remove() {
-            // Unlink this node from its predecessor and successor
-            if (node.previous != null) {
-                node.previous.next = node.next;
+            if (current == null) {
+                throw new IllegalStateException();
             }
 
-            if (node.next != null) {
-                node.next.previous = node.previous;
+            // Unlink the current node from its predecessor and successor
+            if (current.previous == null) {
+                first = current.next;
+            } else {
+                current.previous.next = current.next;
             }
+
+            if (current.next == null) {
+                last = current.previous;
+            } else {
+                current.next.previous = current.previous;
+            }
+
+            length--;
         }
     }
 
@@ -123,7 +183,7 @@
         } else {
             // Find the insertion point
             index = 0;
-            NodeIterator nodeIterator = new NodeIterator();
+            LinkedListItemIterator nodeIterator = new LinkedListItemIterator();
             while (nodeIterator.hasNext()
                 && comparator.compare(item, nodeIterator.next()) > 0) {
                 index++;
@@ -132,8 +192,8 @@
             if (nodeIterator.hasNext()
                 && index > 0) {
                 // Insert the new node here
-                Node<T> node = new Node<T>(nodeIterator.node, nodeIterator.node.next, item);
-                nodeIterator.node.next = node;
+                Node<T> node = new Node<T>(nodeIterator.next, nodeIterator.next.next, item);
+                nodeIterator.next.next = node;
                 node.next.previous = node;
                 length++;
             } else {
@@ -227,7 +287,7 @@
     public int remove(T item) {
         int index = 0;
 
-        NodeIterator nodeIterator = new NodeIterator();
+        LinkedListItemIterator nodeIterator = new LinkedListItemIterator();
         while (nodeIterator.hasNext()) {
             if (nodeIterator.next() == item) {
                 nodeIterator.remove();
@@ -341,7 +401,7 @@
     public int indexOf(T item) {
         int index = 0;
 
-        NodeIterator nodeIterator = new NodeIterator();
+        LinkedListItemIterator nodeIterator = new LinkedListItemIterator();
         while (nodeIterator.hasNext()) {
             if (nodeIterator.next() == item) {
                 break;
@@ -406,8 +466,12 @@
         }
     }
 
-    public Iterator<T> iterator() {
-        return new NodeIterator();
+    public ItemIterator<T> iterator() {
+        return iterator(false);
+    }
+
+    public ItemIterator<T> iterator(boolean reverse) {
+        return new LinkedListItemIterator(reverse);
     }
 
     public ListenerList<ListListener<T>> getListListeners() {
@@ -453,14 +517,16 @@
         sb.append(getClass().getName());
         sb.append(" [");
 
-        int i = 0;
-        for (T item : this) {
-            if (i > 0) {
-                sb.append(", ");
-            }
+        if (getLength() > 0) {
+            int i = 0;
+            for (T item : this) {
+                if (i > 0) {
+                    sb.append(", ");
+                }
 
-            sb.append(item);
-            i++;
+                sb.append(item);
+                i++;
+            }
         }
 
         sb.append("]");

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/List.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/List.java?rev=807650&r1=807649&r2=807650&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/List.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/List.java Tue Aug 25 14:31:13 2009
@@ -17,6 +17,7 @@
 package org.apache.pivot.collections;
 
 import java.util.Comparator;
+import java.util.Iterator;
 
 import org.apache.pivot.util.ListenerList;
 
@@ -25,6 +26,16 @@
  */
 public interface List<T> extends Sequence<T>, Collection<T> {
     /**
+     * Optional item iterator interface.
+     */
+    public interface ItemIterator<T> extends Iterator<T> {
+        public boolean hasPrevious();
+        public T previous();
+        public void insert(T item);
+        public void update(T item);
+    }
+
+    /**
      * List listener list.
      */
     public static class ListListenerList<T>

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/Set.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/Set.java?rev=807650&r1=807649&r2=807650&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/Set.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/Set.java Tue Aug 25 14:31:13 2009
@@ -72,7 +72,7 @@
     /**
      * Returns the number of elements in the set.
      */
-    public int count();
+    public int getCount();
 
     /**
      * @see SetListener#setCleared(Set)

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/adapter/SetAdapter.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/adapter/SetAdapter.java?rev=807650&r1=807649&r2=807650&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/adapter/SetAdapter.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/adapter/SetAdapter.java Tue Aug 25 14:31:13 2009
@@ -90,7 +90,7 @@
         return set.isEmpty();
     }
 
-    public int count() {
+    public int getCount() {
         return set.size();
     }
 

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedSet.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedSet.java?rev=807650&r1=807649&r2=807650&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedSet.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedSet.java Tue Aug 25 14:31:13 2009
@@ -100,8 +100,8 @@
         return ((Set<E>)collection).isEmpty();
     }
 
-    public synchronized int count() {
-        return ((Set<E>)collection).count();
+    public synchronized int getCount() {
+        return ((Set<E>)collection).getCount();
     }
 
     public ListenerList<SetListener<E>> getSetListeners() {

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/immutable/ImmutableSet.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/immutable/ImmutableSet.java?rev=807650&r1=807649&r2=807650&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/immutable/ImmutableSet.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/immutable/ImmutableSet.java Tue Aug 25 14:31:13 2009
@@ -61,8 +61,8 @@
         return set.isEmpty();
     }
 
-    public int count() {
-        return set.count();
+    public int getCount() {
+        return set.getCount();
     }
 
     public Comparator<E> getComparator() {

Modified: incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/HashMapTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/HashMapTest.java?rev=807650&r1=807649&r2=807650&view=diff
==============================================================================
--- incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/HashMapTest.java (original)
+++ incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/HashMapTest.java Tue Aug 25 14:31:13 2009
@@ -60,15 +60,16 @@
         assertEquals(0, map.getCount());
 
         map.put("a", 1);
+        assertEquals(1, map.getCount());
         map.put("b", 2);
+        assertEquals(2, map.getCount());
         map.put("c", 3);
+        assertEquals(3, map.getCount());
 
         assertEquals(1, (int) map.get("a"));
         assertEquals(2, (int) map.get("b"));
         assertEquals(3, (int) map.get("c"));
 
-        assertEquals(3, map.getCount());
-
         Iterator<String> iter = map.iterator();
         int count = 0;
         while (iter.hasNext()) {
@@ -142,7 +143,7 @@
     @Test
     public void iteratorConcurrentModificationTest() {
         HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
-        
+
         map.put(1, 1);
         map.put(2, 2);
         Iterator<Integer> iter = map.iterator();
@@ -155,23 +156,33 @@
             // expecting this
         }
     }
-    
-    private static int LOAD_COUNT = 100000;
+
+    private static int LOAD_COUNT = 10000;
 
     @Test
     public void pivotHashMapSpeedTest() {
+        HashMap.clearRehashTime();
+
+        long t0 = System.currentTimeMillis();
         HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
         for (int i = 0; i < LOAD_COUNT; i++) {
             map.put(Integer.valueOf(i), Integer.valueOf(i));
         }
+        long t1 = System.currentTimeMillis();
+        System.out.println("org.apache.pivot.HashMap " + (t1 - t0) + "ms");
+
+        HashMap.dumpRehashTime();
     }
 
     @Test
     public void javaHashMapSpeedTest() {
+        long t0 = System.currentTimeMillis();
         java.util.HashMap<Integer, Integer> map = new java.util.HashMap<Integer, Integer>();
         for (int i = 0; i < LOAD_COUNT; i++) {
             map.put(Integer.valueOf(i), Integer.valueOf(i));
         }
+        long t1 = System.currentTimeMillis();
+        System.out.println("java.util.HashMap " + (t1 - t0) + "ms");
     }
 
 }

Modified: incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/HashSetTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/HashSetTest.java?rev=807650&r1=807649&r2=807650&view=diff
==============================================================================
--- incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/HashSetTest.java (original)
+++ incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/HashSetTest.java Tue Aug 25 14:31:13 2009
@@ -33,7 +33,7 @@
         assertTrue(hashSet.contains("A"));
         assertTrue(hashSet.contains("B"));
 
-        assertEquals(hashSet.count(), 2);
+        assertEquals(hashSet.getCount(), 2);
 
         int i = 0;
         for (String element : hashSet) {