1- # A DAG in Java
1+ # A ` Dag ` in Java
22
3- ## How do I get it?
4-
5- ### Gradle package from GitHub Packages
6-
7- ``` gradle
8- repositories {
9- mavenCentral()
10- maven {
11- url = uri('https://maven.pkg.github.com/ajs1998/Dag')
12- credentials {
13- username = 'ajs1998'
14- // This is a PAT (Personal Access Token) that only has permission to read/download public GitHub Packages.
15- // This is not the actual password for the account.
16- password = {YOUR GITHUB PAT}
17- }
18- }
19- }
20- ```
21-
22- ``` gradle
23- dependencies {
24- implementation 'me.alexjs:dag:1.10'
25- }
26- ```
27-
28- You need to <a href =" https://github.com/settings/tokens " >create a GitHub Personal Access Token (PAT)</a > to be able to
29- download GitHub Packages. The token only needs the ` read:packages ` permission to work.
30-
31- ### Maven Central package
32-
33- Coming soon
3+ ## What is it?
344
355## What can I do with it?
366
7+ ### Add nodes with (parent, child) relationships to the DAG
8+
379``` java
3810Dag<String > dag = new HashDag<> ();
3911
40- // Add nodes with (parent, child) relationships to the DAG
4112dag. put(" Dorothy" , " Shelby" );
4213dag. put(" Shelby" , " Alex" );
4314dag. put(" Joe" , " Alex" );
15+ ```
4416
45- // Add individual nodes to the DAG
17+ ### Add individual nodes to the DAG
18+
19+ ``` java
4620dag. add(" Clare" );
4721dag. add(" Sarah" );
22+ ```
4823
49- // Find a topologically sorted list of the nodes
50- // Ex: ["Sarah", "Clare", "Dorothy", "Joe", "Shelby", "Alex"]
24+ ### Find a topologically sorted list of the nodes
25+
26+ ``` java
5127List<String > sorted = dag. sort();
28+ ```
5229
53- // Find the root nodes of the DAG
54- // Ex: ["Dorothy", "Joe", "Clare", "Sarah"]
55- Set<String > roots= dag. getRoots();
30+ > ` ["Sarah", "Clare", "Dorothy", "Joe", "Shelby", "Alex"] `
5631
57- // Find the leaf nodes of the DAG
58- // Ex: ["Alex", "Clare", "Sarah"]
32+ ### Find the root nodes of the DAG
33+
34+ ``` java
35+ Set<String > roots = dag. getRoots();
36+ ```
37+
38+ > ` ["Dorothy", "Joe", "Clare", "Sarah"] `
39+
40+ ### Find the leaf nodes of the DAG
41+
42+ ``` java
5943Set<String > leaves = dag. getLeaves();
44+ ```
45+
46+ > ` ["Alex", "Clare", "Sarah"] `
6047
61- // Find the parents of a node
62- // Ex: ["Joe", "Shelby"]
48+ ### Find the parents of a node
49+
50+ ``` java
6351Set<String > parents = dag. getParents(" Alex" );
52+ ```
6453
65- // Find the children of a node
66- // Ex: ["Shelby"]
54+ > ` ["Joe", "Shelby"] `
55+
56+ ### Find the children of a node
57+
58+ ``` java
6759Set<String > children = dag. getChildren(" Dorothy" );
60+ ```
61+
62+ > ` ["Shelby"] `
63+
64+ ### Find the ancestors of a node
6865
69- // Find the ancestors of a node
70- // Ex: ["Joe", "Shelby", "Dorothy"]
66+ ``` java
7167Set<String > ancestors = dag. getAncestors(" Alex" );
68+ ```
69+
70+ > ` ["Joe", "Shelby", "Dorothy"] `
7271
73- // Find the descendants of a node
74- // Ex: ["Shelby", "Alex"]
72+ ### Find the descendants of a node
73+
74+ ``` java
7575Set<String > descendants = dag. getDescendants(" Dorothy" );
76+ ```
7677
77- // Get the Map representation of the DAG
78+ > ` ["Shelby", "Alex"] `
79+
80+ ### Get the Map representation of the DAG
81+
82+ ``` java
7883Map<String , Set<String > > map = dag. toMap();
84+ ```
85+
86+ ### Create a shallow copy
7987
80- // Create a shallow copy
88+ ``` java
8189Dag<String > copy = dag. clone();
8290```
8391
@@ -92,10 +100,40 @@ List<Integer> result = new LinkedList<>();
92100DagUtil . traverse(dag, i - > result. add(i), executorService);
93101```
94102
103+ ## How do I get it?
104+
105+ ### Gradle package from GitHub Packages
106+
107+ ``` gradle
108+ repositories {
109+ mavenCentral()
110+ maven {
111+ url = uri('https://maven.pkg.github.com/ajs1998/Dag')
112+ credentials {
113+ username = {YOUR GITHUB USERNAME}
114+ // This is a PAT (Personal Access Token) that only has permission to read/download public GitHub Packages.
115+ // This is not the actual password for the account.
116+ password = {YOUR GITHUB PAT}
117+ }
118+ }
119+ }
120+ ```
121+
122+ ``` gradle
123+ dependencies {
124+ implementation 'me.alexjs:dag:1.0.0'
125+ }
126+ ```
127+
128+ You need to <a href =" https://github.com/settings/tokens " >create a GitHub Personal Access Token (PAT)</a > to be able to
129+ download GitHub Packages. The token only needs the ` read:packages ` permission to work.
130+
131+ ### Maven Central package
132+
133+ Coming soon
134+
95135## Notes
96136
97137- Flexible ` Dag<T> ` interface so you can write your own implementation
98138- 100% test coverage
99139- 100% Javadoc coverage
100- - I recommend using at least version ` 1.10 ` . Previous versions had little documentation, less test coverage, and fewer
101- features
0 commit comments