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/11/17 00:43:13 UTC

svn commit: r881058 - in /incubator/pivot/trunk: ./ core/src/org/apache/pivot/collections/ core/src/org/apache/pivot/collections/concurrent/

Author: gbrown
Date: Mon Nov 16 23:43:12 2009
New Revision: 881058

URL: http://svn.apache.org/viewvc?rev=881058&view=rev
Log:
Clean up collection arg checks.

Removed:
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/CollectionArgChecks.java
Modified:
    incubator/pivot/trunk/build.xml
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/Dictionary.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/EnumList.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/EnumMap.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/LinkedList.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedList.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedMap.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedQueue.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedSet.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedStack.java

Modified: incubator/pivot/trunk/build.xml
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/build.xml?rev=881058&r1=881057&r2=881058&view=diff
==============================================================================
--- incubator/pivot/trunk/build.xml (original)
+++ incubator/pivot/trunk/build.xml Mon Nov 16 23:43:12 2009
@@ -149,12 +149,12 @@
         <sequential>
             <mkdir dir="${folder.lib}"/>
             <jar destfile="${folder.lib}/@{jarFile}" index="${compiler.indexJars}">
-            	<metainf dir="${basedir}">
-            		<include name="DISCLAIMER"/>
-            		<include name="LICENSE"/>
-            		<include name="NOTICE"/>
-            		<include name="README"/>
-            	</metainf>
+                <metainf dir="${basedir}">
+                    <include name="DISCLAIMER"/>
+                    <include name="LICENSE"/>
+                    <include name="NOTICE"/>
+                    <include name="README"/>
+                </metainf>
                 <manifest>
                     <attribute name="Sealed" value="true"/>
                     <attribute name="Implementation-Vendor-Id" value="org.apache"/>

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=881058&r1=881057&r2=881058&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 Mon Nov 16 23:43:12 2009
@@ -141,7 +141,7 @@
     }
 
     public ArrayList(int capacity) {
-        ArrayList.validateZeroOrGreater("capacity", capacity);
+        ArrayList.verifyNonNegative("capacity", capacity);
 
         items = new Object[capacity];
     }
@@ -151,7 +151,7 @@
     }
 
     public ArrayList(T[] items, int index, int count) {
-        CollectionArgChecks.verifyNotNull("items", items);
+        verifyNotNull("items", items);
         verifyIndexBounds(index, count, 0, items.length);
 
         this.items = new Object[count];
@@ -165,7 +165,7 @@
     }
 
     public ArrayList(Sequence<T> items, int index, int count) {
-        CollectionArgChecks.verifyNotNull("items", items);
+        verifyNotNull("items", items);
         verifyIndexBounds(index, count, 0, items.getLength());
 
         this.items = new Object[count];
@@ -182,7 +182,7 @@
     }
 
     public ArrayList(ArrayList<T> arrayList, int index, int count) {
-        CollectionArgChecks.verifyNotNull("arrayList", arrayList);
+        verifyNotNull("arrayList", arrayList);
         verifyIndexBounds(index, count, 0, arrayList.length);
 
         items = new Object[count];
@@ -498,20 +498,14 @@
         return sb.toString();
     }
 
-    private static void validateZeroOrGreater(String fieldName, int field) {
-	    if (field < 0) {
-	        throw new IllegalArgumentException(fieldName + " " + field + " cannot be < 0");
-	    }
-	}
-
-	public static <T> void sort(ArrayList<T> arrayList, Comparator<T> comparator) {
+    public static <T> void sort(ArrayList<T> arrayList, Comparator<T> comparator) {
         sort(arrayList, 0, arrayList.getLength(), comparator);
     }
 
     @SuppressWarnings("unchecked")
     public static <T> void sort(ArrayList<T> arrayList, int from, int to, Comparator<T> comparator) {
-        CollectionArgChecks.verifyNotNull("arrayList", arrayList);
-        CollectionArgChecks.verifyNotNull("comparator", comparator);
+        verifyNotNull("arrayList", arrayList);
+        verifyNotNull("comparator", comparator);
 
         Arrays.sort((T[])arrayList.items, from, to, comparator);
 
@@ -529,9 +523,9 @@
 
     @SuppressWarnings("unchecked")
     public static <T> int binarySearch(ArrayList<T> arrayList, T item, Comparator<T> comparator) {
-        CollectionArgChecks.verifyNotNull("arrayList", arrayList);
-        CollectionArgChecks.verifyNotNull("comparator", comparator);
-        CollectionArgChecks.verifyNotNull("item", item);
+        verifyNotNull("arrayList", arrayList);
+        verifyNotNull("comparator", comparator);
+        verifyNotNull("item", item);
 
         int index = Arrays.binarySearch((T[])arrayList.items, 0, arrayList.length, item, comparator);
 
@@ -547,22 +541,36 @@
             }
         });
     }
