/** * Replaces the values for the given key with the given values. * * @param key The key * @param values The new values * @return This object */ public FluentStringsMap replaceWith(final String key, final String... values) { return replaceWith(key, Arrays.asList(values)); }
/** * Replace the values for all keys from the given map that are also present in this object, with the values from the given map. * All key-values from the given object that are not present in this object, will be added to it. * * @param src The source object * @return This object */ public FluentStringsMap replaceAll(FluentStringsMap src) { if (src != null) { for (Map.Entry<String, List<String>> header : src) { replaceWith(header.getKey(), header.getValue()); } } return this; }
/** * Replace the values for all keys from the given map that are also present in this object, with the values from the given map. * All key-values from the given object that are not present in this object, will be added to it. * * @param src The source map * @return This object */ public FluentStringsMap replaceAll(Map<? extends String, ? extends Collection<String>> src) { if (src != null) { for (Map.Entry<? extends String, ? extends Collection<String>> header : src.entrySet()) { replaceWith(header.getKey(), header.getValue()); } } return this; }
@Override public List<String> put(String key, List<String> value) { if (key == null) { throw new NullPointerException("Null keys are not allowed"); } List<String> oldValue = get(key); replaceWith(key, value); return oldValue; }
/** * Replaces the values for the given key with the given values. * * @param key The key * @param values The new values * @return This object */ public FluentStringsMap replaceWith(final String key, final String... values) { return replaceWith(key, Arrays.asList(values)); }
/** * Replaces the values for the given key with the given values. * * @param key The key * @param values The new values * @return This object */ public FluentStringsMap replaceWith(final String key, final String... values) { return replaceWith(key, Arrays.asList(values)); }
/** * Replace the values for all keys from the given map that are also present in this object, with the values from the given map. * All key-values from the given object that are not present in this object, will be added to it. * * @param src The source object * @return This object */ public FluentStringsMap replaceAll(FluentStringsMap src) { if (src != null) { for (Map.Entry<String, List<String>> header : src) { replaceWith(header.getKey(), header.getValue()); } } return this; }
/** * Replace the values for all keys from the given map that are also present in this object, with the values from the given map. * All key-values from the given object that are not present in this object, will be added to it. * * @param src The source object * @return This object */ public FluentStringsMap replaceAll(FluentStringsMap src) { if (src != null) { for (Map.Entry<String, List<String>> header : src) { replaceWith(header.getKey(), header.getValue()); } } return this; }
/** * Replace the values for all keys from the given map that are also present in this object, with the values from the given map. * All key-values from the given object that are not present in this object, will be added to it. * * @param src The source map * @return This object */ public FluentStringsMap replaceAll(Map<? extends String, ? extends Collection<String>> src) { if (src != null) { for (Map.Entry<? extends String, ? extends Collection<String>> header : src.entrySet()) { replaceWith(header.getKey(), header.getValue()); } } return this; }
/** * Replace the values for all keys from the given map that are also present in this object, with the values from the given map. * All key-values from the given object that are not present in this object, will be added to it. * * @param src The source map * @return This object */ public FluentStringsMap replaceAll(Map<? extends String, ? extends Collection<String>> src) { if (src != null) { for (Map.Entry<? extends String, ? extends Collection<String>> header : src.entrySet()) { replaceWith(header.getKey(), header.getValue()); } } return this; }
@Override public List<String> put(String key, List<String> value) { if (key == null) { throw new NullPointerException("Null keys are not allowed"); } List<String> oldValue = get(key); replaceWith(key, value); return oldValue; }
@Override public List<String> put(String key, List<String> value) { if (key == null) { throw new NullPointerException("Null keys are not allowed"); } List<String> oldValue = get(key); replaceWith(key, value); return oldValue; }
@Test public void replaceNullTest() { FluentStringsMap map = new FluentStringsMap(); map.add("foo", "bar"); map.add("baz", Arrays.asList("foo", "bar")); assertEquals(map.keySet(), new LinkedHashSet<>(Arrays.asList("foo", "baz"))); assertEquals(map.getFirstValue("foo"), "bar"); assertEquals(map.getJoinedValue("foo", ", "), "bar"); assertEquals(map.get("foo"), Arrays.asList("bar")); assertEquals(map.getFirstValue("baz"), "foo"); assertEquals(map.getJoinedValue("baz", ", "), "foo, bar"); assertEquals(map.get("baz"), Arrays.asList("foo", "bar")); map.replaceWith(null, Arrays.asList("blub")); assertEquals(map.keySet(), new LinkedHashSet<>(Arrays.asList("foo", "baz"))); assertEquals(map.getFirstValue("foo"), "bar"); assertEquals(map.getJoinedValue("foo", ", "), "bar"); assertEquals(map.get("foo"), Arrays.asList("bar")); assertEquals(map.getFirstValue("baz"), "foo"); assertEquals(map.getJoinedValue("baz", ", "), "foo, bar"); assertEquals(map.get("baz"), Arrays.asList("foo", "bar")); }
@Test public void replaceArrayTest() { FluentStringsMap map = new FluentStringsMap(); map.add("foo", "bar"); map.add("baz", Arrays.asList("foo", "bar")); assertEquals(map.keySet(), new LinkedHashSet<>(Arrays.asList("foo", "baz"))); assertEquals(map.getFirstValue("foo"), "bar"); assertEquals(map.getJoinedValue("foo", ", "), "bar"); assertEquals(map.get("foo"), Arrays.asList("bar")); assertEquals(map.getFirstValue("baz"), "foo"); assertEquals(map.getJoinedValue("baz", ", "), "foo, bar"); assertEquals(map.get("baz"), Arrays.asList("foo", "bar")); map.replaceWith("foo", "blub", "bla"); assertEquals(map.keySet(), new LinkedHashSet<>(Arrays.asList("foo", "baz"))); assertEquals(map.getFirstValue("foo"), "blub"); assertEquals(map.getJoinedValue("foo", ", "), "blub, bla"); assertEquals(map.get("foo"), Arrays.asList("blub", "bla")); assertEquals(map.getFirstValue("baz"), "foo"); assertEquals(map.getJoinedValue("baz", ", "), "foo, bar"); assertEquals(map.get("baz"), Arrays.asList("foo", "bar")); }
@Test public void replaceCollectionTest() { FluentStringsMap map = new FluentStringsMap(); map.add("foo", "bar"); map.add("baz", Arrays.asList("foo", "bar")); assertEquals(map.keySet(), new LinkedHashSet<>(Arrays.asList("foo", "baz"))); assertEquals(map.getFirstValue("foo"), "bar"); assertEquals(map.getJoinedValue("foo", ", "), "bar"); assertEquals(map.get("foo"), Arrays.asList("bar")); assertEquals(map.getFirstValue("baz"), "foo"); assertEquals(map.getJoinedValue("baz", ", "), "foo, bar"); assertEquals(map.get("baz"), Arrays.asList("foo", "bar")); map.replaceWith("foo", Arrays.asList("blub", "bla")); assertEquals(map.keySet(), new LinkedHashSet<>(Arrays.asList("foo", "baz"))); assertEquals(map.getFirstValue("foo"), "blub"); assertEquals(map.getJoinedValue("foo", ", "), "blub, bla"); assertEquals(map.get("foo"), Arrays.asList("blub", "bla")); assertEquals(map.getFirstValue("baz"), "foo"); assertEquals(map.getJoinedValue("baz", ", "), "foo, bar"); assertEquals(map.get("baz"), Arrays.asList("foo", "bar")); }
@Test public void replaceValueWithNullTest() { FluentStringsMap map = new FluentStringsMap(); map.add("foo", "bar"); map.add("baz", Arrays.asList("foo", "bar")); assertEquals(map.keySet(), new LinkedHashSet<>(Arrays.asList("foo", "baz"))); assertEquals(map.getFirstValue("foo"), "bar"); assertEquals(map.getJoinedValue("foo", ", "), "bar"); assertEquals(map.get("foo"), Arrays.asList("bar")); assertEquals(map.getFirstValue("baz"), "foo"); assertEquals(map.getJoinedValue("baz", ", "), "foo, bar"); assertEquals(map.get("baz"), Arrays.asList("foo", "bar")); map.replaceWith("baz", (Collection<String>) null); assertEquals(map.keySet(), new LinkedHashSet<>(Arrays.asList("foo"))); assertEquals(map.getFirstValue("foo"), "bar"); assertEquals(map.getJoinedValue("foo", ", "), "bar"); assertEquals(map.get("foo"), Arrays.asList("bar")); assertNull(map.getFirstValue("baz")); assertNull(map.getJoinedValue("baz", ", ")); assertNull(map.get("baz")); }
@Test public void replaceDifferentCaseTest() { FluentStringsMap map = new FluentStringsMap(); map.add("foo", "bar"); map.add("baz", Arrays.asList("foo", "bar")); assertEquals(map.keySet(), new LinkedHashSet<>(Arrays.asList("foo", "baz"))); assertEquals(map.getFirstValue("foo"), "bar"); assertEquals(map.getJoinedValue("foo", ", "), "bar"); assertEquals(map.get("foo"), Arrays.asList("bar")); assertEquals(map.getFirstValue("baz"), "foo"); assertEquals(map.getJoinedValue("baz", ", "), "foo, bar"); assertEquals(map.get("baz"), Arrays.asList("foo", "bar")); map.replaceWith("Foo", Arrays.asList("blub", "bla")); assertEquals(map.keySet(), new LinkedHashSet<>(Arrays.asList("foo", "baz", "Foo"))); assertEquals(map.getFirstValue("foo"), "bar"); assertEquals(map.getJoinedValue("foo", ", "), "bar"); assertEquals(map.get("foo"), Arrays.asList("bar")); assertEquals(map.getFirstValue("baz"), "foo"); assertEquals(map.getJoinedValue("baz", ", "), "foo, bar"); assertEquals(map.get("baz"), Arrays.asList("foo", "bar")); assertEquals(map.getFirstValue("Foo"), "blub"); assertEquals(map.getJoinedValue("Foo", ", "), "blub, bla"); assertEquals(map.get("Foo"), Arrays.asList("blub", "bla")); }
@Test public void replaceUndefinedTest() { FluentStringsMap map = new FluentStringsMap(); map.add("foo", "bar"); map.add("baz", Arrays.asList("foo", "bar")); assertEquals(map.keySet(), new LinkedHashSet<>(Arrays.asList("foo", "baz"))); assertEquals(map.getFirstValue("foo"), "bar"); assertEquals(map.getJoinedValue("foo", ", "), "bar"); assertEquals(map.get("foo"), Arrays.asList("bar")); assertEquals(map.getFirstValue("baz"), "foo"); assertEquals(map.getJoinedValue("baz", ", "), "foo, bar"); assertEquals(map.get("baz"), Arrays.asList("foo", "bar")); map.replaceWith("bar", Arrays.asList("blub")); assertEquals(map.keySet(), new LinkedHashSet<>(Arrays.asList("foo", "baz", "bar"))); assertEquals(map.getFirstValue("foo"), "bar"); assertEquals(map.getJoinedValue("foo", ", "), "bar"); assertEquals(map.get("foo"), Arrays.asList("bar")); assertEquals(map.getFirstValue("baz"), "foo"); assertEquals(map.getJoinedValue("baz", ", "), "foo, bar"); assertEquals(map.get("baz"), Arrays.asList("foo", "bar")); assertEquals(map.getFirstValue("bar"), "blub"); assertEquals(map.getJoinedValue("bar", ", "), "blub"); assertEquals(map.get("bar"), Arrays.asList("blub")); }