Coder Social home page Coder Social logo

jadt's Introduction

Java ADTs

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.

Build from Source

Prerequisites

Assemble JAR File

Fetch the source:

$ git clone https://github.com/2speed/jadt.git

Use the Gradle build task to assemble the JAR file:

$ ./gradlew build

After the build completed, the final build artifact will be located in the jadt/build/libs directory.

Usage

Add classpath Dependency

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:

build.gradle.kts
...
repositories {
    flatDir {
        dirs("path/to/jadt/build/libs")
    }
}

dependencies {
    implementation(":jadt-<version>")
}
...

Graph

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]
        */
    }
}

jadt's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.