-    
-    private static void verifyIndexBounds(int index, int boundStart, int boundEnd) {
-        if (index < boundStart || index > boundEnd) {
-            throw new IndexOutOfBoundsException("index " + index + " out of bounds");
+
+    private static void verifyNotNull(String argument, Object value) {
+        if (value == null) {
+            throw new IllegalArgumentException(argument + " cannot be null.");
+        }
+    }
+
+    private static void verifyNonNegative(String argument, int value) {
+        if (value < 0) {
+            throw new IllegalArgumentException(argument + " cannot be negative.");
+        }
+    }
+
+    private static void verifyIndexBounds(int index, int start, int end) {
+        if (index < start || index > end) {
+            throw new IndexOutOfBoundsException("index " + index + " out of bounds.");
         }
     }
 
-    private static void verifyIndexBounds(int index, int count, int boundStart, int boundEnd) {
+    private static void verifyIndexBounds(int index, int count, int start, int end) {
         if (count < 0) {
             throw new IllegalArgumentException();
         }
-        if (index < boundStart) {
-            throw new IndexOutOfBoundsException("index " + index + " out of bounds");
+
+        if (index < start) {
+            throw new IndexOutOfBoundsException("index " + index + " out of bounds.");
         }
-        if (index + count > boundEnd) {
-            throw new IndexOutOfBoundsException("index + count " + index + "," + count + " out of range");
+
+        if (index + count > end) {
+            throw new IndexOutOfBoundsException("index + count " + index + "," + count + " out of range.");
         }
     }
 }

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/Dictionary.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/Dictionary.java?rev=881058&r1=881057&r2=881058&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/Dictionary.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/Dictionary.java Mon Nov 16 23:43:12 2009
@@ -28,7 +28,9 @@
         public final V value;
 
         public Pair(K key, V value) {
-            CollectionArgChecks.verifyNotNull("key", key);
+            if (key == null) {
+                throw new IllegalArgumentException("key cannot be null.");
+            }
 
             this.key = key;
             this.value = value;

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/EnumList.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/EnumList.java?rev=881058&r1=881057&r2=881058&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/EnumList.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/EnumList.java Mon Nov 16 23:43:12 2009
@@ -107,7 +107,9 @@
 
     @Override
     public int indexOf(E item) {
-        CollectionArgChecks.verifyNotNull("item", item);
+        if (item == null) {
+            throw new IllegalArgumentException("item cannot be null.");
+        }
 
         return item.ordinal();
     }

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=881058&r1=881057&r2=881058&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 Mon Nov 16 23:43:12 2009
@@ -44,7 +44,7 @@
     @SuppressWarnings("unchecked")
     @Override
     public V get(E key) {
-        CollectionArgChecks.verifyNotNull("key", key);
+        verifyNotNull("key", key);
 
         return (V)values[key.ordinal()];
     }
@@ -52,7 +52,7 @@
     @SuppressWarnings("unchecked")
     @Override
     public V put(E key, V value) {
-        CollectionArgChecks.verifyNotNull("key", key);
+        verifyNotNull("key", key);
 
         int ordinal = key.ordinal();
         V previousValue = (V)values[ordinal];
@@ -71,7 +71,7 @@
     @SuppressWarnings("unchecked")
     @Override
     public V remove(E key) {
-        CollectionArgChecks.verifyNotNull("key", key);
+        verifyNotNull("key", key);
 
         V value = null;
         if (keySet.contains(key)) {
@@ -128,4 +128,10 @@
     public ListenerList<MapListener<E, V>> getMapListeners() {
         return mapListeners;
     }
+
+    private static void verifyNotNull(String argument, Object value) {
+        if (value == null) {
+            throw new IllegalArgumentException(argument + " cannot be null.");
+        }
+    }
 }

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=881058&r1=881057&r2=881058&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 Mon Nov 16 23:43:12 2009
@@ -650,22 +650,22 @@
 
         return sb.toString();
     }
-    
-    private static void verifyIndexBounds(int index, int boundStart, int boundEnd) {
-        if (index < boundStart || index > boundEnd) {
-            throw new IndexOutOfBoundsException("index " + index + " out of bounds");
+
+    private static void verifyIndexBounds(int index, int start, int end) {
+        if (index < start || index > end) {
+            throw new IndexOutOfBoundsException("index " + index + " out of bounds.");
         }
     }
 
-    private static void verifyIndexBounds(int index, int count, int boundStart, int boundEnd) {
+    private static void verifyIndexBounds(int index, int count, int start, int end) {
         if (count < 0) {
             throw new IllegalArgumentException();
         }
-        if (index < boundStart) {
-            throw new IndexOutOfBoundsException("index " + index + " out of bounds");
+        if (index < start) {
+            throw new IndexOutOfBoundsException("index " + index + " out of bounds.");
         }
-        if (index + count > boundEnd) {
-            throw new IndexOutOfBoundsException("index + count " + index + "," + count + " out of range");
+        if (index + count > end) {
+            throw new IndexOutOfBoundsException("index + count " + index + "," + count + " out of range.");
         }
     }
 }

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedList.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedList.java?rev=881058&r1=881057&r2=881058&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedList.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedList.java Mon Nov 16 23:43:12 2009
@@ -19,14 +19,12 @@
 import java.util.Comparator;
 import java.util.Iterator;
 
-import org.apache.pivot.collections.CollectionArgChecks;
 import org.apache.pivot.collections.List;
 import org.apache.pivot.collections.ListListener;
 import org.apache.pivot.collections.Sequence;
 import org.apache.pivot.util.ImmutableIterator;
 import org.apache.pivot.util.ListenerList;
 
-
 /**
  * Synchronized implementation of the {@link List} interface.
  */
@@ -73,7 +71,9 @@
     private SynchronizedListListenerList<T> listListeners = new SynchronizedListListenerList<T>();
 
     public SynchronizedList(List<T> list) {
-        CollectionArgChecks.verifyNotNull("list", list);
+        if (list == null) {
+            throw new IllegalArgumentException("list cannot be null.");
+        }
 
         this.list = list;
     }

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=881058&r1=881057&r2=881058&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 Mon Nov 16 23:43:12 2009
@@ -19,7 +19,6 @@
 import java.util.Comparator;
 import java.util.Iterator;
 
-import org.apache.pivot.collections.CollectionArgChecks;
 import org.apache.pivot.collections.Map;
 import org.apache.pivot.collections.MapListener;
 import org.apache.pivot.util.ImmutableIterator;
@@ -71,7 +70,9 @@
     private SynchronizedMapListenerList<K, V> mapListeners = new SynchronizedMapListenerList<K, V>();
 
     public SynchronizedMap(Map<K, V> map) {
-        CollectionArgChecks.verifyNotNull("map", map);
+        if (map == null) {
+            throw new IllegalArgumentException("map cannot be null.");
+        }
 
         this.map = map;
     }

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedQueue.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedQueue.java?rev=881058&r1=881057&r2=881058&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedQueue.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedQueue.java Mon Nov 16 23:43:12 2009
@@ -19,13 +19,11 @@
 import java.util.Comparator;
 import java.util.Iterator;
 
-import org.apache.pivot.collections.CollectionArgChecks;
 import org.apache.pivot.collections.Queue;
 import org.apache.pivot.collections.QueueListener;
 import org.apache.pivot.util.ImmutableIterator;
 import org.apache.pivot.util.ListenerList;
 
-
 /**
  * Synchronized implementation of the {@link Queue} interface.
  */
@@ -57,7 +55,9 @@
     private SynchronizedQueueListenerList<T> queueListeners = new SynchronizedQueueListenerList<T>();
 
     public SynchronizedQueue(Queue<T> queue) {
-        CollectionArgChecks.verifyNotNull("queue", queue);
+        if (queue == null) {
+            throw new IllegalArgumentException("queue cannot be null.");
+        }
 
         this.queue = queue;
     }

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=881058&r1=881057&r2=881058&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 Mon Nov 16 23:43:12 2009
@@ -19,7 +19,6 @@
 import java.util.Comparator;
 import java.util.Iterator;
 
-import org.apache.pivot.collections.CollectionArgChecks;
 import org.apache.pivot.collections.Set;
 import org.apache.pivot.collections.SetListener;
 import org.apache.pivot.util.ImmutableIterator;
@@ -66,7 +65,9 @@
     private SynchronizedSetListenerList<E> setListeners = new SynchronizedSetListenerList<E>();
 
     public SynchronizedSet(Set<E> set) {
-        CollectionArgChecks.verifyNotNull("set", set);
+        if (set == null) {
+            throw new IllegalArgumentException("set cannot be null.");
+        }
 
         this.set = set;
     }

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedStack.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedStack.java?rev=881058&r1=881057&r2=881058&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedStack.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedStack.java Mon Nov 16 23:43:12 2009
@@ -19,13 +19,11 @@
 import java.util.Comparator;
 import java.util.Iterator;
 
-import org.apache.pivot.collections.CollectionArgChecks;
 import org.apache.pivot.collections.Stack;
 import org.apache.pivot.collections.StackListener;
 import org.apache.pivot.util.ImmutableIterator;
 import org.apache.pivot.util.ListenerList;
 
-
 /**
  * Synchronized implementation of the {@link Stack} interface.
  */
@@ -57,7 +55,9 @@
     private SynchronizedStackListenerList<T> stackListeners = new SynchronizedStackListenerList<T>();
 
     public SynchronizedStack(Stack<T> stack) {
-        CollectionArgChecks.verifyNotNull("stack", stack);
+        if (stack == null) {
+            throw new IllegalArgumentException("stack cannot be null.");
+        }
 
         this.stack = stack;
     }