Throughout the course of my personal and professional work over the years, I have accumulated a sizable library of code that has proven to be useful in several use cases. Chief of among this assortment are data structures that, for some reason or other, were/are not part of the standard library. Of course there are excellent alternatives like Google’s Guava, Eclipse Collections, or Apache Commons Collections, but they tend to include the kitchen sink when most of the time all that I needed was a fork and maybe a knife. As time allows, I will update my code and push it here.
-
The Git version management tool
-
The Java Development Kit (JDK), version 14 or later
-
The Gradle build automation tool, version 6.3 or later
Add the jadt-<version>.jar
file as a classpath dependency to your favorite JVM project. For example, if using Gradle, the following could be added to the Gradle build file to use jadt-<version>.jar
file as a local dependency:
...
repositories {
flatDir {
dirs("path/to/jadt/build/libs")
}
}
dependencies {
implementation(":jadt-<version>")
}
...
Simple example using a DirectedGraph
with char
vertices.
import static java.lang.System.out;
import griz.jadt.graph.DirectedGraph;
import griz.jadt.graph.Edge;
import griz.jadt.graph.SimpleEdge;
public class DiGraphExample {
public static void main(String... args) {
// Declare a directed graph instance for character vertices
final var diGraph = new DirectedGraph<Character, Edge<Character>>();
// Add character vertices
diGraph.addEdge(new SimpleEdge<>('a', 'b'));
diGraph.addEdge(new SimpleEdge<>('b', 'd'));
diGraph.addEdge(new SimpleEdge<>('d', 'c'));
// Print the state of the directed graph
out.println(diGraph);
/*
Output:
a, outgoing edges: SimpleEdge { a -> b }
b, outgoing edges: SimpleEdge { b -> d }
c, outgoing edges: none
d, outgoing edges: SimpleEdge { d -> c }
*/
// Print the topological order
out.println(diGraph.topologicalOrder());
/*
Output:
[a, b, d, c]
*/
}
}