Skip to content

Commit 977b625

Browse files
committed
Allow method chaining only for property setters
1 parent ab8e921 commit 977b625

File tree

2 files changed

+55
-24
lines changed

2 files changed

+55
-24
lines changed

src/main/java/org/algorithm_visualizer/GraphTracer.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,31 @@ public GraphTracer weighted() {
2525
return this;
2626
}
2727

28+
public GraphTracer layoutCircle() {
29+
command("layoutCircle", new Object[]{});
30+
return this;
31+
}
32+
33+
public GraphTracer layoutTree(Object root, boolean sorted) {
34+
command("layoutTree", new Object[]{root, sorted});
35+
return this;
36+
}
37+
38+
public GraphTracer layoutTree(Object root) {
39+
command("layoutTree", new Object[]{root});
40+
return this;
41+
}
42+
43+
public GraphTracer layoutTree() {
44+
command("layoutTree", new Object[]{});
45+
return this;
46+
}
47+
48+
public GraphTracer layoutRandom() {
49+
command("layoutRandom", new Object[]{});
50+
return this;
51+
}
52+
2853
public void addNode(Object id, double weight, double x, double y, int visitedCount, int selectedCount) {
2954
command("addNode", new Object[]{id, weight, x, y, visitedCount, selectedCount});
3055
}
@@ -113,26 +138,6 @@ public void removeEdge(Object source, Object target) {
113138
command("removeEdge", new Object[]{source, target});
114139
}
115140

116-
public void layoutCircle() {
117-
command("layoutCircle", new Object[]{});
118-
}
119-
120-
public void layoutTree(Object root, boolean sorted) {
121-
command("layoutTree", new Object[]{root, sorted});
122-
}
123-
124-
public void layoutTree(Object root) {
125-
command("layoutTree", new Object[]{root});
126-
}
127-
128-
public void layoutTree() {
129-
command("layoutTree", new Object[]{});
130-
}
131-
132-
public void layoutRandom() {
133-
command("layoutRandom", new Object[]{});
134-
}
135-
136141
public void visit(Object target, Object source, double weight) {
137142
command("visit", new Object[]{target, source, weight});
138143
}
Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
11
package org.algorithm_visualizer;
22

3+
import org.algorithm_visualizer.*;
4+
35
class Test {
6+
static GraphTracer tracer = new GraphTracer();
7+
tracer.log(new LogTracer());
8+
static int G[][] = { // G[i][j] indicates whether the path from the i-th node to the j-th node exists or not
9+
{0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0},
10+
{0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0},
11+
{0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0},
12+
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0},
13+
{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1},
14+
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
15+
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
16+
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
17+
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
18+
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
19+
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
20+
};
21+
22+
static void DFS(int node, int parent) { // node = current node, parent = previous node
23+
tracer.visit(node, parent).delay();
24+
for (int i = 0; i < G[node].length; i++) {
25+
if (G[node][i] == 1) { // if current node has the i-th node as a child
26+
DFS(i, node); // recursively call DFS
27+
}
28+
}
29+
}
30+
431
public static void main(String[] args) {
5-
ChartTracer chartTracer = new ChartTracer();
6-
chartTracer.set(new Object[]{});
7-
Layout.setRoot(new VerticalLayout(new Commander[]{chartTracer}));
32+
tracer.set(G).layoutTree(0).delay();
33+
DFS(0, -1);
834
}
9-
}
35+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy