Skip to content

Commit

Permalink
feat(docs): add javadocs to the entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Silthus committed Dec 7, 2020
1 parent 4041337 commit 8e35993
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions core/src/main/java/net/silthus/configmapper/ConfigMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>Use the {@link ConfigMap#of(Class)} method to create a new ConfigMap from your class.
* <p>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.
* <p>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.
* <p>Then apply the config to an intance of your config class with {@link #applyTo(Object)}.
* <p><pre>{@code
* ConfigMap.of(MyConfig.class)
* .with(KeyValuePair.of("key", "value")
* .applyTo(new MyConfig());
* }</pre>
*/
public interface ConfigMap {

/**
* Tries to fetch all annotated config fields of the given class.
* <p>The given class must have a parameterless public constructor.
* Use the {@link #of(Class, Supplier)} method if you class has a different signature.
* <p>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.
* <p>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 <TConfig> the type of the config
* @return a ConfigMap of all fields inside the given class
* @throws ConfigurationException if the config class contains invalid field mappings
* @see #of(Class)
*/
static <TConfig> ConfigMap of(Class<TConfig> configClass, Supplier<TConfig> supplier) throws ConfigurationException {

return of(ConfigUtil.getConfigFields(configClass, supplier.get()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.Set;
import java.util.stream.Collectors;

@Log(topic = "net/silthus/configmapper")
@Log(topic = "configmapper")
public final class ConfigUtil {

public static Map<String, ConfigFieldInformation> getConfigFields(Class<?> configClass, FieldNameFormatter formatter) throws ConfigurationException {
Expand Down

0 comments on commit 8e35993

Please sign in to comment.