/** * Replaces the values for the given key with the given values. * * @param key The key * @param values The new values * @return This object */ public FluentCaseInsensitiveStringsMap replaceWith(final String key, final String... values) { return replaceWith(key, Arrays.asList(values)); }
public T setHeader(String name, String value) { request.headers.replaceWith(name, value); return derived.cast(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 FluentCaseInsensitiveStringsMap 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 object * @return This object */ public FluentCaseInsensitiveStringsMap replaceAll(FluentCaseInsensitiveStringsMap src) { if (src != null) { for (Map.Entry<String, List<String>> header : src) { 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 FluentCaseInsensitiveStringsMap 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 FluentCaseInsensitiveStringsMap replaceWith(final String key, final String... values) { return replaceWith(key, Arrays.asList(values)); }
public T setHeader(String name, String value) { request.headers.replaceWith(name, value); return derived.cast(this); }
public T setHeader(String name, String value) { request.headers.replaceWith(name, value); return derived.cast(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 FluentCaseInsensitiveStringsMap replaceAll(FluentCaseInsensitiveStringsMap 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 FluentCaseInsensitiveStringsMap 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 object * @return This object */ public FluentCaseInsensitiveStringsMap replaceAll(FluentCaseInsensitiveStringsMap 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 FluentCaseInsensitiveStringsMap 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 replaceUndefinedTest() { FluentCaseInsensitiveStringsMap map = new FluentCaseInsensitiveStringsMap(); 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")); }
@Test public void replaceNullTest() { FluentCaseInsensitiveStringsMap map = new FluentCaseInsensitiveStringsMap(); 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 replaceTest() { FluentCaseInsensitiveStringsMap map = new FluentCaseInsensitiveStringsMap(); 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 replaceValueWithNullTest() { FluentCaseInsensitiveStringsMap map = new FluentCaseInsensitiveStringsMap(); 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", ", ")); assertTrue(map.get("baz").isEmpty()); }