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

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

Author: noelgrandin
Date: Sat Nov 14 05:45:16 2009
New Revision: 836127

URL: http://svn.apache.org/viewvc?rev=836127&view=rev
Log:
move argument checking methods into caller classes, rename to use verifyXXX() style

Modified:
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/ArrayList.java
    incubator/pivot/trunk/core/src/org/apache/pivot/collections/CollectionArgChecks.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/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=836127&r1=836126&r2=836127&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 Sat Nov 14 05:45:16 2009
@@ -141,7 +141,7 @@
     }
 
     public ArrayList(int capacity) {
-        CollectionArgChecks.zeroOrGreater("capacity", capacity);
+        ArrayList.validateZeroOrGreater("capacity", capacity);
 
         items = new Object[capacity];
     }
@@ -151,8 +151,8 @@
     }
 
     public ArrayList(T[] items, int index, int count) {
-        CollectionArgChecks.notNull("items", items);
-        CollectionArgChecks.indexBounds(index, count, 0, items.length);
+        CollectionArgChecks.verifyNotNull("items", items);
+        verifyIndexBounds(index, count, 0, items.length);
 
         this.items = new Object[count];
         System.arraycopy(items, index, this.items, 0, count);
@@ -165,8 +165,8 @@
     }
 
     public ArrayList(Sequence<T> items, int index, int count) {
-        CollectionArgChecks.notNull("items", items);
-        CollectionArgChecks.indexBounds(index, count, 0, items.getLength());
+        CollectionArgChecks.verifyNotNull("items", items);
+        verifyIndexBounds(index, count, 0, items.getLength());
 
         this.items = new Object[count];
 
@@ -182,8 +182,8 @@
     }
 
     public ArrayList(ArrayList<T> arrayList, int index, int count) {
-        CollectionArgChecks.notNull("arrayList", arrayList);
-        CollectionArgChecks.indexBounds(index, count, 0, arrayList.length);
+        CollectionArgChecks.verifyNotNull("arrayList", arrayList);
+        verifyIndexBounds(index, count, 0, arrayList.length);
 
         items = new Object[count];
         length = count;
@@ -220,7 +220,7 @@
     }
 
     private void insert(T item, int index, boolean validate) {
-        CollectionArgChecks.indexBounds(index, 0, length);
+        verifyIndexBounds(index, 0, length);
 
         if (comparator != null
             && validate) {
@@ -250,7 +250,7 @@
     @SuppressWarnings("unchecked")
     @Override
     public T update(int index, T item) {
-        CollectionArgChecks.indexBounds(index, 0, length - 1);
+        verifyIndexBounds(index, 0, length - 1);
 
         T previousItem = (T)items[index];
 
@@ -295,7 +295,7 @@
     @SuppressWarnings("unchecked")
     @Override
     public Sequence<T> remove(int index, int count) {
-        CollectionArgChecks.indexBounds(index, count, 0, length);
+        verifyIndexBounds(index, count, 0, length);
 
         ArrayList<T> removed = new ArrayList<T>((T[])items, index, count);
 
@@ -336,7 +336,7 @@
     @SuppressWarnings("unchecked")
     @Override
     public T get(int index) {
-        CollectionArgChecks.indexBounds(index, 0, length);
+        verifyIndexBounds(index, 0, length);
 
         return (T)items[index];
     }
@@ -498,14 +498,20 @@
         return sb.toString();
     }
 
-    public static <T> void sort(ArrayList<T> arrayList, Comparator<T> comparator) {
+    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) {
         sort(arrayList, 0, arrayList.getLength(), comparator);
     }
 
     @SuppressWarnings("unchecked")
     public static <T> void sort(ArrayList<T> arrayList, int from, int to, Comparator<T> comparator) {
-        CollectionArgChecks.notNull("arrayList", arrayList);
-        CollectionArgChecks.notNull("comparator", comparator);
+        CollectionArgChecks.verifyNotNull("arrayList", arrayList);
+        CollectionArgChecks.verifyNotNull("comparator", comparator);
 
         Arrays.sort((T[])arrayList.items, from, to, comparator);
 
@@ -523,9 +529,9 @@
 
     @SuppressWarnings("unchecked")
     public static <T> int binarySearch(ArrayList<T> arrayList, T item, Comparator<T> comparator) {
-        CollectionArgChecks.notNull("arrayList", arrayList);
-        CollectionArgChecks.notNull("comparator", comparator);
-        CollectionArgChecks.notNull("item", item);
+        CollectionArgChecks.verifyNotNull("arrayList", arrayList);
+        CollectionArgChecks.verifyNotNull("comparator", comparator);
+        CollectionArgChecks.verifyNotNull("item", item);
 
         int index = Arrays.binarySearch((T[])arrayList.items, 0, arrayList.length, item, comparator);
 
@@ -541,4 +547,22 @@
             }
         });
     }
+    
+    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 count, int boundStart, int boundEnd) {
+        if (count < 0) {
+            throw new IllegalArgumentException();
+        }
+        if (index < boundStart) {
+            throw new IndexOutOfBoundsException("index " + index + " out of bounds");
+        }
+        if (index + count > boundEnd) {
+            throw new IndexOutOfBoundsException("index + count " + index + "," + count + " out of range");
+        }
+    }
 }

Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/CollectionArgChecks.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/CollectionArgChecks.java?rev=836127&r1=836126&r2=836127&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/CollectionArgChecks.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/CollectionArgChecks.java Sat Nov 14 05:45:16 2009
@@ -22,33 +22,10 @@
  */
 public class CollectionArgChecks {
 
-    public static void notNull(String fieldName, Object field) {
+    public static void verifyNotNull(String fieldName, Object field) {
         if (field == null) {
             throw new IllegalArgumentException(fieldName + " cannot be null");
         }
     }
 
-    public static void zeroOrGreater(String fieldName, int field) {
-        if (field < 0) {
-            throw new IllegalArgumentException(fieldName + " " + field + " cannot be < 0");
-        }
-    }
-
-    public static void indexBounds(int index, int boundStart, int boundEnd) {
-        if (index < boundStart || index > boundEnd) {
-            throw new IndexOutOfBoundsException("index " + index + " out of bounds");
-        }
-    }
-
-    public static void indexBounds(int index, int count, int boundStart, int boundEnd) {
-        if (count < 0) {
-            throw new IllegalArgumentException();
-        }
-        if (index < boundStart) {
-            throw new IndexOutOfBoundsException("index " + index + " out of bounds");
-        }
-        if (index + count > boundEnd) {
-            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=836127&r1=836126&r2=836127&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 Sat Nov 14 05:45:16 2009
@@ -28,7 +28,7 @@
         public final V value;
 
         public Pair(K key, V value) {
-            CollectionArgChecks.notNull("key", key);
+            CollectionArgChecks.verifyNotNull("key", key);
 
             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=836127&r1=836126&r2=836127&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 Sat Nov 14 05:45:16 2009
@@ -107,7 +107,7 @@
 
     @Override
     public int indexOf(E item) {
-        CollectionArgChecks.notNull("item", item);
+        CollectionArgChecks.verifyNotNull("item", item);
 
         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=836127&r1=836126&r2=836127&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 Nov 14 05:45:16 2009
@@ -44,7 +44,7 @@
     @SuppressWarnings("unchecked")
     @Override
     public V get(E key) {
-        CollectionArgChecks.notNull("key", key);
+        CollectionArgChecks.verifyNotNull("key", key);
 
         return (V)values[key.ordinal()];
     }
@@ -52,7 +52,7 @@
     @SuppressWarnings("unchecked")
     @Override
     public V put(E key, V value) {
-        CollectionArgChecks.notNull("key", key);
+        CollectionArgChecks.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.notNull("key", key);
+        CollectionArgChecks.verifyNotNull("key", key);
 
         V value = null;
         if (keySet.contains(key)) {

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=836127&r1=836126&r2=836127&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 Sat Nov 14 05:45:16 2009
@@ -305,7 +305,7 @@
 
     @Override
     public void insert(T item, int index) {
-        CollectionArgChecks.indexBounds(index, 0, length);
+        verifyIndexBounds(index, 0, length);
 
         Node<T> next = null;
         Node<T> previous = null;
@@ -345,7 +345,7 @@
 
     @Override
     public T update(int index, T item) {
-        CollectionArgChecks.indexBounds(index, 0, length - 1);
+        verifyIndexBounds(index, 0, length - 1);
 
         // Get the previous item at index
         Node<T> node = getNode(index);
@@ -403,7 +403,7 @@
 
     @Override
     public Sequence<T> remove(int index, int count) {
-        CollectionArgChecks.indexBounds(index, count, 0, length);
+        verifyIndexBounds(index, count, 0, length);
 
         LinkedList<T> removed = new LinkedList<T>();
 
@@ -470,7 +470,7 @@
 
     @Override
     public T get(int index) {
-        CollectionArgChecks.indexBounds(index, 0, length - 1);
+        verifyIndexBounds(index, 0, length - 1);
 
         Node<T> node = getNode(index);
         return node.item;
@@ -650,4 +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 count, int boundStart, int boundEnd) {
+        if (count < 0) {
+            throw new IllegalArgumentException();
+        }
+        if (index < boundStart) {
+            throw new IndexOutOfBoundsException("index " + index + " out of bounds");
+        }
+        if (index + count > boundEnd) {
+            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=836127&r1=836126&r2=836127&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 Sat Nov 14 05:45:16 2009
@@ -73,7 +73,7 @@
     private SynchronizedListListenerList<T> listListeners = new SynchronizedListListenerList<T>();
 
     public SynchronizedList(List<T> list) {
-        CollectionArgChecks.notNull("list", list);
+        CollectionArgChecks.verifyNotNull("list", list);
 
         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=836127&r1=836126&r2=836127&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 Nov 14 05:45:16 2009
@@ -71,7 +71,7 @@
     private SynchronizedMapListenerList<K, V> mapListeners = new SynchronizedMapListenerList<K, V>();
 
     public SynchronizedMap(Map<K, V> map) {
-        CollectionArgChecks.notNull("map", map);
+        CollectionArgChecks.verifyNotNull("map", map);
 
         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=836127&r1=836126&r2=836127&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 Sat Nov 14 05:45:16 2009
@@ -57,7 +57,7 @@
     private SynchronizedQueueListenerList<T> queueListeners = new SynchronizedQueueListenerList<T>();
 
     public SynchronizedQueue(Queue<T> queue) {
-        CollectionArgChecks.notNull("queue", queue);
+        CollectionArgChecks.verifyNotNull("queue", queue);
 
         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=836127&r1=836126&r2=836127&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 Nov 14 05:45:16 2009
@@ -66,7 +66,7 @@
     private SynchronizedSetListenerList<E> setListeners = new SynchronizedSetListenerList<E>();
 
     public SynchronizedSet(Set<E> set) {
-        CollectionArgChecks.notNull("set", set);
+        CollectionArgChecks.verifyNotNull("set", set);
 
         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=836127&r1=836126&r2=836127&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 Sat Nov 14 05:45:16 2009
@@ -57,7 +57,7 @@
     private SynchronizedStackListenerList<T> stackListeners = new SynchronizedStackListenerList<T>();
 
     public SynchronizedStack(Stack<T> stack) {
-        CollectionArgChecks.notNull("stack", stack);
+        CollectionArgChecks.verifyNotNull("stack", stack);
 
         this.stack = stack;
     }