diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java index d10c48e66fd..ab5e87c8852 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java @@ -17,8 +17,6 @@ import java.io.IOException; import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; import javax.servlet.DispatcherType; import javax.servlet.RequestDispatcher; @@ -30,7 +28,6 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.Attributes; -import org.eclipse.jetty.util.LazyList; import org.eclipse.jetty.util.MultiMap; import org.eclipse.jetty.util.UrlEncoded; @@ -128,7 +125,7 @@ public class Dispatcher implements RequestDispatcher final DispatcherType old_type = baseRequest.getDispatcherType(); final Attributes old_attr=baseRequest.getAttributes(); - MultiMap old_params=baseRequest.getParameters(); + MultiMap old_params=baseRequest.getParameters(); try { baseRequest.setDispatcherType(DispatcherType.INCLUDE); @@ -148,21 +145,12 @@ public class Dispatcher implements RequestDispatcher old_params=baseRequest.getParameters(); } - MultiMap parameters=new MultiMap(); + MultiMap parameters=new MultiMap<>(); UrlEncoded.decodeTo(query,parameters,baseRequest.getCharacterEncoding()); - if (old_params!=null && old_params.size()>0) - { + if(old_params != null) { // Merge parameters. - Iterator iter = old_params.entrySet().iterator(); - while (iter.hasNext()) - { - Map.Entry entry = (Map.Entry)iter.next(); - String name=(String)entry.getKey(); - Object values=entry.getValue(); - for (int i=0;i old_params=baseRequest.getParameters(); try { diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index e98b9fb5d95..d1c6f0a2d98 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -30,11 +30,9 @@ import java.util.Collections; import java.util.Enumeration; import java.util.EventListener; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Map.Entry; import javax.servlet.AsyncContext; import javax.servlet.AsyncListener; @@ -68,7 +66,6 @@ import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandler.Context; import org.eclipse.jetty.util.Attributes; import org.eclipse.jetty.util.AttributesMap; -import org.eclipse.jetty.util.LazyList; import org.eclipse.jetty.util.MultiMap; import org.eclipse.jetty.util.MultiPartInputStream; import org.eclipse.jetty.util.StringUtil; @@ -126,7 +123,7 @@ public class Request implements HttpServletRequest private boolean _asyncSupported = true; private volatile Attributes _attributes; private Authentication _authentication; - private MultiMap _baseParameters; + private MultiMap _baseParameters; private String _characterEncoding; private ContextHandler.Context _context; private boolean _newContext; @@ -138,7 +135,7 @@ public class Request implements HttpServletRequest private int _inputState = __NONE; private HttpMethod _httpMethod; private String _method; - private MultiMap _parameters; + private MultiMap _parameters; private boolean _paramsExtracted; private String _pathInfo; private int _port; @@ -192,7 +189,7 @@ public class Request implements HttpServletRequest public void extractParameters() { if (_baseParameters == null) - _baseParameters = new MultiMap(); + _baseParameters = new MultiMap<>(); if (_paramsExtracted) { @@ -283,15 +280,7 @@ public class Request implements HttpServletRequest else if (_parameters != _baseParameters) { // Merge parameters (needed if parameters extracted after a forward). - Iterator iter = _baseParameters.entrySet().iterator(); - while (iter.hasNext()) - { - Map.Entry entry = (Map.Entry)iter.next(); - String name = (String)entry.getKey(); - Object values = entry.getValue(); - for (int i = 0; i < LazyList.size(values); i++) - _parameters.add(name,LazyList.get(values,i)); - } + _parameters.addAllValues(_baseParameters); } } finally @@ -335,10 +324,10 @@ public class Request implements HttpServletRequest * @see javax.servlet.ServletRequest#getAttributeNames() */ @Override - public Enumeration getAttributeNames() + public Enumeration getAttributeNames() { if (_attributes == null) - return Collections.enumeration(Collections.EMPTY_LIST); + return Collections.enumeration(Collections.emptyList()); return AttributesMap.getAttributeNamesCopy(_attributes); } @@ -499,7 +488,7 @@ public class Request implements HttpServletRequest * @see javax.servlet.http.HttpServletRequest#getHeaderNames() */ @Override - public Enumeration getHeaderNames() + public Enumeration getHeaderNames() { return _fields.getFieldNames(); } @@ -509,11 +498,11 @@ public class Request implements HttpServletRequest * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String) */ @Override - public Enumeration getHeaders(String name) + public Enumeration getHeaders(String name) { - Enumeration e = _fields.getValues(name); + Enumeration e = _fields.getValues(name); if (e == null) - return Collections.enumeration(Collections.EMPTY_LIST); + return Collections.enumeration(Collections.emptyList()); return e; } @@ -691,7 +680,7 @@ public class Request implements HttpServletRequest * @see javax.servlet.ServletRequest#getParameterMap() */ @Override - public Map getParameterMap() + public Map getParameterMap() { if (!_paramsExtracted) extractParameters(); @@ -715,7 +704,7 @@ public class Request implements HttpServletRequest /** * @return Returns the parameters. */ - public MultiMap getParameters() + public MultiMap getParameters() { return _parameters; } @@ -1691,7 +1680,7 @@ public class Request implements HttpServletRequest * @param parameters * The parameters to set. */ - public void setParameters(MultiMap parameters) + public void setParameters(MultiMap parameters) { _parameters = (parameters == null)?_baseParameters:parameters; if (_paramsExtracted && _parameters == null) @@ -2017,7 +2006,7 @@ public class Request implements HttpServletRequest public void mergeQueryString(String query) { // extract parameters from dispatch query - MultiMap parameters = new MultiMap(); + MultiMap parameters = new MultiMap<>(); UrlEncoded.decodeTo(query,parameters,getCharacterEncoding()); boolean merge_old_query = false; @@ -2030,21 +2019,7 @@ public class Request implements HttpServletRequest if (_parameters != null && _parameters.size() > 0) { // Merge parameters; new parameters of the same name take precedence. - Iterator> iter = _parameters.entrySet().iterator(); - while (iter.hasNext()) - { - Map.Entry entry = iter.next(); - String name = entry.getKey(); - - // If the names match, we will need to remake the query string - if (parameters.containsKey(name)) - merge_old_query = true; - - // Add the old values to the new parameter map - Object values = entry.getValue(); - for (int i = 0; i < LazyList.size(values); i++) - parameters.add(name,LazyList.get(values,i)); - } + merge_old_query = parameters.addAllValues(_parameters); } if (_queryString != null && _queryString.length() > 0) @@ -2052,23 +2027,20 @@ public class Request implements HttpServletRequest if (merge_old_query) { StringBuilder overridden_query_string = new StringBuilder(); - MultiMap overridden_old_query = new MultiMap(); + MultiMap overridden_old_query = new MultiMap<>(); UrlEncoded.decodeTo(_queryString,overridden_old_query,getCharacterEncoding()); - MultiMap overridden_new_query = new MultiMap(); + MultiMap overridden_new_query = new MultiMap<>(); UrlEncoded.decodeTo(query,overridden_new_query,getCharacterEncoding()); - Iterator> iter = overridden_old_query.entrySet().iterator(); - while (iter.hasNext()) + for(String name: overridden_old_query.keySet()) { - Map.Entry entry = iter.next(); - String name = entry.getKey(); if (!overridden_new_query.containsKey(name)) { - Object values = entry.getValue(); - for (int i = 0; i < LazyList.size(values); i++) + List values = overridden_old_query.get(name); + for(String v: values) { - overridden_query_string.append("&").append(name).append("=").append(LazyList.get(values,i)); + overridden_query_string.append("&").append(name).append("=").append(v); } } } diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java index 133e1d7bc0c..6fd5ab614a4 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java @@ -99,7 +99,7 @@ public class ServletHandler extends ScopedHandler private final Map _filterNameMap= new HashMap<>(); private List _filterPathMappings; - private MultiMap _filterNameMappings; + private MultiMap _filterNameMappings; private final Map _servletNameMap=new HashMap<>(); private PathMap _servletPathMap; @@ -1109,7 +1109,7 @@ public class ServletHandler extends ScopedHandler else { _filterPathMappings=new ArrayList<>(); - _filterNameMappings=new MultiMap(); + _filterNameMappings=new MultiMap(); for (FilterMapping filtermapping : _filterMappings) { FilterHolder filter_holder = _filterNameMap.get(filtermapping.getFilterName()); diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiMap.java b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiMap.java index 4c5abcd091f..55fdf005d23 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiMap.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiMap.java @@ -13,28 +13,31 @@ package org.eclipse.jetty.util; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; /** * A multi valued Map. */ @SuppressWarnings("serial") -public class MultiMap extends HashMap +public class MultiMap extends HashMap> { public MultiMap() { super(); } - public MultiMap(Map map) + public MultiMap(Map> map) { super(map); } - public MultiMap(MultiMap map) + public MultiMap(MultiMap map) { super(map); } @@ -46,9 +49,13 @@ public class MultiMap extends HashMap * @param name The entry key. * @return Unmodifieable List of values. */ - public List getValues(String name) + public List getValues(String name) { - return LazyList.getList(get(name),true); + List vals = super.get(name); + if((vals == null) || vals.isEmpty()) { + return null; + } + return vals; } /* ------------------------------------------------------------ */ @@ -59,12 +66,16 @@ public class MultiMap extends HashMap * @param i Index of element to get. * @return Unmodifieable List of values. */ - public Object getValue(String name,int i) + public V getValue(String name,int i) { - Object l=get(name); - if (i==0 && LazyList.size(l)==0) + List vals = getValues(name); + if(vals == null) { return null; - return LazyList.get(l,i); + } + if (i==0 && vals.isEmpty()) { + return null; + } + return vals.get(i); } @@ -78,46 +89,57 @@ public class MultiMap extends HashMap */ public String getString(String name) { - Object l=get(name); - switch(LazyList.size(l)) + List vals =get(name); + if ((vals == null) || (vals.isEmpty())) { - case 0: - return null; - case 1: - Object o=LazyList.get(l,0); - return o==null?null:o.toString(); - default: - { - StringBuilder values=new StringBuilder(128); - for (int i=0; i0) - values.append(','); - values.append(e.toString()); - } - } - return values.toString(); - } + return null; } + + if (vals.size() == 1) + { + // simple form. + return vals.get(0).toString(); + } + + // delimited form + StringBuilder values=new StringBuilder(128); + for (V e : vals) + { + if (e != null) + { + if (values.length() > 0) + values.append(','); + values.append(e.toString()); + } + } + return values.toString(); } - /* ------------------------------------------------------------ */ - @Override - public Object get(Object name) + /** + * Put multi valued entry. + * @param name The entry key. + * @param value The simple value + * @return The previous value or null. + */ + public List put(String name, V value) { - Object l=super.get(name); - switch(LazyList.size(l)) + if(value == null) { + return super.put(name, null); + } + List vals = new ArrayList<>(); + vals.add(value); + return put(name,vals); + } + + /** + * Shorthand version of putAll + * @param input the input map + */ + public void putAllValues(Map input) + { + for(Map.Entry entry: input.entrySet()) { - case 0: - return null; - case 1: - Object o=LazyList.get(l,0); - return o; - default: - return LazyList.getList(l,true); + put(entry.getKey(), entry.getValue()); } } @@ -127,23 +149,23 @@ public class MultiMap extends HashMap * @param values The List of multiple values. * @return The previous value or null. */ - public Object putValues(String name, List values) + public List putValues(String name, List values) { - return put(name,values); + return super.put(name,values); } /* ------------------------------------------------------------ */ /** Put multi valued entry. * @param name The entry key. - * @param values The String array of multiple values. + * @param values The array of multiple values. * @return The previous value or null. */ - public Object putValues(String name, String... values) + @SafeVarargs + public final List putValues(String name, V... values) { - Object list=null; - for (int i=0;i list = new ArrayList<>(); + list.addAll(Arrays.asList(values)); + return super.put(name,list); } @@ -154,12 +176,14 @@ public class MultiMap extends HashMap * @param name The entry key. * @param value The entry value. */ - public void add(String name, Object value) + public void add(String name, V value) { - Object lo = get(name); - Object ln = LazyList.add(lo,value); - if (lo!=ln) - put(name,ln); + List lo = get(name); + if(lo == null) { + lo = new ArrayList<>(); + } + lo.add(value); + super.put(name,lo); } /* ------------------------------------------------------------ */ @@ -169,12 +193,14 @@ public class MultiMap extends HashMap * @param name The entry key. * @param values The List of multiple values. */ - public void addValues(String name, List values) + public void addValues(String name, List values) { - Object lo = get(name); - Object ln = LazyList.addCollection(lo,values); - if (lo!=ln) - put(name,ln); + List lo = get(name); + if(lo == null) { + lo = new ArrayList<>(); + } + lo.addAll(values); + put(name,lo); } /* ------------------------------------------------------------ */ @@ -184,12 +210,47 @@ public class MultiMap extends HashMap * @param name The entry key. * @param values The String array of multiple values. */ - public void addValues(String name, String[] values) + public void addValues(String name, V[] values) { - Object lo = get(name); - Object ln = LazyList.addCollection(lo,Arrays.asList(values)); - if (lo!=ln) - put(name,ln); + List lo = get(name); + if(lo == null) { + lo = new ArrayList<>(); + } + lo.addAll(Arrays.asList(values)); + put(name,lo); + } + + /** + * Merge values. + * + * @param the + * map to overlay on top of this one, merging together values if needed. + * @return true if an existing key was merged with potentially new values, false if either no change was made, or there were only new keys. + */ + public boolean addAllValues(MultiMap map) + { + boolean merged = false; + + if ((map == null) || (map.isEmpty())) + { + // done + return merged; + } + + for (Map.Entry> entry : map.entrySet()) + { + String name = entry.getKey(); + List values = entry.getValue(); + + if (this.containsKey(name)) + { + merged = true; + } + + this.addValues(name,values); + } + + return merged; } /* ------------------------------------------------------------ */ @@ -198,20 +259,70 @@ public class MultiMap extends HashMap * @param value The entry value. * @return true if it was removed. */ - public boolean removeValue(String name,Object value) + public boolean removeValue(String name,V value) { - Object lo = get(name); - Object ln=lo; - int s=LazyList.size(lo); - if (s>0) - { - ln=LazyList.remove(lo,value); - if (ln==null) - remove(name); - else - put(name, ln); + List lo = get(name); + if((lo == null)||(lo.isEmpty())) { + return false; } - return LazyList.size(ln)!=s; + boolean ret = lo.remove(value); + if(lo.isEmpty()) { + remove(name); + } else { + put(name,lo); + } + return ret; + } + + /** + * Test for a specific single value in the map. + *

+ * NOTE: This is a SLOW operation, and is actively discouraged. + * @param value + * @return + */ + public boolean containsSimpleValue(V value) + { + for (List vals : values()) + { + if ((vals.size() == 1) && vals.contains(value)) + { + return true; + } + } + return false; + } + + @Override + public String toString() + { + Iterator>> iter = entrySet().iterator(); + StringBuilder sb = new StringBuilder(); + sb.append('{'); + boolean delim = false; + while (iter.hasNext()) + { + Entry> e = iter.next(); + if (delim) + { + sb.append(", "); + } + String key = e.getKey(); + List vals = e.getValue(); + sb.append(key); + sb.append('='); + if (vals.size() == 1) + { + sb.append(vals.get(0)); + } + else + { + sb.append(vals); + } + delim = true; + } + sb.append('}'); + return sb.toString(); } /* ------------------------------------------------------------ */ @@ -241,11 +352,17 @@ public class MultiMap extends HashMap } }; - for(Map.Entry entry: entrySet()) + for(Map.Entry> entry: entrySet()) { - String[] a = LazyList.toStringArray(entry.getValue()); + String[] a = null; + if (entry.getValue() != null) + { + a = new String[entry.getValue().size()]; + a = entry.getValue().toArray(a); + } map.put(entry.getKey(),a); } return map; } + } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/MultiMapTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/MultiMapTest.java index 7730eb8490f..77885dd1833 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/MultiMapTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/MultiMapTest.java @@ -29,7 +29,7 @@ public class MultiMapTest @Test public void testPut() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); String key = "formats"; @@ -42,13 +42,30 @@ public class MultiMapTest * Tests {@link MultiMap#put(Object, Object)} */ @Test - public void testPut_Null() + public void testPut_Null_String() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); String key = "formats"; + String val = null; - mm.put(key,null); + mm.put(key,val); + assertMapSize(mm,1); + assertNullValues(mm,key); + } + + /** + * Tests {@link MultiMap#put(Object, Object)} + */ + @Test + public void testPut_Null_List() + { + MultiMap mm = new MultiMap<>(); + + String key = "formats"; + List vals = null; + + mm.put(key,vals); assertMapSize(mm,1); assertNullValues(mm,key); } @@ -59,7 +76,7 @@ public class MultiMapTest @Test public void testPut_Replace() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); String key = "formats"; Object ret; @@ -83,7 +100,7 @@ public class MultiMapTest @Test public void testPutValues_List() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); String key = "formats"; @@ -103,7 +120,7 @@ public class MultiMapTest @Test public void testPutValues_StringArray() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); String key = "formats"; @@ -119,7 +136,7 @@ public class MultiMapTest @Test public void testPutValues_VarArgs() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); String key = "formats"; @@ -134,7 +151,7 @@ public class MultiMapTest @Test public void testAdd() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); String key = "formats"; @@ -157,7 +174,7 @@ public class MultiMapTest @Test public void testAddValues_List() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); String key = "formats"; @@ -183,7 +200,7 @@ public class MultiMapTest @Test public void testAddValues_List_Empty() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); String key = "formats"; @@ -206,7 +223,7 @@ public class MultiMapTest @Test public void testAddValues_StringArray() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); String key = "formats"; @@ -229,7 +246,7 @@ public class MultiMapTest @Test public void testAddValues_StringArray_Empty() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); String key = "formats"; @@ -252,7 +269,7 @@ public class MultiMapTest @Test public void testRemoveValue() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); String key = "formats"; @@ -274,7 +291,7 @@ public class MultiMapTest @Test public void testRemoveValue_InvalidItem() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); String key = "formats"; @@ -295,7 +312,7 @@ public class MultiMapTest @Test public void testRemoveValue_AllItems() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); String key = "formats"; @@ -325,7 +342,7 @@ public class MultiMapTest @Test public void testRemoveValue_FromEmpty() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); String key = "formats"; @@ -346,7 +363,7 @@ public class MultiMapTest @Test public void testPutAll_Map() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); assertMapSize(mm,0); // Shouldn't have anything yet. @@ -355,7 +372,7 @@ public class MultiMapTest input.put("color","red"); input.put("amount","bushel"); - mm.putAll(input); + mm.putAllValues(input); assertMapSize(mm,3); assertValues(mm,"food","apple"); @@ -369,11 +386,11 @@ public class MultiMapTest @Test public void testPutAll_MultiMap_Simple() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); assertMapSize(mm,0); // Shouldn't have anything yet. - MultiMap input = new MultiMap(); + MultiMap input = new MultiMap<>(); input.put("food","apple"); input.put("color","red"); input.put("amount","bushel"); @@ -392,11 +409,11 @@ public class MultiMapTest @Test public void testPutAll_MultiMapComplex() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); assertMapSize(mm,0); // Shouldn't have anything yet. - MultiMap input = new MultiMap(); + MultiMap input = new MultiMap<>(); input.putValues("food","apple","cherry","raspberry"); input.put("color","red"); input.putValues("amount","bushel","pint"); @@ -415,7 +432,7 @@ public class MultiMapTest @Test public void testToStringArrayMap() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); mm.putValues("food","apple","cherry","raspberry"); mm.put("color","red"); mm.putValues("amount","bushel","pint"); @@ -436,7 +453,7 @@ public class MultiMapTest @Test public void testToString() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); mm.put("color","red"); Assert.assertEquals("{color=red}", mm.toString()); @@ -452,7 +469,7 @@ public class MultiMapTest @Test public void testClear() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); mm.putValues("food","apple","cherry","raspberry"); mm.put("color","red"); mm.putValues("amount","bushel","pint"); @@ -470,7 +487,7 @@ public class MultiMapTest @Test public void testContainsKey() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); mm.putValues("food","apple","cherry","raspberry"); mm.put("color","red"); mm.putValues("amount","bushel","pint"); @@ -479,18 +496,37 @@ public class MultiMapTest Assert.assertFalse("Contains Key [nutrition]", mm.containsKey("nutrition")); } + /** + * Tests {@link MultiMap#containsSimpleValue(Object)} + */ + @Test + public void testContainsSimpleValue() + { + MultiMap mm = new MultiMap<>(); + mm.putValues("food","apple","cherry","raspberry"); + mm.put("color","red"); + mm.putValues("amount","bushel","pint"); + + Assert.assertTrue("Contains Value [red]", mm.containsSimpleValue("red")); + Assert.assertFalse("Contains Value [nutrition]", mm.containsValue("nutrition")); + } + /** * Tests {@link MultiMap#containsValue(Object)} */ @Test public void testContainsValue() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); mm.putValues("food","apple","cherry","raspberry"); mm.put("color","red"); mm.putValues("amount","bushel","pint"); - Assert.assertTrue("Contains Value [red]", mm.containsValue("red")); + List acr = new ArrayList<>(); + acr.add("apple"); + acr.add("cherry"); + acr.add("raspberry"); + Assert.assertTrue("Contains Value [apple,cherry,raspberry]", mm.containsValue(acr)); Assert.assertFalse("Contains Value [nutrition]", mm.containsValue("nutrition")); } @@ -500,7 +536,7 @@ public class MultiMapTest @Test public void testContainsValue_LazyList() { - MultiMap mm = new MultiMap(); + MultiMap mm = new MultiMap<>(); mm.putValues("food","apple","cherry","raspberry"); mm.put("color","red"); mm.putValues("amount","bushel","pint"); @@ -521,7 +557,7 @@ public class MultiMapTest } } - private void assertValues(MultiMap mm, String key, Object... expectedValues) + private void assertValues(MultiMap mm, String key, Object... expectedValues) { List values = mm.getValues(key); @@ -539,7 +575,7 @@ public class MultiMapTest } } - private void assertNullValues(MultiMap mm, String key) + private void assertNullValues(MultiMap mm, String key) { List values = mm.getValues(key); @@ -548,7 +584,7 @@ public class MultiMapTest Assert.assertThat(prefix + ".size",values,nullValue()); } - private void assertEmptyValues(MultiMap mm, String key) + private void assertEmptyValues(MultiMap mm, String key) { List values = mm.getValues(key); @@ -557,7 +593,7 @@ public class MultiMapTest Assert.assertEquals(prefix + ".size",0,LazyList.size(values)); } - private void assertMapSize(MultiMap mm, int expectedSize) + private void assertMapSize(MultiMap mm, int expectedSize) { Assert.assertEquals("MultiMap.size",expectedSize,mm.size()); }