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/01 15:43:17 UTC

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

Author: gbrown
Date: Sat Aug  1 13:43:17 2009
New Revision: 799860

URL: http://svn.apache.org/viewvc?rev=799860&view=rev
Log:
Return boolean from Set#add() and Set#remove() to reflect the result of the operation (parallels java.util.Set); add a count() method to Map and Set; complete implementation of ListSelection.

Modified:
    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/Group.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/HashSet.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/Map.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/Set.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/adapter/MapAdapter.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/adapter/SetAdapter.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedMap.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedSet.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/immutable/ImmutableMap.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/immutable/ImmutableSet.java
    incubator/pivot/trunk/core/src/org/apache/pivot/util/concurrent/TaskGroup.java
    incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/ArrayListTest.java
    incubator/pivot/trunk/web/src/org/apache/pivot/web/server/ProxyServlet.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListSelection.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java

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=799860&r1=799859&r2=799860&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 Sat Aug  1 13:43:17 2009
@@ -105,6 +105,10 @@
         return keySet.isEmpty();
     }
 
+    public int count() {
+        return keySet.count();
+    }
+
     public Comparator<E> getComparator() {
         return null;
     }

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=799860&r1=799859&r2=799860&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 Sat Aug  1 13:43:17 2009
@@ -87,24 +87,34 @@
         return enumClass;
     }
 
-    public void add(E element) {
-        int ordinal = element.ordinal();
+    public boolean add(E element) {
+        boolean added = false;
 
+        int ordinal = element.ordinal();
         if (!members[ordinal]) {
             members[ordinal] = true;
+            added = true;
             count++;
+
             setListeners.elementAdded(this, element);
         }
+
+        return added;
     }
 
-    public void remove(E element) {
-        int ordinal = element.ordinal();
+    public boolean remove(E element) {
+        boolean removed = false;
 
+        int ordinal = element.ordinal();
         if (members[ordinal]) {
             members[ordinal] = false;
+            removed = true;
             count--;
+
             setListeners.elementRemoved(this, element);
         }
+
+        return removed;
     }
 
     public void clear() {
@@ -123,6 +133,10 @@
         return count == 0;
     }
 
+    public int count() {
+        return count;
+    }
+
     public Comparator<E> getComparator() {
         return null;
     }

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/Group.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/Group.java?rev=799860&r1=799859&r2=799860&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/Group.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/Group.java Sat Aug  1 13:43:17 2009
@@ -27,16 +27,24 @@
      *
      * @param element
      * The element to add to the group.
+     *
+     * @return
+     * <tt>true</tt> if the element was added to the group; <tt>false</tt>,
+     * otherwise.
      */
-    public void add(E element);
+    public boolean add(E element);
 
     /**
      * Removes an element from the group.
      *
      * @param element
      * The element to remove from the set.
+     *
+     * @return
+     * <tt>true</tt> if the element was removed from the group; <tt>false</tt>,
+     * otherwise.
      */
-    public void remove(E element);
+    public boolean remove(E element);
 
     /**
      * Tests the existence of an element in the group.

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=799860&r1=799859&r2=799860&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 Sat Aug  1 13:43:17 2009
@@ -66,18 +66,30 @@
         // this.comparator = comparator;
     }
 
-    public void add(E element) {
+    public boolean add(E element) {
+        boolean added = false;
+
         if (!hashSet.contains(element)) {
             hashSet.add(element);
+            added = true;
+
             setListeners.elementAdded(this, element);
         }
+
+        return added;
     }
 
-    public void remove(E element) {
+    public boolean remove(E element) {
+        boolean removed = false;
+
         if (hashSet.contains(element)) {
             hashSet.remove(element);
+            removed = true;
+
             setListeners.elementRemoved(this, element);
         }
+
+        return removed;
     }
 
     public void clear() {

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/Map.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/Map.java?rev=799860&r1=799859&r2=799860&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/Map.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/Map.java Sat Aug  1 13:43:17 2009
@@ -138,6 +138,11 @@
     public void clear();
 
     /**
+     * Returns the number of entries in the map.
+     */
+    public int count();
+
+    /**
      * @see MapListener#comparatorChanged(Map, Comparator)
      */
     public void setComparator(Comparator<K> comparator);

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=799860&r1=799859&r2=799860&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 Sat Aug  1 13:43:17 2009
@@ -61,12 +61,12 @@
     /**
      * @see SetListener#elementAdded(Set, Object)
      */
-    public void add(E element);
+    public boolean add(E element);
 
     /**
      * @see SetListener#elementRemoved(Set, Object)
      */
-    public void remove(E element);
+    public boolean remove(E element);
 
     /**
      * @see SetListener#setCleared(Set)
@@ -74,6 +74,11 @@
     public void clear();
 
     /**
+     * Returns the number of elements in the set.
+     */
+    public int count();
+
+    /**
      * @see SetListener#setCleared(Set)
      */
     public void setComparator(Comparator<E> comparator);

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/adapter/MapAdapter.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/adapter/MapAdapter.java?rev=799860&r1=799859&r2=799860&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/adapter/MapAdapter.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/adapter/MapAdapter.java Sat Aug  1 13:43:17 2009
@@ -90,6 +90,10 @@
         return map.isEmpty();
     }
 
+    public int count() {
+        return map.size();
+    }
+
     public Comparator<K> getComparator() {
         return null;
     }

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=799860&r1=799859&r2=799860&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 Sat Aug  1 13:43:17 2009
@@ -45,18 +45,30 @@
         return set;
     }
 
