Gadtry
Добро пожаловать в Gadtry!
Gadtry — это набор библиотек инструментов Java. Содержит: IoC, AOP, Mock, Exec, Graph и др.
<dependency>
<groupId>com.github.harbby</groupId>
<artifactId>gadtry</artifactId>
<version>1.9.6</version>
</dependency>
Создание фабрики:
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
Внедрение класса:
public class TestInject
{
@Autowired
private TestInject test;
@Autowired
public TestInject(HashMap set){
System.out.println(set);
}
}
Поддержка концентрической кольцевой модели:
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);
Также может быть объединено с контейнером IOC:
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(bender1 -> {
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);
Передать задачу дочернему процессу:
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 graph = ImmutableGraph.builder()
.addNode("Throwable")
.addNode("Exception")
.addNode("IOException")
.addNode("FileNotFoundException")
``` ```
.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();
graph.printShow("Throwable").forEach(System.out::println);
/
└────Throwable
├────Error
│ ├────NoClassDefFoundError
│ └────OutOfMemoryError
└────Exception
├────RuntimeException
│ ├────IllegalArgumentException
│ └────UnsupportedOperationException
├────FileNotFoundException
└────IOException
Graph<Void,EdgeData> graph = ...create...
List<Route<Void, EdgeData>> routes = graph.searchRuleRoute("A", "C", route -> {
long distances = getRouteDistance(route);
return distances < 30;
});
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Комментарии ( 0 )