Introduce ConstrettoConfigurationFactory

Description

The API provided by ConstrettoBuilder creates very verbose client code when the same ini or properties file is accessed to define constants across various class files.

For example a repetition of the following happens

import static org.springframework.core.io.ResourceLoader.CLASSPATH_URL_PREFIX;

public static final String CONSTANT_A = new ConstrettoBuilder()
.createIniFileConfigurationStore()
.addResource(new DefaultResourceLoader().getResource(CLASSPATH_URL_PREFIX + "file.ini"))
.done()
.getConfiguration()
.evaluateToString("CONSTANT_A");

public static final String CONSTANT_B = new ConstrettoBuilder()
.createIniFileConfigurationStore()
.addResource(new DefaultResourceLoader().getResource(CLASSPATH_URL_PREFIX + "file.ini"))
.done()
.getConfiguration()
.evaluateToString("CONSTANT_B");
The attached factory provides convenience methods to simplify the above code into the following

import static org.springframework.core.io.ResourceLoader.CLASSPATH_URL_PREFIX;
import static no.finntech.commons.constretto.ConstrettoConfigurationFactory.iniFile;

public static final String CONSTANT_A = iniFile(CLASSPATH_URL_PREFIX + "file.ini").evaluateToString("CONSTANT_A");

public static final String CONSTANT_B = iniFile(CLASSPATH_URL_PREFIX + "file.ini").evaluateToString("CONSTANT_B");
It also caches the ConstrettoConfigurations to improve application performance.

Environment

None

Status

Assignee

Kaare Nilsen

Reporter

Kaare Nilsen

Labels

None

Fix versions

Priority

Minor