-    public void add(E element) {
+    public boolean add(E element) {
+        boolean added = false;
+
         if (!contains(element)) {
             set.add(element);
+            added = true;
+
             setListeners.elementAdded(this, element);
         }
+
+        return added;
     }
 
-    public void remove(E element) {
+    public boolean remove(E element) {
+        boolean removed = false;
+
         if (contains(element)) {
             set.remove(element);
+            removed = false;
+
             setListeners.elementRemoved(this, element);
         }
+
+        return removed;
     }
 
     public void clear() {
@@ -74,6 +86,10 @@
         return set.isEmpty();
     }
 
+    public int count() {
+        return set.size();
+    }
+
     public Comparator<E> getComparator() {
         return null;
     }

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedMap.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedMap.java?rev=799860&r1=799859&r2=799860&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedMap.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedMap.java Sat Aug  1 13:43:17 2009
@@ -116,6 +116,11 @@
         return ((Map<K, V>)collection).containsKey(key);
     }
 
+    @SuppressWarnings("unchecked")
+    public synchronized int count() {
+        return ((Map<K, V>)collection).count();
+    }
+
     public ListenerList<MapListener<K, V>> getMapListeners() {
         return mapListeners;
     }

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=799860&r1=799859&r2=799860&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 Sat Aug  1 13:43:17 2009
@@ -22,7 +22,6 @@
 import org.apache.pivot.collections.SetListener;
 import org.apache.pivot.util.ListenerList;
 
-
 /**
  * Synchronized implementation of the {@link Set} interface.
  *
@@ -69,18 +68,30 @@
         super(set);
     }
 
-    public synchronized void add(E element) {
+    public synchronized boolean add(E element) {
+        boolean added = false;
+
         if (!contains(element)) {
             ((Set<E>)collection).add(element);
+            added = true;
+
             setListeners.elementAdded(this, element);
         }
+
+        return added;
     }
 
-    public synchronized void remove(E element) {
+    public synchronized boolean remove(E element) {
+        boolean removed = false;
+
         if (contains(element)) {
             ((Set<E>)collection).remove(element);
+            removed = true;
+
             setListeners.elementRemoved(this, element);
         }
+
+        return removed;
     }
 
     public synchronized boolean contains(E element) {
@@ -91,6 +102,10 @@
         return ((Set<E>)collection).isEmpty();
     }
 
+    public synchronized int count() {
+        return ((Set<E>)collection).count();
+    }
+
     public ListenerList<SetListener<E>> getSetListeners() {
         return setListeners;
     }

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/immutable/ImmutableMap.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/immutable/ImmutableMap.java?rev=799860&r1=799859&r2=799860&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/immutable/ImmutableMap.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/immutable/ImmutableMap.java Sat Aug  1 13:43:17 2009
@@ -66,6 +66,10 @@
         return map.isEmpty();
     }
 
+    public int count() {
+        return map.count();
+    }
+
     public Comparator<K> getComparator() {
         return null;
     }

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=799860&r1=799859&r2=799860&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 Sat Aug  1 13:43:17 2009
@@ -41,11 +41,11 @@
         this.set = set;
     }
 
-    public void add(E element) {
+    public boolean add(E element) {
         throw new UnsupportedOperationException();
     }
 
-    public void remove(E element) {
+    public boolean remove(E element) {
         throw new UnsupportedOperationException();
     }
 
@@ -61,6 +61,10 @@
         return set.isEmpty();
     }
 
+    public int count() {
+        return set.count();
+    }
+
     public Comparator<E> getComparator() {
         return null;
     }

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/util/concurrent/TaskGroup.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/util/concurrent/TaskGroup.java?rev=799860&r1=799859&r2=799860&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/util/concurrent/TaskGroup.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/util/concurrent/TaskGroup.java Sat Aug  1 13:43:17 2009
@@ -79,22 +79,30 @@
         return null;
     }
 
-    public void add(Task<?> element) {
+    public boolean add(Task<?> element) {
         if (isPending()) {
             throw new IllegalStateException();
         }
 
-        tasks.add(element);
-        count++;
+        boolean added = tasks.add(element);
+        if (added) {
+            count++;
+        }
+
+        return added;
     }
 
-    public void remove(Task<?> element) {
+    public boolean remove(Task<?> element) {
         if (isPending()) {
             throw new IllegalStateException();
         }
 
-        tasks.remove(element);
-        count--;
+        boolean removed = tasks.remove(element);
+        if (removed) {
+            count--;
+        }
+
+        return removed;
     }
 
     public boolean contains(Task<?> element) {

Modified: incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/ArrayListTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/ArrayListTest.java?rev=799860&r1=799859&r2=799860&view=diff
==============================================================================
--- incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/ArrayListTest.java (original)
+++ incubator/pivot/trunk/core/test/org/apache/pivot/collections/test/ArrayListTest.java Sat Aug  1 13:43:17 2009
@@ -67,7 +67,7 @@
 
         assertEquals(list.getLength(), 3);
         assertEquals(list.get(0), "a");
-        assertEquals(list.get(0), "b");
-        assertEquals(list.get(0), "c");
+        assertEquals(list.get(1), "b");
+        assertEquals(list.get(2), "c");
     }
 }

Modified: incubator/pivot/trunk/web/src/org/apache/pivot/web/server/ProxyServlet.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/src/org/apache/pivot/web/server/ProxyServlet.java?rev=799860&r1=799859&r2=799860&view=diff
==============================================================================
--- incubator/pivot/trunk/web/src/org/apache/pivot/web/server/ProxyServlet.java (original)
+++ incubator/pivot/trunk/web/src/org/apache/pivot/web/server/ProxyServlet.java Sat Aug  1 13:43:17 2009
@@ -51,13 +51,13 @@
         private static final long serialVersionUID = 3055851700567335445L;
 
         @Override
-        public void add(String element) {
-            super.add(element.toLowerCase());
+        public boolean add(String element) {
+            return super.add(element.toLowerCase());
         }
 
         @Override
-        public void remove(String element) {
-            super.remove(element.toLowerCase());
+        public boolean remove(String element) {
+            return super.remove(element.toLowerCase());
         }
 
         @Override

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListSelection.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListSelection.java?rev=799860&r1=799859&r2=799860&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListSelection.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListSelection.java Sat Aug  1 13:43:17 2009
@@ -67,20 +67,19 @@
      * A sequence containing the ranges that were added.
      */
     public Sequence<Span> addRange(int start, int end) {
-        assert(start >= 0);
-        assert(end >= start);
+        ArrayList<Span> addedRanges = new ArrayList<Span>();
 
-        ArrayList<Span> added = new ArrayList<Span>();
-
-        Span range = new Span(start, end);
+        Span range = normalize(start, end);
+        assert(range.start >= 0);
 
         if (range.getLength() > 0) {
             int n = selectedRanges.getLength();
 
             if (n == 0) {
                 // The selection is currently empty; append the new range
+                // and add it to the added range list
                 selectedRanges.add(range);
-                added.add(range);
+                addedRanges.add(range);
             } else {
                 // Locate the lower bound of the intersection
                 int i = ArrayList.binarySearch(selectedRanges, range, START_COMPARATOR);
@@ -98,9 +97,9 @@
 
                 if (i == n) {
                     // The new range starts after the last existing selection
-                    // ends; append
+                    // ends; append it and add it to the added range list
                     selectedRanges.add(range);
-                    added.add(range);
+                    addedRanges.add(range);
                 } else {
                     // Locate the upper bound of the intersection
                     int j = ArrayList.binarySearch(selectedRanges, range, END_COMPARATOR);
@@ -120,28 +119,42 @@
 
                     if (i == j) {
                         selectedRanges.insert(range, i);
-                        added.add(range);
+                        addedRanges.add(range);
                     } else {
+                        // Create a new range representing the union of the intersecting ranges
                         Span lowerRange = selectedRanges.get(i);
                         Span upperRange = selectedRanges.get(j - 1);
 
-                        // Remove all redundant ranges
-                        // TODO Add the gaps to the added list
-                        if (i < j) {
-                            selectedRanges.remove(i + 1, j - i - 1);
-                        }
-
-                        // Create a new range representing the union of the intersecting ranges
                         range = new Span(Math.min(range.start, lowerRange.start),
                             Math.max(range.end, upperRange.end));
 
+                        // Add the gaps to the added list
+                        if (range.start < lowerRange.start) {
+                            addedRanges.add(new Span(range.start, lowerRange.start - 1));
+                        }
+
+                        for (int k = i; k < j - 1; k++) {
+                            Span selectedRange = selectedRanges.get(k);
+                            Span nextSelectedRange = selectedRanges.get(k + 1);
+                            addedRanges.add(new Span(selectedRange.end + 1, nextSelectedRange.start - 1));
+                        }
+
+                        if (range.end > upperRange.end) {
+                            addedRanges.add(new Span(upperRange.end + 1, range.end));
+                        }
+
+                        // Remove all redundant ranges
                         selectedRanges.update(i, range);
+
+                        if (i < j) {
+                            selectedRanges.remove(i + 1, j - i - 1);
+                        }
                     }
                 }
             }
         }
 
-        return added;
+        return addedRanges;
     }
 
     /**
@@ -155,12 +168,10 @@
      * A sequence containing the ranges that were removed.
      */
     public Sequence<Span> removeRange(int start, int end) {
-        assert(start >= 0);
-        assert(end >= start);
-
-        ArrayList<Span> removed = new ArrayList<Span>();
+        ArrayList<Span> removedRanges = new ArrayList<Span>();
 
-        Span range = new Span(start, end);
+        Span range = normalize(start, end);
+        assert(range.start >= 0);
 
         if (range.getLength() > 0) {
             int n = selectedRanges.getLength();
@@ -180,12 +191,13 @@
                     // into two ranges
                     selectedRanges.update(i, new Span(lowerRange.start, range.start - 1));
                     selectedRanges.insert(new Span(range.end + 1, lowerRange.end), i + 1);
-                    removed.add(range);
+                    removedRanges.add(range);
                 } else {
+                    Span leadingRemovedRange = null;
                     if (range.start > lowerRange.start) {
                         // Remove the tail of this range
-                        // TODO Add removed tail to removed list
                         selectedRanges.update(i, new Span(lowerRange.start, range.start - 1));
+                        leadingRemovedRange = new Span(range.start, lowerRange.end);
                         i++;
                     }
 
@@ -199,21 +211,34 @@
 
                     Span upperRange = selectedRanges.get(j - 1);
 
+                    Span trailingRemovedRange = null;
                     if (range.end < upperRange.end) {
-                        // Remove the head of this range;
-                        // TODO Add removed head to removed list
-                        selectedRanges.update(j, new Span(range.end + 1, upperRange.end));
+                        // Remove the head of this range
+                        selectedRanges.update(j - 1, new Span(range.end + 1, upperRange.end));
+                        trailingRemovedRange = new Span(upperRange.start, range.end);
                         j--;
                     }
 
                     // Remove all cleared ranges
-                    // TODO Add the removed ranges to the removed list
-                    selectedRanges.remove(i, j - i);
+                    Sequence<Span> clearedRanges = selectedRanges.remove(i, j - i);
+
+                    // Construct the removed range list
+                    if (leadingRemovedRange != null) {
+                        removedRanges.add(leadingRemovedRange);
+                    }
+
+                    for (int k = 0, c = clearedRanges.getLength(); k < c; k++) {
+                        removedRanges.add(clearedRanges.get(k));
+                    }
+
+                    if (trailingRemovedRange != null) {
+                        removedRanges.add(trailingRemovedRange);
+                    }
                 }
             }
         }
 
