Author: rwhitcomb Date: Tue Apr 8 18:08:49 2014 New Revision: 1585800 URL: http://svn.apache.org/r1585800 Log: PIVOT-941: Allow random access to a ListenerList via a "get(int)" method. This is easier in some situations than iterating through the list to find a particular element.
Modified: pivot/branches/2.0.x/core/src/org/apache/pivot/util/ListenerList.java pivot/trunk/core/src/org/apache/pivot/util/ListenerList.java Modified: pivot/branches/2.0.x/core/src/org/apache/pivot/util/ListenerList.java URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/core/src/org/apache/pivot/util/ListenerList.java?rev=1585800&r1=1585799&r2=1585800&view=diff ============================================================================== --- pivot/branches/2.0.x/core/src/org/apache/pivot/util/ListenerList.java (original) +++ pivot/branches/2.0.x/core/src/org/apache/pivot/util/ListenerList.java Tue Apr 8 18:08:49 2014 @@ -155,6 +155,20 @@ public abstract class ListenerList<T> im return last; } + /** + * Get the indexed element in the list. + * + * @return + * the element at position <tt>index</tt> + * or throw an <tt>IndexOutOfBoundsException</tt> + */ + public T get(int index) { + if (index < 0 || index >= last) { + throw new IndexOutOfBoundsException("index " + index + " out of bounds [0," + last + "]."); + } + return list[index]; + } + @Override public Iterator<T> iterator() { return new NodeIterator(); 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=1585800&r1=1585799&r2=1585800&view=diff ============================================================================== --- pivot/trunk/core/src/org/apache/pivot/util/ListenerList.java (original) +++ pivot/trunk/core/src/org/apache/pivot/util/ListenerList.java Tue Apr 8 18:08:49 2014 @@ -149,6 +149,20 @@ public abstract class ListenerList<T> im return last; } + /** + * Get the indexed element in the list. + * + * @return + * the element at position <tt>index</tt> + * or throw an <tt>IndexOutOfBoundsException</tt> + */ + public T get(int index) { + if (index < 0 || index >= last) { + throw new IndexOutOfBoundsException("index " + index + " out of bounds [0," + last + "]."); + } + return list[index]; + } + @Override public Iterator<T> iterator() { return new NodeIterator();