diff --git a/core/src/main/java/net/silthus/configmapper/ConfigMap.java b/core/src/main/java/net/silthus/configmapper/ConfigMap.java index a52def2..62d6ae5 100644 --- a/core/src/main/java/net/silthus/configmapper/ConfigMap.java +++ b/core/src/main/java/net/silthus/configmapper/ConfigMap.java @@ -23,13 +23,51 @@ import java.util.Map; import java.util.function.Supplier; +/** + * The ConfigMap holds information about all fields and their type inside your config class. + *
Use the {@link ConfigMap#of(Class)} method to create a new ConfigMap from your class. + *
This will create a new instance of your class and search all fields annotated with @{@link ConfigOption}. + * The fields are then stored as {@link ConfigFieldInformation} and mapped to their keys. + *
Use the {@link #with(KeyValuePair...)} method to load the actual config values into the ConfigMap. + * This is required before you can apply the config to your object. + *
Then apply the config to an intance of your config class with {@link #applyTo(Object)}. + *
{@code + * ConfigMap.of(MyConfig.class) + * .with(KeyValuePair.of("key", "value") + * .applyTo(new MyConfig()); + * }+ */ public interface ConfigMap { + /** + * Tries to fetch all annotated config fields of the given class. + *
The given class must have a parameterless public constructor. + * Use the {@link #of(Class, Supplier)} method if you class has a different signature. + *
Only fields annotated with @{@link ConfigOption} will be cataloged or sub classes that + * have the {@code @ConfigOption} annotation. + * + * @param configClass the config class that should be analyzed for configured fiels + * @return a ConfigMap of all fields inside the given class + * @throws ConfigurationException if the class cannot be instantiated (e.g. no public constructor) + * or if a mapping failed + */ static ConfigMap of(Class> configClass) throws ConfigurationException { return of(ConfigUtil.getConfigFields(configClass)); } + /** + * Creates a new ConfigMap using the given supplier to create the config object. + *
This is the alternative to the {@link #of(Class)} method that does not require a
+ * public parameterless constructor.
+ *
+ * @param configClass the config class that should be analyzed for configured fiels
+ * @param supplier the supplier used to create a fresh instance of the config class
+ * @param