} else { sectionMap.keySet().removeAll(chainSection.valueList(CHAIN_REMOVE));
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_empty() { PropertySet test = PropertySet.empty(); assertEquals(test.isEmpty(), true); assertEquals(test.contains("unknown"), false); assertEquals(test.valueList("unknown"), ImmutableList.of()); assertThrowsIllegalArg(() -> test.value("unknown")); assertEquals(test.toString(), "{}"); }
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]}"); }
public void test_of_propertyNoEquals() { IniFile test = IniFile.of(CharSource.wrap("[section]\na\n")); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a", ""); assertEquals(test.asMap(), ImmutableMap.of("section", PropertySet.of(keyValues1))); assertEquals(test.section("section"), PropertySet.of(keyValues1)); assertEquals(test.section("section").contains("a"), true); assertEquals(test.section("section").valueList("a"), ImmutableList.of("")); assertEquals(test.section("section").contains("b"), false); assertEquals(test.section("section").keys(), ImmutableSet.of("a")); assertEquals(test.section("section").asMultimap(), ImmutableListMultimap.of("a", "")); assertEquals(test.toString(), "{section={a=[]}}"); }
public void test_of_list() { IniFile test = IniFile.of(CharSource.wrap(INI3)); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a", "x", "a", "y"); assertEquals(test.asMap(), ImmutableMap.of("section", PropertySet.of(keyValues1))); assertEquals(test.section("section"), PropertySet.of(keyValues1)); assertEquals(test.section("section").contains("a"), true); assertThrowsIllegalArg(() -> test.section("section").value("a")); assertEquals(test.section("section").valueList("a"), ImmutableList.of("x", "y")); assertEquals(test.section("section").contains("b"), false); assertEquals(test.section("section").keys(), ImmutableSet.of("a")); assertEquals(test.section("section").asMultimap(), ImmutableListMultimap.of("a", "x", "a", "y")); assertEquals(test.toString(), "{section={a=[x, y]}}"); }
assertEquals(test.section("section").contains("c"), true); assertEquals(test.section("section").value("c"), "x"); assertEquals(test.section("section").valueList("c"), ImmutableList.of("x")); assertEquals(test.section("section").contains("b"), true); assertEquals(test.section("section").value("b"), "y"); assertEquals(test.section("section").valueList("b"), ImmutableList.of("y")); assertEquals(test.section("section").contains("a"), true); assertEquals(test.section("section").value("a"), "z"); assertEquals(test.section("section").valueList("a"), ImmutableList.of("z")); assertEquals(test.section("section").contains("d"), false); assertEquals(test.section("name").contains("a"), true); assertEquals(test.section("name").value("a"), "m"); assertEquals(test.section("name").valueList("a"), ImmutableList.of("m")); assertEquals(test.section("name").contains("b"), true); assertEquals(test.section("name").value("b"), "n"); assertEquals(test.section("name").valueList("b"), ImmutableList.of("n")); assertEquals(test.section("name").contains("c"), false); assertEquals(ImmutableList.copyOf(test.section("name").keys()), ImmutableList.of("a", "b")); assertEquals(test.section("section").valueList("unknown"), ImmutableList.of()); assertThrowsIllegalArg(() -> test.section("section").value("unknown")); assertEquals(test.toString(), "{section={c=[x], b=[y], a=[z]}, name={a=[m], b=[n]}}");
/** * Combines this property set with another. * <p> * This property set takes precedence. * Any order of any additional keys will be retained, with those keys located after the base set of keys. * * @param other the other property set * @return the combined property set */ public PropertySet combinedWith(PropertySet other) { ArgChecker.notNull(other, "other"); if (other.isEmpty()) { return this; } if (isEmpty()) { return other; } // cannot use ArrayListMultiMap as it does not retain the order of the keys // whereas ImmutableListMultimap does retain the order of the keys ImmutableListMultimap.Builder<String, String> map = ImmutableListMultimap.builder(); map.putAll(this.keyValueMap); for (String key : other.keyValueMap.keySet()) { if (!this.contains(key)) { map.putAll(key, other.valueList(key)); } } return new PropertySet(map.build()); }