private static ImmutableMap<String, String> parseAlternates(IniFile config) { if (!config.contains(ALTERNATES_SECTION)) { return ImmutableMap.of(); } Map<String, String> alternates = new HashMap<>(); for (Entry<String, String> entry : config.section(ALTERNATES_SECTION).asMap().entrySet()) { alternates.put(entry.getKey(), entry.getValue()); alternates.putIfAbsent(entry.getKey().toUpperCase(Locale.ENGLISH), entry.getValue()); } return ImmutableMap.copyOf(alternates); }
private static ImmutableMap<String, ImmutableMap<String, String>> parseExternals(IniFile config) { ImmutableMap.Builder<String, ImmutableMap<String, String>> builder = ImmutableMap.builder(); for (String sectionName : config.sections()) { if (sectionName.startsWith(EXTERNALS_SECTION)) { String group = sectionName.substring(EXTERNALS_SECTION.length()); builder.put(group, config.section(sectionName).asMap()); } } return builder.build(); }
private static ImmutableList<Pair<Pattern, String>> parseLenientPatterns(IniFile config) { if (!config.contains(LENIENT_PATTERNS_SECTION)) { return ImmutableList.of(); } List<Pair<Pattern, String>> alternates = new ArrayList<>(); for (Entry<String, String> entry : config.section(LENIENT_PATTERNS_SECTION).asMap().entrySet()) { alternates.add(Pair.of(Pattern.compile(entry.getKey(), Pattern.CASE_INSENSITIVE), entry.getValue())); } return ImmutableList.copyOf(alternates); }
public void test_of_map() { Map<String, String> keyValues = ImmutableMap.of("a", "x", "b", "y"); PropertySet test = PropertySet.of(keyValues); assertEquals(test.isEmpty(), false); assertEquals(test.contains("a"), true); assertEquals(test.value("a"), "x"); assertEquals(test.valueList("a"), ImmutableList.of("x")); assertEquals(test.contains("b"), true); assertEquals(test.value("b"), "y"); assertEquals(test.valueList("b"), ImmutableList.of("y")); assertEquals(test.contains("c"), false); assertEquals(test.keys(), ImmutableSet.of("a", "b")); assertEquals(test.asMap(), ImmutableMap.of("a", "x", "b", "y")); assertEquals(test.asMultimap(), ImmutableListMultimap.of("a", "x", "b", "y")); assertEquals(test.valueList("unknown"), ImmutableSet.of()); assertThrowsIllegalArg(() -> test.value("unknown")); assertEquals(test.toString(), "{a=[x], b=[y]}"); }
public void test_of_multimap() { Multimap<String, String> keyValues = ImmutableMultimap.of("a", "x", "a", "y", "b", "z"); PropertySet test = PropertySet.of(keyValues); assertEquals(test.isEmpty(), false); assertEquals(test.contains("a"), true); assertThrowsIllegalArg(() -> test.value("a")); assertEquals(test.valueList("a"), ImmutableList.of("x", "y")); assertEquals(test.contains("b"), true); assertEquals(test.value("b"), "z"); assertEquals(test.valueList("b"), ImmutableList.of("z")); assertEquals(test.contains("c"), false); assertEquals(test.keys(), ImmutableSet.of("a", "b")); assertEquals(test.asMultimap(), ImmutableListMultimap.of("a", "x", "a", "y", "b", "z")); assertEquals(test.valueList("unknown"), ImmutableSet.of()); assertThrowsIllegalArg(() -> test.asMap()); assertThrowsIllegalArg(() -> test.value("unknown")); assertEquals(test.toString(), "{a=[x, y], b=[z]}"); }