Author: rwhitcomb
Date: Tue Nov  7 19:52:03 2017
New Revision: 1814533

URL: http://svn.apache.org/viewvc?rev=1814533&view=rev
Log:
PIVOT-1011, PIVOT-999, Code cleanup:
* Use "Utils" methods for parameter validation in some
  of the "web" classes.
* Move the QueryListenerList to inside QueryListener, rename
  to just "List" (so users would have "QueryListener.List"
  instead of "QueryListenerList").
* Use "forEach" in this listener for simplicity.

Modified:
    pivot/trunk/web/src/org/apache/pivot/web/Query.java
    pivot/trunk/web/src/org/apache/pivot/web/QueryListener.java

Modified: pivot/trunk/web/src/org/apache/pivot/web/Query.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/web/src/org/apache/pivot/web/Query.java?rev=1814533&r1=1814532&r2=1814533&view=diff
==============================================================================
--- pivot/trunk/web/src/org/apache/pivot/web/Query.java (original)
+++ pivot/trunk/web/src/org/apache/pivot/web/Query.java Tue Nov  7 19:52:03 2017
@@ -35,6 +35,7 @@ import org.apache.pivot.json.JSONSeriali
 import org.apache.pivot.serialization.SerializationException;
 import org.apache.pivot.serialization.Serializer;
 import org.apache.pivot.util.ListenerList;
+import org.apache.pivot.util.Utils;
 
 /**
  * Abstract base class for web queries. A web query is an asynchronous 
operation
@@ -80,50 +81,6 @@ public abstract class Query<V> extends I
         public static final int HTTP_VERSION_NOT_SUPPORTED = 505;
     }
 
-    /**
-     * Query listener list.
-     */
-    private static class QueryListenerList<V> extends 
ListenerList<QueryListener<V>> implements
-        QueryListener<V> {
-        @Override
-        public synchronized void add(QueryListener<V> listener) {
-            super.add(listener);
-        }
-
-        @Override
-        public synchronized void remove(QueryListener<V> listener) {
-            super.remove(listener);
-        }
-
-        @Override
-        public synchronized void connected(Query<V> query) {
-            for (QueryListener<V> listener : this) {
-                listener.connected(query);
-            }
-        }
-
-        @Override
-        public synchronized void requestSent(Query<V> query) {
-            for (QueryListener<V> listener : this) {
-                listener.requestSent(query);
-            }
-        }
-
-        @Override
-        public synchronized void responseReceived(Query<V> query) {
-            for (QueryListener<V> listener : this) {
-                listener.responseReceived(query);
-            }
-        }
-
-        @Override
-        public synchronized void failed(Query<V> query) {
-            for (QueryListener<V> listener : this) {
-                listener.failed(query);
-            }
-        }
-    }
-
     private URL locationContext = null;
     private HostnameVerifier hostnameVerifier = null;
     private Proxy proxy = null;
@@ -137,7 +94,7 @@ public abstract class Query<V> extends I
 
     private Serializer<?> serializer = new JSONSerializer();
 
-    private QueryListenerList<V> queryListeners = new QueryListenerList<>();
+    private QueryListener.List<V> queryListeners = new QueryListener.List<>();
 
     public static final int DEFAULT_PORT = -1;
 
@@ -307,9 +264,7 @@ public abstract class Query<V> extends I
      * @throws IllegalArgumentException if the input is {@code null}.
      */
     public void setSerializer(Serializer<?> serializer) {
-        if (serializer == null) {
-            throw new IllegalArgumentException("Serializer is null.");
-        }
+        Utils.checkNull(serializer, "serializer");
 
         this.serializer = serializer;
     }

Modified: pivot/trunk/web/src/org/apache/pivot/web/QueryListener.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/web/src/org/apache/pivot/web/QueryListener.java?rev=1814533&r1=1814532&r2=1814533&view=diff
==============================================================================
--- pivot/trunk/web/src/org/apache/pivot/web/QueryListener.java (original)
+++ pivot/trunk/web/src/org/apache/pivot/web/QueryListener.java Tue Nov  7 
19:52:03 2017
@@ -16,6 +16,8 @@
  */
 package org.apache.pivot.web;
 
+import org.apache.pivot.util.ListenerList;
+
 /**
  * Query listener interface.
  */
@@ -45,6 +47,33 @@ public interface QueryListener<V> {
         }
     }
 
+    /**
+     * Query listener list.
+     */
+    public static class List<V>
+            extends ListenerList<QueryListener<V>>
+            implements QueryListener<V> {
+        @Override
+        public synchronized void connected(Query<V> query) {
+            forEach(listener -> listener.connected(query));
+        }
+
+        @Override
+        public synchronized void requestSent(Query<V> query) {
+            forEach(listener -> listener.requestSent(query));
+        }
+
+        @Override
+        public synchronized void responseReceived(Query<V> query) {
+            forEach(listener -> listener.responseReceived(query));
+        }
+
+        @Override
+        public synchronized void failed(Query<V> query) {
+            forEach(listener -> listener.failed(query));
+        }
+    }
+
     /**
      * Called when a query has connected to the server but the request has not
      * yet been sent.


Reply via email to