-
Notifications
You must be signed in to change notification settings - Fork 20
Introduction
ljacqu edited this page Dec 29, 2019
·
4 revisions
ConfigMe provides a stable, null-safe way of managing configuration files. In particular, it has the following features:
- null-safe retrieval of values—no need to ever check for
nulls - you can add comments to your config that will be kept
- easy to extend migration so your configuration can evolve without losing your user's settings
- possibility to reload the entire configuration from the file at any given time
- few dependencies (i.e. small JAR size)
We'll see the details later, but as a short example, you could have properties as such:
public class TitleConfig implements SettingsHolder {
@Comment("The text of the title")
public static final Property<String> TITLE_TEXT =
newProperty("title.text", "-Default-");
@Comment("The size that the title will have")
public static final Property<Integer> TITLE_SIZE =
newProperty("title.size", 10);
}We can retrieve the values from the settings manager, and as mentioned, they are never null:
int titleSize = settingsManager.getProperty(TitleConfig.TITLE_SIZE);
System.out.println("Title size is " + titleSize);It either reads the value from the configuration file, or if it is absent or invalid, it will take the default value that we've defined with the property (in this case: 10).
Saving the configuration to the file will yield something like this:
title:
# The text of the title
text: '-Default-'
# The size that the title will have
size: 10Next: Technical overview
Guide
- Introduction
- Getting started
- Migration service
- Bean properties
- Custom property types
- Technical documentation
Updating
Development (internal)