Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UndirectedGraph notification deactivation #3202

Merged
merged 6 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 86 additions & 9 deletions math/src/main/java/com/powsybl/math/graph/UndirectedGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,31 @@ public interface UndirectedGraph<V, E> {
*/
int addVertex();

/**
* Create a new vertex and notify the {@link UndirectedGraphListener}s.
*
* @param notify notify the {@link UndirectedGraphListener}s if true.
* @return the index of the new vertex.
*/
int addVertex(boolean notify);

/**
* If the specified vertex does not exist or is null, create it and notify the {@link UndirectedGraphListener}
*/
default void addVertexIfNotPresent(int v) {
throw new UnsupportedOperationException();
}
void addVertexIfNotPresent(int v);

/**
* If the specified vertex does not exist or is null, create it and notify the {@link UndirectedGraphListener}
*
* @param notify notify the {@link UndirectedGraphListener}s if true.
*/
void addVertexIfNotPresent(int v, boolean notify);

/**
* Check if a specified vertex exists.
* This method throws a {@link com.powsybl.commons.PowsyblException} if the vertex index is invalid (negative).
*/
default boolean vertexExists(int v) {
throw new UnsupportedOperationException();
}
boolean vertexExists(int v);

/**
* Remove the specified vertex and notify the {@link UndirectedGraphListener}s.
Expand All @@ -60,6 +71,16 @@ default boolean vertexExists(int v) {
*/
V removeVertex(int v);

/**
* Remove the specified vertex and notify the {@link UndirectedGraphListener}s.
* This method throws a {@link com.powsybl.commons.PowsyblException} if the vertex doesn't exist or if an edge is connected to this vertex.
*
* @param v the vertex index to remove.
* @param notify notify the {@link UndirectedGraphListener}s if true.
* @return the value attached to the vertex.
*/
V removeVertex(int v, boolean notify);

/**
* Return the number of non-null vertices.
* As the contiguity of vertices is not mandatory, the number of vertices can be less than the highest vertex index.
Expand All @@ -79,6 +100,18 @@ default boolean vertexExists(int v) {
*/
int addEdge(int v1, int v2, E obj);

/**
* Create an edge between the two specified vertices and notify the {@link UndirectedGraphListener}s.
* This method throws a {@link com.powsybl.commons.PowsyblException} if one of the vertices doesn't exist.
*
* @param v1 the first end of the edge.
* @param v2 the second end of the edge.
* @param obj the value attached to the edge.
* @param notify notify the {@link UndirectedGraphListener}s if true.
* @return the index of the new edge.
*/
int addEdge(int v1, int v2, E obj, boolean notify);

/**
* Remove the specified edge and notify the {@link UndirectedGraphListener}s.
* This method thows a {@link com.powsybl.commons.PowsyblException} if the edge doesn't exist.
Expand All @@ -88,11 +121,28 @@ default boolean vertexExists(int v) {
*/
E removeEdge(int e);

/**
* Remove the specified edge and notify the {@link UndirectedGraphListener}s.
* This method thows a {@link com.powsybl.commons.PowsyblException} if the edge doesn't exist.
*
* @param e the edge index to remove.
* @param notify notify the {@link UndirectedGraphListener}s if true.
* @return the value attached to the edge.
*/
E removeEdge(int e, boolean notify);

/**
* Remove all the edges and notify the {@link UndirectedGraphListener}s.
*/
void removeAllEdges();

/**
* Remove all the edges and notify the {@link UndirectedGraphListener}s.
*
* @param notify notify the {@link UndirectedGraphListener}s if true.
*/
void removeAllEdges(boolean notify);

/**
* Return the number of edges.
*
Expand Down Expand Up @@ -147,14 +197,24 @@ default boolean vertexExists(int v) {
V getVertexObject(int v);

/**
* Set the value attached to the specified vertex.
* Set the value attached to the specified vertex and notify the {@link UndirectedGraphListener}s.
* This method throws a {@link com.powsybl.commons.PowsyblException} if the vertex doesn't exist.
*
* @param v the vertex index.
* @param obj the value to attach to the vertex.
*/
void setVertexObject(int v, V obj);

/**
* Set the value attached to the specified vertex and notify the {@link UndirectedGraphListener}s.
* This method throws a {@link com.powsybl.commons.PowsyblException} if the vertex doesn't exist.
*
* @param v the vertex index.
* @param obj the value to attach to the vertex.
* @param notify notify the {@link UndirectedGraphListener}s if true.
*/
void setVertexObject(int v, V obj, boolean notify);

/**
* Return the index of the first vertex that the specified edge is connected to.
* This method throws a {@link com.powsybl.commons.PowsyblException} if the edge doesn't exist.
Expand Down Expand Up @@ -210,11 +270,19 @@ default boolean vertexExists(int v) {
int getEdgeVertex2(int e);

/**
* Remove all the vertices of this graph.
* Remove all the vertices of this graph and notify the {@link UndirectedGraphListener}s.
* This method throws a {@link com.powsybl.commons.PowsyblException} if edges exist.
*/
void removeAllVertices();

/**
* Remove all the vertices of this graph and notify the {@link UndirectedGraphListener}s.
* This method throws a {@link com.powsybl.commons.PowsyblException} if edges exist.
*
* @param notify notify the {@link UndirectedGraphListener}s if true.
*/
void removeAllVertices(boolean notify);

/**
* Return an {@link Iterable} to iterate over the values attached to the edges.
*
Expand Down Expand Up @@ -330,7 +398,16 @@ default boolean vertexExists(int v) {
void print(PrintStream out, Function<V, String> vertexToString, Function<E, String> edgeToString);

/**
* Remove from the vertices which are not connected to any edge, and which have no associated object.
* Remove from the vertices which are not connected to any edge, and which have no associated object
* and notify the {@link UndirectedGraphListener}s.
*/
void removeIsolatedVertices();

/**
* Remove from the vertices which are not connected to any edge, and which have no associated object
* and notify the {@link UndirectedGraphListener}s.
*
* @param notify notify the {@link UndirectedGraphListener}s if true.
*/
void removeIsolatedVertices(boolean notify);
}
Loading