Skip to content

Commit

Permalink
Use addIfAbsent instead of checking if an element is contained
Browse files Browse the repository at this point in the history
Relates to #32988
  • Loading branch information
s1monw committed Aug 23, 2018
1 parent 4664068 commit b6fca90
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.io.Closeable;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;
Expand Down Expand Up @@ -85,9 +84,7 @@ public ConnectionManager(Settings settings, Transport transport, ThreadPool thre
}

public void addListener(TransportConnectionListener listener) {
if (connectionListener.listeners.contains(listener) == false) {
this.connectionListener.listeners.add(listener);
}
this.connectionListener.listeners.addIfAbsent(listener);
}

public void removeListener(TransportConnectionListener listener) {
Expand Down Expand Up @@ -297,7 +294,7 @@ public void onFailure(Exception e) {

private static final class DelegatingNodeConnectionListener implements TransportConnectionListener {

private final List<TransportConnectionListener> listeners = new CopyOnWriteArrayList<>();
private final CopyOnWriteArrayList<TransportConnectionListener> listeners = new CopyOnWriteArrayList<>();

@Override
public void onNodeDisconnected(DiscoveryNode key) {
Expand Down

0 comments on commit b6fca90

Please sign in to comment.