/** * Returns the value for the given key. If there are multiple values for this key, * then only the first one will be returned. * * @param key The key * @return The first value */ public String getFirstValue(String key) { List<String> values = get(key); if (values == null) { return null; } else if (values.isEmpty()) { return ""; } else { return values.get(0); } }
@Test public void nullValueTest() { FluentStringsMap map = new FluentStringsMap(); map.add("foo", (String) null); assertEquals(map.getFirstValue("foo"), null); assertEquals(map.getJoinedValue("foo", ", "), null); assertEquals(map.get("foo").size(), 1); }
@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 normalTest() { 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")); assertNull(map.getFirstValue("foo")); assertNull(map.getJoinedValue("foo", ", ")); assertNull(map.get("foo")); assertEquals(map.getFirstValue("Baz"), "fOo"); assertEquals(map.getJoinedValue("Baz", ", "), "fOo, bar"); assertEquals(map.get("Baz"), Arrays.asList("fOo", "bar")); assertNull(map.getFirstValue("baz")); assertNull(map.getJoinedValue("baz", ", ")); assertNull(map.get("baz")); }
@Override public List<String> remove(Object key) { if (key == null) { return null; } else { List<String> oldValues = get(key.toString()); delete(key.toString()); return oldValues; } }
@Test public void addNullTest() { FluentStringsMap map = new FluentStringsMap(); map.add("fOO", "bAr"); map.add(null, Arrays.asList("fOo", "bar")); 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("foo")); assertNull(map.getJoinedValue("foo", ", ")); assertNull(map.get("foo")); assertNull(map.getFirstValue(null)); assertNull(map.getJoinedValue("Baz", ", ")); assertNull(map.get(null)); }
/** * Returns the values for the given key joined into a single string using the given delimiter. * * @param key The key * @return The value as a single string */ public String getJoinedValue(String key, String delimiter) { List<String> values = get(key); if (values == null) { return null; } else if (values.size() == 1) { return values.get(0); } else { StringBuilder result = new StringBuilder(); for (String value : values) { if (result.length() > 0) { result.append(delimiter); } result.append(value); } return result.toString(); } }
@Test public void emptyValueTest() { FluentStringsMap map = new FluentStringsMap(); map.add("foo", ""); assertEquals(map.keySet(), new LinkedHashSet<>(Arrays.asList("foo"))); assertEquals(map.getFirstValue("foo"), ""); assertEquals(map.getJoinedValue("foo", ", "), ""); assertEquals(map.get("foo"), Arrays.asList("")); }
/** * Returns the value for the given key. If there are multiple values for this key, * then only the first one will be returned. * * @param key The key * @return The first value */ public String getFirstValue(String key) { List<String> values = get(key); if (values == null) { return null; } else if (values.isEmpty()) { return ""; } else { return values.get(0); } }
@Test public void deleteTest() { 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.delete("baz"); 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")); }
/** * Returns the value for the given key. If there are multiple values for this key, * then only the first one will be returned. * * @param key The key * @return The first value */ public String getFirstValue(String key) { List<String> values = get(key); if (values == null) { return null; } else if (values.isEmpty()) { return ""; } else { return values.get(0); } }
@Test public void sameKeyMultipleTimesTest() { FluentStringsMap map = new FluentStringsMap(); map.add("foo", "baz,foo"); map.add("foo", Arrays.asList("bar")); map.add("foo", "bla", "blubb"); map.add("fOO", "duh"); assertEquals(map.keySet(), new LinkedHashSet<>(Arrays.asList("foo", "fOO"))); assertEquals(map.getFirstValue("foo"), "baz,foo"); assertEquals(map.getJoinedValue("foo", ", "), "baz,foo, bar, bla, blubb"); assertEquals(map.get("foo"), Arrays.asList("baz,foo", "bar", "bla", "blubb")); assertEquals(map.getFirstValue("fOO"), "duh"); assertEquals(map.getJoinedValue("fOO", ", "), "duh"); assertEquals(map.get("fOO"), Arrays.asList("duh")); }
/** * Returns the value for the given key. If there are multiple values for this key, * then only the first one will be returned. * * @param key The key * @return The first value */ public String getFirstValue(String key) { List<String> values = get(key); if (values == null) { return null; } else if (values.isEmpty()) { return ""; } else { return values.get(0); } }
@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); replace(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; }
@Override public List<String> remove(Object key) { if (key == null) { return null; } else { List<String> oldValues = get(key.toString()); delete(key.toString()); return oldValues; } }
@Override public List<String> remove(Object key) { if (key == null) { return null; } else { List<String> oldValues = get(key.toString()); delete(key.toString()); return oldValues; } }
@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> remove(Object key) { if (key == null) { return null; } else { List<String> oldValues = get(key.toString()); delete(key.toString()); return oldValues; } }
protected void doCloseRequest() { ((DefaultOptions) options).b.reconnect(false); List<String> uuid = decodeQueryString(request).get("X-Atmosphere-tracking-id"); if (!closedByProtocol.getAndSet(true)) { RequestBuilder r = new RequestBuilder(); FluentStringsMap f = new FluentStringsMap(); f.add("X-Atmosphere-Transport", "close").add("X-Atmosphere-tracking-id", uuid); r.setUrl(request.uri()) .setMethod("GET") .setHeaders(request.headers()) .setQueryParams(f); try { options.runtime().prepareRequest(r.build()).execute().get(); } catch (Exception e) { logger.debug("Was unable to send the close request {}", uuid); logger.trace("", e); } } }