1 /* 2 * Hunt - A refined core library for D programming language. 3 * 4 * Copyright (C) 2018-2019 HuntLabs 5 * 6 * Website: https://www.huntlabs.net/ 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 module hunt.collection.MultiValueMap; 13 14 import hunt.collection.List; 15 import hunt.collection.Map; 16 17 alias MultiValuesMap(T) = Map!(string, List!(T)); 18 alias MultiStringsMap = MultiValuesMap!string; 19 20 21 /** 22 * Extension of the {@code Map} interface that stores multiple values. 23 * 24 * @author Arjen Poutsma 25 */ 26 interface MultiValueMap(K, V) : Map!(K, List!(V)) { 27 28 /** 29 * Return the first value for the given key. 30 * @param key the key 31 * @return the first value for the specified key, or {@code null} if none 32 */ 33 V getFirst(K key); 34 35 /** 36 * Add the given single value to the current list of values for the given key. 37 * @param key the key 38 * @param value the value to be added 39 */ 40 void add(K key, V value); 41 42 /** 43 * Add all the values of the given list to the current list of values for the given key. 44 * @param key they key 45 * @param values the values to be added 46 * @since 5.0 47 */ 48 void addAll(K key, List!V values); 49 50 /** 51 * Add all the values of the given {@code MultiValueMap} to the current values. 52 * @param values the values to be added 53 * @since 5.0 54 */ 55 void addAll(Map!(K, List!V) values); 56 57 /** 58 * Set the given single value under the given key. 59 * @param key the key 60 * @param value the value to set 61 */ 62 void set(K key, V value); 63 64 /** 65 * Set the given values under. 66 * @param values the values. 67 */ 68 void setAll(Map!(K, V) values); 69 70 /** 71 * Returns the first values contained in this {@code MultiValueMap}. 72 * @return a single value representation of this map 73 */ 74 Map!(K, V) toSingleValueMap(); 75 76 }