Coder Social home page Coder Social logo

Gadtry Java CI with Gradle

codecov license language os

Welcome to gadtry !

Gadtry A collection of java tool libraries. Contains: ioc. aop. mock. exec. graph ...

Use

  • maven
<dependency>
    <groupId>com.github.harbby</groupId>
    <artifactId>gadtry</artifactId>
    <version>1.9.9</version>
</dependency>

Ioc

Create Factory:

IocFactory iocFactory = IocFactory.create(binder -> {
    binder.bind(Set.class).by(HashSet.class).withSingle();
    binder.bind(HashSet.class).withSingle();
    binder.bind(List.class).byCreator(ArrayList::new);  //No Single object
    binder.bind(Map.class).byCreator(HashMap::new).withSingle();  //Single object
    binder.bind(TestInject.class).noScope();
});

Set a1 = iocFactory.getInstance(Set.class);
Set a2 = iocFactory.getInstance(Set.class);
Assert.assertEquals(true, a1 == a2); // Single object

Class Inject

public class TestInject
{
    @Autowired
    private TestInject test;

    @Autowired
    public TestInject(HashMap set){
        System.out.println(set);
    }
}

Aop

support concentric ring model

List<String> actions = new ArrayList<>();
Set set = AopGo.proxy(Set.class)
        .byInstance(new HashSet<>())
        .aop(binder -> {
            binder.doBefore(before -> {
                actions.add("before1");
            }).when().size();
            binder.doAround(cut -> {
                actions.add("before2");
                int value = (int) cut.proceed() + 1;
                actions.add("before3");
                return value;
            }).whereMethod(method -> method.getName().startsWith("size"));
            binder.doBefore(before -> {
                actions.add("before4");
            }).when().size();
        })
        .build();
Assert.assertEquals(set.size(), 1);
Assert.assertEquals(MutableList.of("before1", "before2", "before4", "before3"), actions);

can also be combined with ioc container

IocFactory iocFactory = GadTry.create(binder -> {
    binder.bind(Map.class).byCreator(HashMap::new).withSingle();
    binder.bind(HashSet.class).by(HashSet.class).withSingle();
}).aop(binder -> {
    binder.bind(HashSet.class).aop(binder1 -> {
        binder1.doAfter(methodInfo -> {
            System.out.println("after2");
        }).whereMethod(methodInfo -> methodInfo.getName().startsWith("add"));
        binder1.doBefore((info) -> {
            Assert.assertEquals("add", info.getName());
            System.out.println("before1");
        }).methodName("add");
    });
}).setConfigurationProperties(MutableMap.of())
        .initialize();

Set set = iocFactory.getInstance(HashSet.class);

Multiprocessing Exec Fork New Jvm

Throw the task to the child process,

JVMLauncher<Integer> launcher = JVMLaunchers.<Integer>newJvm()
    .setCallable(() -> {
        // this is child process
        System.out.println("************ runing your task ***************");
        return 1;
    })
    .setName("set this jvm jps name")   //set fork jvm jps name
    .setEnvironment("TestEnv", envValue)  //set Fork Jvm Env
    .addUserjars(Collections.emptyList())
    .setXms("16m")
    .setXmx("16m")
    .setConsole((msg) -> System.out.println(msg))
    .build();

Integer out = launcher.startAndGet();
Assert.assertEquals(out.intValue(), 1);

Graph

  • Create ImmutableGraph
Graph graph = ImmutableGraph.builder()
                .addNode("Throwable")
                .addNode("Exception")
                .addNode("IOException")
                .addNode("FileNotFoundException")

                .addNode("RuntimeException")
                .addNode("UnsupportedOperationException")
                .addNode("IllegalArgumentException")

                .addNode("Error")
                .addNode("OutOfMemoryError")
                .addNode("NoClassDefFoundError")

                .addEdge("Throwable", "Exception")
                .addEdge("Throwable", "Error")

                .addEdge("Exception", "IOException")
                .addEdge("Exception", "FileNotFoundException")
                .addEdge("Exception", "RuntimeException")
                .addEdge("RuntimeException", "UnsupportedOperationException")
                .addEdge("RuntimeException", "IllegalArgumentException")

                .addEdge("Error", "OutOfMemoryError")
                .addEdge("Error", "NoClassDefFoundError")
                .create();
  • Print Graph:
graph.printShow("Throwable").forEach(System.out::println);

/
└────Throwable
     ├────Error
     │    ├────NoClassDefFoundError
     │    └────OutOfMemoryError
     └────Exception
          ├────RuntimeException
          │    ├────IllegalArgumentException
          │    └────UnsupportedOperationException
          ├────FileNotFoundException
          └────IOException
  • Search Graph:
    Demo: Search for routes with A to C distances less than 30:
        Graph<Void,EdgeData> graph = ...create...
        List<Route<Void, EdgeData>> routes = graph.searchRuleRoute("A", "C", route -> {
            long distances = getRouteDistance(route);
            return distances < 30;
        });

Useful mailing lists

ideal's Projects

arrow icon arrow

Apache Arrow is a cross-language development platform for in-memory data. It specifies a standardized language-independent columnar memory format for flat and hierarchical data, organized for efficient analytic operations on modern hardware. It also provides computational libraries and zero-copy streaming messaging and interprocess communication. Languages currently supported include C, C++, Java, JavaScript, Python, and Ruby.

asm-intellij-plugin icon asm-intellij-plugin

A plugin for Intellij IDEA that enables the user to see the Byte-code as well as the ASM code.

chatgpt icon chatgpt

🔮 ChatGPT Desktop Application (Mac, Windows and Linux)

git icon git

A fork of Git containing Windows-specific patches.

graal icon graal

GraalVM: Run Programs Faster Anywhere :rocket:

gradle-serviceloader icon gradle-serviceloader

gradle java spi plugin, support scala, link https://github.com/delphyne/gradle-serviceloader-manifest

guava icon guava

Google core libraries for Java

hexo icon hexo

A fast, simple & powerful blog framework, powered by Node.js.

hikaricp icon hikaricp

光 HikariCP・A solid, high-performance, JDBC connection pool at last.

janino icon janino

Janino is a super-small, super-fast Java™ compiler.

jep icon jep

Embed Python in Java

loom icon loom

https://openjdk.java.net/projects/loom/

nalim icon nalim

Fast Java native interface based on JVMCI

presto icon presto

Distributed SQL query engine for big data

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.