class ExternalResourceUtils {

	public static Map<String, Long> getExternalResources(Configuration config, String suffix) {
		final Set<String> resourceSet = getExternalResourceSet(config);
		LOG.info("Enabled external resources: {}", resourceSet);

		if (resourceSet.isEmpty()) {
			return Collections.emptyMap();
		}

		final Map<String, Long> externalResourceConfigs = new HashMap<>();
		for (String resourceName: resourceSet) {
			final ConfigOption<Long> amountOption =
				key(ExternalResourceOptions.getAmountConfigOptionForResource(resourceName))
					.longType()
					.noDefaultValue();
			final ConfigOption<String> configKeyOption =
				key(ExternalResourceOptions.getSystemConfigKeyConfigOptionForResource(resourceName, suffix))
					.stringType()
					.noDefaultValue();
			final String configKey = config.getString(configKeyOption);
			final Optional<Long> amountOpt = config.getOptional(amountOption);

			if (StringUtils.isNullOrWhitespaceOnly(configKey)) {
				LOG.warn("Could not find valid {} for {}. Will ignore that resource.", configKeyOption.key(), resourceName);
				continue;
			}
			if (!amountOpt.isPresent()) {
				LOG.warn("The amount of the {} should be configured. Will ignore that resource.", resourceName);
				continue;
			} else if (amountOpt.get() <= 0) {
				LOG.warn("The amount of the {} should be positive while finding {}. Will ignore that resource.", amountOpt.get(), resourceName);
				continue;
			}

			if (externalResourceConfigs.put(configKey, amountOpt.get()) != null) {
				LOG.warn("Duplicate config key {} occurred for external resources, the one named {} with amount {} will overwrite the value.", configKey, resourceName, amountOpt);
			} else {
				LOG.info("Add external resource config for {} with key {} value {}.", resourceName, configKey, amountOpt);
			}
		}

		return externalResourceConfigs;
	}

	private  ExternalResourceUtils();

}