001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.util; 018 019import java.util.List; 020import java.util.Map; 021 022/** 023 * Extension of the {@code Map} interface that stores multiple values. 024 * 025 * @author Arjen Poutsma 026 * @since 3.0 027 * @param <K> the key type 028 * @param <V> the value element type 029 */ 030public interface MultiValueMap<K, V> extends Map<K, List<V>> { 031 032 /** 033 * Return the first value for the given key. 034 * @param key the key 035 * @return the first value for the specified key, or {@code null} if none 036 */ 037 V getFirst(K key); 038 039 /** 040 * Add the given single value to the current list of values for the given key. 041 * @param key the key 042 * @param value the value to be added 043 */ 044 void add(K key, V value); 045 046 /** 047 * Set the given single value under the given key. 048 * @param key the key 049 * @param value the value to set 050 */ 051 void set(K key, V value); 052 053 /** 054 * Set the given values under. 055 * @param values the values. 056 */ 057 void setAll(Map<K, V> values); 058 059 /** 060 * Return a {@code Map} with the first values contained in this {@code MultiValueMap}. 061 * @return a single value representation of this map 062 */ 063 Map<K, V> toSingleValueMap(); 064 065}