@Test public void testToBundleNameToFilesMap() { final Path ignorableBasePath= Paths.get("/some/path/src/main/resources"); final List<File> resourceFiles= ImmutableList.of( ignorableBasePath.resolve("i18n/messages_de.properties").toFile(), ignorableBasePath.resolve("i18n/messages_en.properties").toFile(), ignorableBasePath.resolve("i18n/options.properties").toFile(), ignorableBasePath.resolve("i18n/options_en_US.properties").toFile(), ignorableBasePath.resolve("i18n/options_en_GB.properties").toFile() ); final ResourceBundleContentHelper helper= new ResourceBundleContentHelper(ignorableBasePath); final Map<String, Map<Language, File>> bundleNameToFilesMap = helper.toBundleNameToFilesMap(resourceFiles); System.out.println(bundleNameToFilesMap.keySet()); assertThat(bundleNameToFilesMap.keySet()).containsExactly("i18n/messages", "i18n/options"); assertThat(bundleNameToFilesMap.get("i18n/messages")).containsKeys(Language.of("de"), Language.of("en")); assertThat(bundleNameToFilesMap.get("i18n/messages").get(Language.of("de"))).hasName("messages_de.properties"); assertThat(bundleNameToFilesMap.get("i18n/messages").get(Language.of("en"))).hasName("messages_en.properties"); assertThat(bundleNameToFilesMap.get("i18n/options")).containsKeys(Language.of(""), Language.of("en_US"), Language.of("en_GB")); assertThat(bundleNameToFilesMap.get("i18n/options").get(Language.of(""))).hasName("options.properties"); assertThat(bundleNameToFilesMap.get("i18n/options").get(Language.of("en_US"))).hasName("options_en_US.properties"); assertThat(bundleNameToFilesMap.get("i18n/options").get(Language.of("en_GB"))).hasName("options_en_GB.properties"); }
public Map<String, Map<Language, File>> toBundleNameToFilesMap(final Collection<File> propertyFiles) { Require.nonNull(propertyFiles); final Map<String, Map<Language, File>> result= new LinkedHashMap<>(); for (final File file : propertyFiles) { final Matcher matcher = PATTERN_RESOURCE_BUNDLE_FILE_NAME.matcher(file.getName()); if (matcher.matches()) { final String bundleBasename= matcher.group("BUNDLE"); final String langCode= matcher.group("LOCALE"); final Language language= Language.of(langCode != null ? langCode : ""); final String bundlePrefix= getBundlePrefix(file); final String fullBundleName; if (bundlePrefix == null || bundlePrefix.trim().isEmpty()) { fullBundleName= bundleBasename; } else { fullBundleName= bundlePrefix + "/" + bundleBasename; } if (!result.containsKey(fullBundleName)) { result.put(fullBundleName, new LinkedHashMap<>()); } final Map<Language, File> langToFileMap= result.get(fullBundleName); if (langToFileMap.containsKey(language)) { throw new RuntimeException("Language "+langCode+" already in map. Should never happen."); } langToFileMap.put(language, file); } else { LOGGER.log(Level.WARN, "File {} doesn't match the expected pattern. It will not be processed! Does your file name end with .properties?", file.getAbsolutePath()); } } return result; }
ResourceBundleContentHelper { public Map<String, Map<Language, File>> toBundleNameToFilesMap(final Collection<File> propertyFiles) { Require.nonNull(propertyFiles); final Map<String, Map<Language, File>> result= new LinkedHashMap<>(); for (final File file : propertyFiles) { final Matcher matcher = PATTERN_RESOURCE_BUNDLE_FILE_NAME.matcher(file.getName()); if (matcher.matches()) { final String bundleBasename= matcher.group("BUNDLE"); final String langCode= matcher.group("LOCALE"); final Language language= Language.of(langCode != null ? langCode : ""); final String bundlePrefix= getBundlePrefix(file); final String fullBundleName; if (bundlePrefix == null || bundlePrefix.trim().isEmpty()) { fullBundleName= bundleBasename; } else { fullBundleName= bundlePrefix + "/" + bundleBasename; } if (!result.containsKey(fullBundleName)) { result.put(fullBundleName, new LinkedHashMap<>()); } final Map<Language, File> langToFileMap= result.get(fullBundleName); if (langToFileMap.containsKey(language)) { throw new RuntimeException("Language "+langCode+" already in map. Should never happen."); } langToFileMap.put(language, file); } else { LOGGER.log(Level.WARN, "File {} doesn't match the expected pattern. It will not be processed! Does your file name end with .properties?", file.getAbsolutePath()); } } return result; } }
ResourceBundleContentHelper { public Map<String, Map<Language, File>> toBundleNameToFilesMap(final Collection<File> propertyFiles) { Require.nonNull(propertyFiles); final Map<String, Map<Language, File>> result= new LinkedHashMap<>(); for (final File file : propertyFiles) { final Matcher matcher = PATTERN_RESOURCE_BUNDLE_FILE_NAME.matcher(file.getName()); if (matcher.matches()) { final String bundleBasename= matcher.group("BUNDLE"); final String langCode= matcher.group("LOCALE"); final Language language= Language.of(langCode != null ? langCode : ""); final String bundlePrefix= getBundlePrefix(file); final String fullBundleName; if (bundlePrefix == null || bundlePrefix.trim().isEmpty()) { fullBundleName= bundleBasename; } else { fullBundleName= bundlePrefix + "/" + bundleBasename; } if (!result.containsKey(fullBundleName)) { result.put(fullBundleName, new LinkedHashMap<>()); } final Map<Language, File> langToFileMap= result.get(fullBundleName); if (langToFileMap.containsKey(language)) { throw new RuntimeException("Language "+langCode+" already in map. Should never happen."); } langToFileMap.put(language, file); } else { LOGGER.log(Level.WARN, "File {} doesn't match the expected pattern. It will not be processed! Does your file name end with .properties?", file.getAbsolutePath()); } } return result; } ResourceBundleContentHelper();  ResourceBundleContentHelper(final File ignorableBasePath);  ResourceBundleContentHelper(final Path ignorableBasePath); }
ResourceBundleContentHelper { public Map<String, Map<Language, File>> toBundleNameToFilesMap(final Collection<File> propertyFiles) { Require.nonNull(propertyFiles); final Map<String, Map<Language, File>> result= new LinkedHashMap<>(); for (final File file : propertyFiles) { final Matcher matcher = PATTERN_RESOURCE_BUNDLE_FILE_NAME.matcher(file.getName()); if (matcher.matches()) { final String bundleBasename= matcher.group("BUNDLE"); final String langCode= matcher.group("LOCALE"); final Language language= Language.of(langCode != null ? langCode : ""); final String bundlePrefix= getBundlePrefix(file); final String fullBundleName; if (bundlePrefix == null || bundlePrefix.trim().isEmpty()) { fullBundleName= bundleBasename; } else { fullBundleName= bundlePrefix + "/" + bundleBasename; } if (!result.containsKey(fullBundleName)) { result.put(fullBundleName, new LinkedHashMap<>()); } final Map<Language, File> langToFileMap= result.get(fullBundleName); if (langToFileMap.containsKey(language)) { throw new RuntimeException("Language "+langCode+" already in map. Should never happen."); } langToFileMap.put(language, file); } else { LOGGER.log(Level.WARN, "File {} doesn't match the expected pattern. It will not be processed! Does your file name end with .properties?", file.getAbsolutePath()); } } return result; } ResourceBundleContentHelper();  ResourceBundleContentHelper(final File ignorableBasePath);  ResourceBundleContentHelper(final Path ignorableBasePath); Map<String, Map<Language, File>> toBundleNameToFilesMap(final Collection<File> propertyFiles); }
ResourceBundleContentHelper { public Map<String, Map<Language, File>> toBundleNameToFilesMap(final Collection<File> propertyFiles) { Require.nonNull(propertyFiles); final Map<String, Map<Language, File>> result= new LinkedHashMap<>(); for (final File file : propertyFiles) { final Matcher matcher = PATTERN_RESOURCE_BUNDLE_FILE_NAME.matcher(file.getName()); if (matcher.matches()) { final String bundleBasename= matcher.group("BUNDLE"); final String langCode= matcher.group("LOCALE"); final Language language= Language.of(langCode != null ? langCode : ""); final String bundlePrefix= getBundlePrefix(file); final String fullBundleName; if (bundlePrefix == null || bundlePrefix.trim().isEmpty()) { fullBundleName= bundleBasename; } else { fullBundleName= bundlePrefix + "/" + bundleBasename; } if (!result.containsKey(fullBundleName)) { result.put(fullBundleName, new LinkedHashMap<>()); } final Map<Language, File> langToFileMap= result.get(fullBundleName); if (langToFileMap.containsKey(language)) { throw new RuntimeException("Language "+langCode+" already in map. Should never happen."); } langToFileMap.put(language, file); } else { LOGGER.log(Level.WARN, "File {} doesn't match the expected pattern. It will not be processed! Does your file name end with .properties?", file.getAbsolutePath()); } } return result; } ResourceBundleContentHelper();  ResourceBundleContentHelper(final File ignorableBasePath);  ResourceBundleContentHelper(final Path ignorableBasePath); Map<String, Map<Language, File>> toBundleNameToFilesMap(final Collection<File> propertyFiles);  }