This is a Spring Framework-based datasource instantiator which reads its properties from the Spring Framework context, i.e. the values are initially all String from properties files and numbers have to be tested for presence and validity.Normally it would be totally superfluous in Spring Framework because the purpose of Spring Framework is to allow Java developers to by-pass it all. However sometimes as in this case, something is different and it has to be done manually.My main concern with this method is the repeated use of the couldBe variable which is an attempt to make it more readable. couldBe is the possibly hopefully valid number retrieved from the properties file, which could in fact be invalid. This is all that is in the class:private final Pattern testForInt =     Pattern.compile(GeneralUtils.REGEX_TEST_FOR_INT);@Bean@ConfigurationProperties(prefix = tardis.datasource)public Map<String, String> dataSourceProperties() {    // Spring populates the map with properties prefixed as above    return new HashMap<>();}@Beanpublic DataSource dataSource() {    Map<String, String> props = dataSourceProperties();    HikariConfig dataSourceConfig = new HikariConfig();    dataSourceConfig.setDriverClassName(props.get(driver));    dataSourceConfig.setUsername(props.get(username));    dataSourceConfig.setPassword(props.get(password));    dataSourceConfig.setJdbcUrl(props.get(url));    String couldBe = props.get(maximumPoolSize);    if (couldBe != null && testForInt.matcher(couldBe).find()) {        dataSourceConfig.setMaximumPoolSize(Integer.valueOf(couldBe));    }    couldBe = props.get(maxLifeTime);    if (couldBe != null && testForInt.matcher(couldBe).find()) {        dataSourceConfig.setMaxLifetime(Long.valueOf(couldBe));    }    couldBe = props.get(leakDetectionThreshold);    if (couldBe != null && testForInt.matcher(couldBe).find()) {        dataSourceConfig.setLeakDetectionThreshold(Long.valueOf(couldBe));    }    couldBe = props.get(connectionTimeout);    if (couldBe != null && testForInt.matcher(couldBe).find()) {        dataSourceConfig.setConnectionTimeout(Long.valueOf(couldBe));    }    return new HikariDataSource(dataSourceConfig);}
Initialising numerical properties from a text-based properties file
java;validation;spring;configuration