/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package etomica.nbr.list;

import java.util.LinkedList;

public class NeighborListEventManager {

    private final LinkedList<INeighborListListener> intervalListeners = new LinkedList<INeighborListListener>();
    private static final long serialVersionUID = 1L;

    
    public synchronized void addListener(INeighborListListener newListener) {
        if(newListener == null) throw new NullPointerException("Cannot add null as a listener to Neighbor List");
        if (intervalListeners.contains(newListener)) {
            throw new RuntimeException(newListener+" is already an interval action");
        }
        intervalListeners.add(newListener);
    }

    public synchronized void removeListener(INeighborListListener listener) {
        intervalListeners.remove(listener);
    }

    public void neighborsUpdated() {
        for(int i = 0; i < intervalListeners.size(); i++) {
            intervalListeners.get(i).neighborListNeighborsUpdated();
        }
    }
}

@@ -245,20 +245,64 @@
 .util.Li
-nked
+st;%0Aimport java.util.concurrent.CopyOnWriteArray
 List;%0A%0Ap
@@ -359,22 +359,16 @@
 e final 
-Linked
 List%3CINe
@@ -387,25 +387,17 @@
 stener%3E 
-intervalL
+l
 isteners
@@ -407,127 +407,45 @@
 new 
-LinkedList%3CINeighborListListener%3E();%0A    private static final long serialVersionUID = 1L;%0A%0A    %0A    public synchronized
+CopyOnWriteArrayList%3C%3E();%0A%0A    public
  voi
@@ -505,16 +505,17 @@
       if
+ 
 (newList
@@ -527,16 +527,30 @@
 == null)
+ %7B%0A           
  throw n
@@ -636,21 +636,23 @@
     
-if (intervalL
+%7D%0A        if (l
 iste
@@ -731,17 +731,19 @@
 Listener
-+
+ + 
 %22 is alr
@@ -783,33 +783,25 @@
   %7D%0A        
-intervalL
+l
 isteners.add
@@ -837,21 +837,8 @@
 lic 
-synchronized 
 void
@@ -891,33 +891,25 @@
 ) %7B%0A        
-intervalL
+l
 isteners.rem
@@ -982,93 +982,76 @@
  for
-(int i = 0; i %3C intervalListeners.size(); i++) %7B%0A            intervalListeners.get(i)
+ (INeighborListListener listener : listeners) %7B%0A            listener
 .nei

Refactor NeighborListEventManager to use CopyOnWriteArrayList