11package it .unive .lisa .cfg ;
22
3+ import it .unive .lisa .cfg .edge .Edge ;
4+ import it .unive .lisa .cfg .edge .FalseEdge ;
5+ import it .unive .lisa .cfg .edge .SequentialEdge ;
6+ import it .unive .lisa .cfg .edge .TrueEdge ;
7+ import it .unive .lisa .cfg .statement .NoOp ;
8+ import it .unive .lisa .cfg .statement .Statement ;
9+ import it .unive .lisa .util .collections .ExternalSet ;
10+ import it .unive .lisa .util .collections .ExternalSetCache ;
311import java .util .Collection ;
412import java .util .HashSet ;
513import java .util .Iterator ;
917import java .util .concurrent .ConcurrentHashMap ;
1018import java .util .stream .Collectors ;
1119import java .util .stream .Stream ;
12-
1320import org .apache .commons .lang3 .StringUtils ;
1421import org .apache .commons .lang3 .tuple .Pair ;
1522
16- import it .unive .lisa .cfg .edge .Edge ;
17- import it .unive .lisa .cfg .edge .FalseEdge ;
18- import it .unive .lisa .cfg .edge .SequentialEdge ;
19- import it .unive .lisa .cfg .edge .TrueEdge ;
20- import it .unive .lisa .cfg .statement .NoOp ;
21- import it .unive .lisa .cfg .statement .Statement ;
22- import it .unive .lisa .util .collections .ExternalSet ;
23- import it .unive .lisa .util .collections .ExternalSetCache ;
24-
2523/**
2624 * An adjacency matrix for a graph that has {@link Statement}s as nodes and
2725 * {@link Edge}s as edges. It is represented as a map between a statement and a
@@ -54,8 +52,9 @@ public AdjacencyMatrix() {
5452 }
5553
5654 /**
57- * Copies the given matrix by keeping the same edge {@link ExternalSetCache},
58- * shallow-copying the {@link Statement}s and deep-copying the values.
55+ * Copies the given matrix by keeping the same edge
56+ * {@link ExternalSetCache}, shallow-copying the {@link Statement}s and
57+ * deep-copying the values.
5958 *
6059 * @param other the matrix to copy
6160 */
@@ -85,11 +84,13 @@ public final Collection<Statement> getNodes() {
8584 }
8685
8786 /**
88- * Adds an edge to this matrix
87+ * Adds an edge to this matrix.
8988 *
9089 * @param e the edge to add
91- * @throws UnsupportedOperationException if the source or the destination of the
92- * given edge are not part of this matrix
90+ *
91+ * @throws UnsupportedOperationException if the source or the destination of
92+ * the given edge are not part of
93+ * this matrix
9394 */
9495 public void addEdge (Edge e ) {
9596 if (!matrix .containsKey (e .getSource ()))
@@ -104,13 +105,14 @@ public void addEdge(Edge e) {
104105
105106 /**
106107 * Yields the edge connecting the two given statements, if any. Yields
107- * {@code null} if such edge does not exist, or if one of the two statements is
108- * not inside this matrix.
108+ * {@code null} if such edge does not exist, or if one of the two statements
109+ * is not inside this matrix.
109110 *
110111 * @param source the source statement
111112 * @param destination the destination statement
113+ *
112114 * @return the edge connecting {@code source} to {@code destination}, or
113- * {@code null}
115+ * {@code null}
114116 */
115117 public final Edge getEdgeConnecting (Statement source , Statement destination ) {
116118 if (!matrix .containsKey (source ))
@@ -135,12 +137,13 @@ public final Collection<Edge> getEdges() {
135137 }
136138
137139 /**
138- * Yields the collection of the nodes that are followers of the given one, that
139- * is, all nodes such that there exist an edge in this matrix going from the
140- * given node to such node. Yields {@code null} if the node is not in this
141- * matrix.
140+ * Yields the collection of the nodes that are followers of the given one,
141+ * that is, all nodes such that there exist an edge in this matrix going
142+ * from the given node to such node. Yields {@code null} if the node is not
143+ * in this matrix.
142144 *
143145 * @param node the node
146+ *
144147 * @return the collection of followers
145148 */
146149 public final Collection <Statement > followersOf (Statement node ) {
@@ -151,12 +154,13 @@ public final Collection<Statement> followersOf(Statement node) {
151154 }
152155
153156 /**
154- * Yields the collection of the nodes that are predecessors of the given vertex,
155- * that is, all nodes such that there exist an edge in this matrix going from
156- * such node to the given one. Yields {@code null} if the node is not in this
157- * matrix.
157+ * Yields the collection of the nodes that are predecessors of the given
158+ * vertex, that is, all nodes such that there exist an edge in this matrix
159+ * going from such node to the given one. Yields {@code null} if the node is
160+ * not in this matrix.
158161 *
159162 * @param node the node
163+ *
160164 * @return the collection of predecessors
161165 */
162166 public final Collection <Statement > predecessorsOf (Statement node ) {
@@ -167,17 +171,18 @@ public final Collection<Statement> predecessorsOf(Statement node) {
167171 }
168172
169173 /**
170- * Simplifies this matrix, removing all {@link NoOp}s and rewriting the edge set
171- * accordingly. This method will throw an {@link UnsupportedOperationException}
172- * if one of the {@link NoOp}s has an outgoing edge that is not a
173- * {@link SequentialEdge}, since such statement is expected to always be
174- * sequential.
174+ * Simplifies this matrix, removing all {@link NoOp}s and rewriting the edge
175+ * set accordingly. This method will throw an
176+ * {@link UnsupportedOperationException} if one of the {@link NoOp}s has an
177+ * outgoing edge that is not a {@link SequentialEdge}, since such statement
178+ * is expected to always be sequential.
175179 *
176180 * @throws UnsupportedOperationException if there exists at least one
177- * {@link NoOp} with an outgoing
178- * non-sequential edge, or if one of the
179- * ingoing edges to the {@link NoOp} is
180- * not currently supported.
181+ * {@link NoOp} with an outgoing
182+ * non-sequential edge, or if one
183+ * of the ingoing edges to the
184+ * {@link NoOp} is not currently
185+ * supported.
181186 */
182187 public synchronized void simplify () {
183188 Set <Statement > noops = matrix .keySet ().stream ().filter (k -> k instanceof NoOp ).collect (Collectors .toSet ());
@@ -239,11 +244,13 @@ public boolean equals(Object obj) {
239244 }
240245
241246 /**
242- * Checks if this matrix is effectively equal to the given one, that is, if they
243- * have the same structure while potentially being different instances.
247+ * Checks if this matrix is effectively equal to the given one, that is, if
248+ * they have the same structure while potentially being different instances.
244249 *
245250 * @param other the other matrix
246- * @return {@code true} if this matrix and the given one are effectively equals
251+ *
252+ * @return {@code true} if this matrix and the given one are effectively
253+ * equals
247254 */
248255 public boolean isEqualTo (AdjacencyMatrix other ) {
249256 if (this == other )
0 commit comments