1 16 17 package org.springframework.mock.web; 18 19 import java.util.Collection ; 20 import java.util.Collections ; 21 import java.util.Iterator ; 22 import java.util.LinkedList ; 23 import java.util.List ; 24 import java.util.Map ; 25 26 import org.springframework.util.Assert; 27 import org.springframework.util.CollectionUtils; 28 29 36 class HeaderValueHolder { 37 38 private final List values = new LinkedList (); 39 40 41 public void setValue(Object value) { 42 this.values.clear(); 43 this.values.add(value); 44 } 45 46 public void addValue(Object value) { 47 this.values.add(value); 48 } 49 50 public void addValues(Collection values) { 51 this.values.addAll(values); 52 } 53 54 public void addValueArray(Object values) { 55 CollectionUtils.mergeArrayIntoCollection(values, this.values); 56 } 57 58 public List getValues() { 59 return Collections.unmodifiableList(this.values); 60 } 61 62 public Object getValue() { 63 return (!this.values.isEmpty() ? this.values.get(0) : null); 64 } 65 66 67 74 public static HeaderValueHolder getByName(Map headers, String name) { 75 Assert.notNull(name, "Header name must not be null"); 76 for (Iterator it = headers.keySet().iterator(); it.hasNext();) { 77 String headerName = (String ) it.next(); 78 if (headerName.equalsIgnoreCase(name)) { 79 return (HeaderValueHolder) headers.get(headerName); 80 } 81 } 82 return null; 83 } 84 85 } 86 | Popular Tags |