/** * Removes value from the specified key * * @param key * @param value */ public void removeValue(final K key, final V value) { List<V> list = get(key); if (list != null) { list.remove(value); } }
/** * Gets the first value in the value list * * @param key * @return first value */ public V getFirstValue(final K key) { List<V> list = get(key); if ((list != null) && !list.isEmpty()) { return list.get(0); } return null; } }
/** * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String) * @param name * @return all headers with name */ public Collection<String> getHeaders(String name) { List<Object> values = headers.get(name); if (values == null) { return Collections.emptyList(); } List<String> ret = new ArrayList<>(values.size()); for (Object value : values) { ret.add(value.toString()); } return ret; }
/** * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String) * @param name * @return all headers with name */ @Override public Collection<String> getHeaders(String name) { List<Object> values = headers.get(name); if (values == null) { return Collections.emptyList(); } List<String> ret = new ArrayList<>(values.size()); for (Object value : values) { ret.add(value.toString()); } return ret; }
/** * Adds value to the specified key * * @param key * @param value */ public void addValue(final K key, final V value) { List<V> list = get(key); if (list == null) { list = new ArrayList<>(1); put(key, list); } list.add(value); }
/** * Replaces all existing values with the specified value. If no values exist for the key the * value will be added. * * @param key * @param value */ public void replaceValues(final K key, final V value) { List<V> list = get(key); if (list != null) { list.clear(); list.add(value); } else { addValue(key, value); } }