[OLINGO-659] Replaced Collection with List

This commit is contained in:
Michael Bolz 2015-08-14 13:49:29 +02:00
parent a739034f2f
commit 1984525384
4 changed files with 24 additions and 21 deletions

View File

@ -21,6 +21,7 @@ package org.apache.olingo.commons.api.http;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.Locale; import java.util.Locale;
/** /**
@ -183,7 +184,7 @@ public class HttpHeader {
public static final String ODATA_ENTITY_ID = "OData-EntityID"; public static final String ODATA_ENTITY_ID = "OData-EntityID";
private final String name; private final String name;
private final Collection<String> values; private final List<String> values;
/** /**
* Create header for given name * Create header for given name
@ -216,8 +217,8 @@ public class HttpHeader {
* Get all values for this header * Get all values for this header
* @return all header values * @return all header values
*/ */
public Collection<String> getValues() { public List<String> getValues() {
return Collections.unmodifiableCollection(values); return Collections.unmodifiableList(values);
} }
/** /**

View File

@ -22,6 +22,8 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -104,6 +106,21 @@ public class HttpHeaders {
return Collections.unmodifiableCollection(headers.values()); return Collections.unmodifiableCollection(headers.values());
} }
/**
* Get all headers with the according values.
*
* @return an unmodifiable Map of header names/values
*/
public Map<String, List<String>> getHeaderToValues() {
Map<String, List<String>> result = new HashMap<String, List<String>>();
Collection<HttpHeader> allHeaders = headers.values();
for (HttpHeader header : allHeaders) {
result.put(header.getName(), header.getValues());
}
return Collections.unmodifiableMap(result);
}
/** /**
* Get all header names. * Get all header names.
* *

View File

@ -20,9 +20,6 @@ package org.apache.olingo.server.api;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -124,14 +121,7 @@ public class ODataRequest {
* @return an unmodifiable Map of header names/values * @return an unmodifiable Map of header names/values
*/ */
public Map<String, List<String>> getAllHeaders() { public Map<String, List<String>> getAllHeaders() {
Collection<HttpHeader> allHeader = headers.getHeaders(); return headers.getHeaderToValues();
Map<String, List<String>> result = new HashMap<String, List<String>>();
for (HttpHeader httpHeader : allHeader) {
result.put(httpHeader.getName(), new ArrayList<String>(httpHeader.getValues()));
}
return Collections.unmodifiableMap(result);
} }
@ -241,7 +231,7 @@ public class ODataRequest {
/** /**
* Sets the HTTP protocol used * Sets the HTTP protocol used
* @param protocol * @param 2protocol
* @see #getProtocol() * @see #getProtocol()
*/ */
public void setProtocol(String protocol) { public void setProtocol(String protocol) {

View File

@ -97,12 +97,7 @@ public class ODataResponse {
* @return an unmodifiable Map of header names/values * @return an unmodifiable Map of header names/values
*/ */
public Map<String, List<String>> getAllHeaders() { public Map<String, List<String>> getAllHeaders() {
Map<String, List<String>> result = new HashMap<String, List<String>>(); return headers.getHeaderToValues();
Collection<HttpHeader> allHeaders = headers.getHeaders();
for (HttpHeader header : allHeaders) {
result.put(header.getName(), new ArrayList<String>(header.getValues()));
}
return Collections.unmodifiableMap(result);
} }
/** /**