Skip to content

Commit

Permalink
Remove deprecated experimental methods
Browse files Browse the repository at this point in the history
  • Loading branch information
FeldrinH committed Dec 22, 2023
1 parent db0ffb5 commit 277b5f5
Showing 1 changed file with 0 additions and 113 deletions.
113 changes: 0 additions & 113 deletions src/main/java/ee/ut/dendroloj/Dendrologist.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,119 +141,6 @@ public static void drawGraph(GraphCanvas<?> graphCanvas) {
GraphGUI.initGenericGUI(uiScale, graph, GenericGraphLayout.autoLayout());
}

/**
* <b>EXPERIMENTAL API</b>
* <p>
* Draws a graph based on the provided adjacency matrix.
* Negative values in the adjacency matrix are treated as missing edges.
*
* @param adjacencyMatrix graph adjacency matrix; value at [i][j] is treated as the weight of the edge from vertex i to vertex j
* @param labels string labels for vertices; pass null to use vertex indices as labels
* @deprecated THIS API IS EXPERIMENTAL AND MAY EVENTUALLY BE REMOVED
*/
@Deprecated
public static void drawGraph(int[][] adjacencyMatrix, String[] labels) {
if (isHeadless()) {
System.err.println("Dendrologist: Running in headless environment. Ignoring call to drawGraph.");
return;
}
for (var row : adjacencyMatrix) {
if (row.length != adjacencyMatrix.length) {
throw new IllegalArgumentException("Adjacency matrix is not square");
}
}

drawAdjacencyMatrixGraph(adjacencyMatrix.length, (from, to) -> {
int value = adjacencyMatrix[from][to];
return value >= 0 ? value : null;
}, labels);
}

/**
* <b>EXPERIMENTAL API</b>
* <p>
* Draws a graph based on the provided adjacency matrix.
* Infinite and NaN values in the adjacency matrix are treated as missing edges.
*
* @param adjacencyMatrix graph adjacency matrix; value at [i][j] is treated as the weight of the edge from vertex i to vertex j
* @param labels string labels for vertices; pass null to use vertex indices as labels
* @deprecated THIS API IS EXPERIMENTAL AND MAY EVENTUALLY BE REMOVED
*/
@Deprecated
public static void drawGraph(double[][] adjacencyMatrix, String[] labels) {
if (isHeadless()) {
System.err.println("Dendrologist: Running in headless environment. Ignoring call to drawGraph.");
return;
}
for (var row : adjacencyMatrix) {
if (row.length != adjacencyMatrix.length) {
throw new IllegalArgumentException("Adjacency matrix is not square");
}
}

drawAdjacencyMatrixGraph(adjacencyMatrix.length, (from, to) -> {
double value = adjacencyMatrix[from][to];
return Double.isFinite(value) ? value : null;
}, labels);
}

/**
* <b>EXPERIMENTAL API</b>
* <p>
* Draws a graph based on the provided adjacency matrix.
* Infinite and NaN values in the adjacency matrix are treated as missing edges.
*
* @param adjacencyMatrix graph adjacency matrix; value at [i][j] is treated as the weight of the edge from vertex i to vertex j
* @param labels string labels for vertices; pass null to use vertex indices as labels
* @deprecated THIS API IS EXPERIMENTAL AND MAY EVENTUALLY BE REMOVED
*/
@Deprecated
public static void drawGraph(float[][] adjacencyMatrix, String[] labels) {
if (isHeadless()) {
System.err.println("Dendrologist: Running in headless environment. Ignoring call to drawGraph.");
return;
}
for (var row : adjacencyMatrix) {
if (row.length != adjacencyMatrix.length) {
throw new IllegalArgumentException("Adjacency matrix is not square");
}
}

drawAdjacencyMatrixGraph(adjacencyMatrix.length, (from, to) -> {
float value = adjacencyMatrix[from][to];
return Float.isFinite(value) ? value : null;
}, labels);
}

private static void drawAdjacencyMatrixGraph(int vertexCount, WeightProvider weights, String[] labels) {
GraphCanvas<Number> graphCanvas = new GraphCanvas<>();
for (int i = 0; i < vertexCount; i++) {
graphCanvas.drawVertex(i, labels == null ? String.valueOf(i) : labels[i]);
Number selfWeight = weights.getWeight(i, i);
if (selfWeight != null && selfWeight.doubleValue() != 0.0) {
graphCanvas.drawEdge(i, i, selfWeight.toString());
}
for (int j = i + 1; j < vertexCount; j++) {
Number weight = weights.getWeight(i, j);
Number backwardsWeight = weights.getWeight(j, i);
if (Objects.equals(weight, backwardsWeight)) {
if (weight != null) graphCanvas.drawEdge(i, j, weight.toString());
} else {
if (weight != null) graphCanvas.drawDirectedEdge(i, j, weight.toString());
if (backwardsWeight != null) graphCanvas.drawDirectedEdge(j, i, backwardsWeight.toString());
}

}
}
Graph graph = GenericGraphLayout.assembleGraph(graphCanvas);
GraphGUI.initGenericGUI(uiScale, graph, GenericGraphLayout.autoLayout());
}

@FunctionalInterface
private interface WeightProvider {
Number getWeight(int from, int to);
}

private static boolean isHeadless() {
return GraphGUI.isHeadless();
}
Expand Down

0 comments on commit 277b5f5

Please sign in to comment.