Skip to content

Commit dc5a985

Browse files
committed
Fix: #74 - forgot removeConnectivityListener
1 parent de78537 commit dc5a985

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

CHANGELOG.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ This file lists modifications introduced by each version.
1414

1515
In order to better match the behavior introduced around `Topology.getOrientation()` in [[issue 49]][issue: #49], the
1616
following modifications have been applied:
17-
* `Topology.addConnectivityListener(ConnectivityListener, Orientation)` has been added
18-
* `Topology.addConnectivityListener(ConnectivityListener, boolean)` has been marked **deprecated**
19-
20-
Please use `Topology.addConnectivityListener(ConnectivityListener, Orientation)` instead.
21-
* `Topology.addConnectivityListener(ConnectivityListener)`'s behavior is changed
22-
23-
It now takes `Topology.getOrientation()` into account when registering a new listener.
24-
Previously, it always registered to undirected events.
17+
* `Topology.addConnectivityListener(ConnectivityListener, Orientation)` and
18+
`Topology.removeConnectivityListener(ConnectivityListener, Orientation)` have been added
19+
* `Topology.addConnectivityListener(ConnectivityListener, boolean)` and
20+
`Topology.removeConnectivityListener(ConnectivityListener, boolean)` have been marked **deprecated**
21+
22+
Please use `Topology.addConnectivityListener(ConnectivityListener, Orientation)` and
23+
`Topology.removeConnectivityListener(ConnectivityListener, Orientation)` instead.
24+
* `Topology.addConnectivityListener(ConnectivityListener)` and
25+
`Topology.removeConnectivityListener(ConnectivityListener)`'s behaviors are changed
26+
27+
They now takes `Topology.getOrientation()` into account when registering/unregistering a listener.
28+
Previously, it always worked on undirected events.
2529

2630
[issue: #74]: https://github.com/jbotsim/JBotSim/issues/74
2731

lib/jbotsim-core/src/main/java/io/jbotsim/core/Topology.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -859,11 +859,11 @@ public void addConnectivityListener(ConnectivityListener listener) {
859859
* @param listener The listener to register.
860860
* @param directed The orientation of links to be listened, as a boolean (<code>true</code> for
861861
* directed, <code>false</code> for undirected).
862-
* @deprecated use {@link Topology#addConnectivityListener(ConnectivityListener, Orientation)} instead.
862+
* @deprecated use {@link #addConnectivityListener(ConnectivityListener, Link.Orientation)} instead.
863863
*/
864864
@Deprecated
865865
public void addConnectivityListener(ConnectivityListener listener, boolean directed) {
866-
addConnectivityListener(listener, isDirected());
866+
addConnectivityListener(listener, directed?Orientation.DIRECTED:Orientation.UNDIRECTED);
867867
}
868868

869869
/**
@@ -882,25 +882,41 @@ public void addConnectivityListener(ConnectivityListener listener, Orientation o
882882
}
883883

884884
/**
885-
* Unregisters the specified connectivity listener from the 'undirected'
886-
* listeners.
885+
* <p>Unregisters the specified connectivity listener according to the orientation of the topology.</p>
886+
*
887+
* <p>The listener will be removed from the list of listeners, according to the current orientation of the topology.</p>
887888
*
888889
* @param listener The listener to unregister.
890+
* @see #getOrientation()
889891
*/
890892
public void removeConnectivityListener(ConnectivityListener listener) {
891-
removeConnectivityListener(listener, false);
893+
removeConnectivityListener(listener, getOrientation());
892894
}
893895

894896
/**
895-
* Unregisters the specified connectivity listener from the listeners
896-
* of the specified type.
897+
* <p>Unregisters the specified connectivity listener from the listeners
898+
* of the specified orientation.</p>
897899
*
898900
* @param listener The listener to unregister.
899-
* @param directed The type of links that this listener was listening
901+
* @param directed The orientation of links that this listener was listening
900902
* (<code>true</code> for directed, <code>false</code> for undirected).
903+
* @deprecated use {@link #removeConnectivityListener(ConnectivityListener, Link.Orientation)} instead.
901904
*/
905+
@Deprecated
902906
public void removeConnectivityListener(ConnectivityListener listener, boolean directed) {
903-
if (directed)
907+
removeConnectivityListener(listener, directed?Orientation.DIRECTED:Orientation.UNDIRECTED);
908+
}
909+
910+
911+
/**
912+
* <p>Unregisters the specified connectivity listener from the listeners
913+
* of the specified orientation.</p>
914+
*
915+
* @param listener The listener to unregister.
916+
* @param orientation The orientation of links that this listener was listening, as an {@link Orientation}.
917+
*/
918+
public void removeConnectivityListener(ConnectivityListener listener, Orientation orientation) {
919+
if (orientation == Orientation.DIRECTED)
904920
cxDirectedListeners.remove(listener);
905921
else
906922
cxUndirectedListeners.remove(listener);

0 commit comments

Comments
 (0)