You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2021/02/16 00:10:46 UTC

svn commit: r1886557 - /pivot/trunk/core/src/org/apache/pivot/util/ListenerList.java

Author: rwhitcomb
Date: Tue Feb 16 00:10:45 2021
New Revision: 1886557

URL: http://svn.apache.org/viewvc?rev=1886557&view=rev
Log:
Changes to reduce "checkstyle" violations.

Modified:
    pivot/trunk/core/src/org/apache/pivot/util/ListenerList.java

Modified: pivot/trunk/core/src/org/apache/pivot/util/ListenerList.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/ListenerList.java?rev=1886557&r1=1886556&r2=1886557&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/ListenerList.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/ListenerList.java Tue Feb 16 00:10:45 2021
@@ -34,13 +34,13 @@ public abstract class ListenerList<T> im
 
     /**
      * Iterator through the current array of elements.
-     *
-     * @param <T> The listener type to iterate over.
      */
     private class NodeIterator implements Iterator<T> {
+        /** The current position in the list for the iteration. */
         private int index;
 
-        public NodeIterator() {
+        /** Construct and start iteration at the beginning. */
+        NodeIterator() {
             this.index = 0;
         }
 
@@ -65,14 +65,17 @@ public abstract class ListenerList<T> im
         }
     }
 
+    /** We don't expect many listeners (1 or 2 typically), so start off with this size. */
     private static final int DEFAULT_SIZE = 5;
 
-    // The current array of items (some of which are null)
-    // All non-null objects are at the beginning of the array
-    // and the array is reorganized on "remove"
-    @SuppressWarnings({ "unchecked" })
+    /**
+     * The current array of items (some of which are null).
+     * <p> All non-null objects are at the beginning of the array
+     * and the array is reorganized on "remove".
+     */
+    @SuppressWarnings("unchecked")
     private T[] list = (T[]) new Object[DEFAULT_SIZE];
-    // The current length of the active list
+    /** The current length of the active list. */
     private int last = 0;
 
     /**
@@ -110,7 +113,7 @@ public abstract class ListenerList<T> im
 
         // If no slot is available, increase the size of the array
         if (last >= list.length) {
-            @SuppressWarnings({ "unchecked" })
+            @SuppressWarnings("unchecked")
             T[] newList = (T[]) new Object[list.length + DEFAULT_SIZE];
             if (index > 0) {
                 System.arraycopy(list, 0, newList, 0, index);
@@ -151,7 +154,14 @@ public abstract class ListenerList<T> im
         list[--last] = null;
     }
 
-    private int indexOf(T listener) {
+    /**
+     * Search for the given listener in the list.
+     *
+     * @param listener The listener to find.
+     * @return The index {@code >= 0} of the listener if found, or {@code -1}
+     * if not found.
+     */
+    private int indexOf(final T listener) {
         Utils.checkNull(listener, "listener");
 
         for (int i = 0; i < last; i++) {
@@ -205,12 +215,12 @@ public abstract class ListenerList<T> im
     }
 
     @Override
-    public Iterator<T> iterator() {
+    public final Iterator<T> iterator() {
         return new NodeIterator();
     }
 
     @Override
-    public String toString() {
+    public final String toString() {
         StringBuilder sb = new StringBuilder(getClass().getSimpleName());
         return StringUtils.append(sb, this).toString();
     }