@TuliAutoInitializer
GitHub Created At GitHub last commit Jitpack GitHub Release Date Made by Tulis
## What is it? It's a Java project for initializing classes automatically, a little like Spring uses Beans. You can avoid a mess like this: ```java new Command(); new Command2(); new Event(); new Event2(); ``` and instead use `@Init` annotation to initialize the class (using your constructor configuration) automatically: ```java new AutomaticInitializer.Builder() .setPackageName("(the main package to look for classes)") .addInitVariable(Integer.class, 123) // You can add as many as you want .addInitVariable(MyMainClass.class, mainClassObject) // Or none if you want the default constructor .run(); ``` and for the class: ```java @Init public class Test { public Test(Integer i, MyMainClass myMainClass) { System.out.println("Hi from test! My int value: " + i); myMainClass.registerEvent(this); // You can initialize the event here for example! } } ``` ## Installation Install TuliAutoInitializer by Maven or Gradle using Jitpack, or my self-hosted gitea (on git.tulisiowice.top): ### Repos: ```xml jitpack.io https://jitpack.io ``` ```xml gitea https://git.tulisiowice.top/api/packages/Tulis/maven ``` ### The package: ```xml // Jitpack com.github.Tulis12 TuliAutoInitializer latest-version // If you don't know it, check the Jitpack badge! ``` ```xml // Gitea dev.tulis TuliAutoInitializer latest-version ``` ## All annotation's parameters ### `initializeWithoutParameters = true` Tries to use the default constructor of class (the one without parameters), defaults to false (using the configuration of the builder). ```java @Init(initializeWithoutParameters = true) public class Test { public Test() { System.out.println("Will use this instead!"); } public Test(Integer i1, Integer i2) { System.out.println("Won't use this!"); } } ``` The Initializer won't force use of default constructor (for example, if its private), will instead throw `NoSuchMethodException`, `IllegalAccessException` respectively. ### `initializeOnlyWith = { Integer.class, MyMainClass.class }` Will use only those two, even if there are more. In case of multiple values with the same class, will take the one first added in the builder, defaults to an empty array (will use the configuration of builder). ```java @Init(initializeOnlyWith = { Integer.class, MyMainClass.class }) public class Test { public Test(Integer integer, MyMainClass myMainClass) { System.out.println("Will use this, even if in builder there is more."); } public Test(Integer integer, String string, MyMainClass myMainClass) { System.out.println("Won't use this!"); } } ``` Remember, if there is no class (with a value) provided in the builder, but you will try to use it here, the builder will throw `MissingParameterException`. ## License Released under the MIT license.