class PostmanScenarioIndexerService {

    String extractCountryCodes(String[] path) {
        if (path != null && path.length != 0) {
            String rootFolder = path[0];
            if (StringUtils.isNotEmpty(rootFolder)) {
                final Set<String> countryCodes = Arrays.stream(rootFolder.split("\\+"))
                        .map(String::trim)
                        .filter(StringUtils::isNotEmpty)
                        .collect(Collectors.toCollection(TreeSet::new)); // distinct and sorted

                // If "all" is present, other are redundant
                // Also return "all" if all country-codes were empty strings
                if (countryCodes.isEmpty() || countryCodes.contains(Tag.COUNTRY_ALL)) {
                    countryCodes.clear();
                    countryCodes.add(Tag.COUNTRY_ALL);
                }

                return String.join(Scenario.COUNTRY_CODES_SEPARATOR, countryCodes);
            }
        }

        return Tag.COUNTRY_ALL;
    }

}