-        return removed;
+        return removedRanges;
     }
 
     public void clear() {
@@ -336,4 +361,8 @@
             i++;
         }
     }
+
+    public static Span normalize(int start, int end) {
+        return new Span(Math.min(start, end), Math.max(start, end));
+    }
 }

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java?rev=799860&r1=799859&r2=799860&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java Sat Aug  1 13:43:17 2009
@@ -677,16 +677,12 @@
             throw new IndexOutOfBoundsException();
         }
 
-        Sequence<Span> added = listSelection.addRange(start, end);
+        Sequence<Span> addedRanges = listSelection.addRange(start, end);
 
-        // TODO
-        listViewSelectionListeners.selectedRangeAdded(this, start, end);
-        /*
-        for (int i = 0, n = added.getLength(); i < n; i++) {
-            Span addedRange = added.get(i);
+        for (int i = 0, n = addedRanges.getLength(); i < n; i++) {
+            Span addedRange = addedRanges.get(i);
             listViewSelectionListeners.selectedRangeAdded(this, addedRange.start, addedRange.end);
         }
-        */
     }
 
     /**
@@ -731,17 +727,12 @@
             throw new IndexOutOfBoundsException();
         }
 
-        Sequence<Span> removed = listSelection.removeRange(start, end);
+        Sequence<Span> removedRanges = listSelection.removeRange(start, end);
 
-        // TODO
-        listViewSelectionListeners.selectedRangeRemoved(this, start, end);
-
-        /*
-        for (int i = 0, n = removed.getLength(); i < n; i++) {
-            Span removedRange = removed.get(i);
+        for (int i = 0, n = removedRanges.getLength(); i < n; i++) {
+            Span removedRange = removedRanges.get(i);
             listViewSelectionListeners.selectedRangeRemoved(this, removedRange.start, removedRange.end);
         }
-        */
     }
 
     /**

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java?rev=799860&r1=799859&r2=799860&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java Sat Aug  1 13:43:17 2009
@@ -1130,17 +1130,12 @@
             throw new IndexOutOfBoundsException();
         }
 
-        Sequence<Span> added = tableSelection.addRange(start, end);
+        Sequence<Span> addedRanges = tableSelection.addRange(start, end);
 
-        // TODO
-        tableViewSelectionListeners.selectedRangeAdded(this, start, end);
-
-        /*
-        for (int i = 0, n = added.getLength(); i < n; i++) {
-            Span addedRange = added.get(i);
+        for (int i = 0, n = addedRanges.getLength(); i < n; i++) {
+            Span addedRange = addedRanges.get(i);
             tableViewSelectionListeners.selectedRangeAdded(this, addedRange.start, addedRange.end);
         }
-        */
     }
 
     /**
@@ -1185,17 +1180,12 @@
             throw new IndexOutOfBoundsException();
         }
 
-        Sequence<Span> removed = tableSelection.removeRange(start, end);
-
-        // TODO
-        tableViewSelectionListeners.selectedRangeRemoved(this, start, end);
+        Sequence<Span> removedRanges = tableSelection.removeRange(start, end);
 
-        /*
-        for (int i = 0, n = removed.getLength(); i < n; i++) {
-            Span removedRange = removed.get(i);
+        for (int i = 0, n = removedRanges.getLength(); i < n; i++) {
+            Span removedRange = removedRanges.get(i);
             tableViewSelectionListeners.selectedRangeRemoved(this, removedRange.start, removedRange.end);
         }
-        */
     }
 
     /**