Skip to content

Commit 760cab8

Browse files
committed
refactored HTTP support into top-level package "org.springframework.http"; revised RestTemplate facility in package "org.springframework.web.client"
1 parent 882c195 commit 760cab8

File tree

71 files changed

+1299
-1318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1299
-1318
lines changed

org.springframework.core/src/main/java/org/springframework/util/DefaultMultiValueMap.java

Lines changed: 0 additions & 144 deletions
This file was deleted.
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*
2+
* Copyright 2002-2009 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.util;
18+
19+
import java.util.Collection;
20+
import java.util.LinkedHashMap;
21+
import java.util.LinkedList;
22+
import java.util.List;
23+
import java.util.Map;
24+
import java.util.Set;
25+
26+
/**
27+
* Simple implementation of {@link MultiValueMap} that wraps a plain {@code Map}
28+
* (by default a {@link LinkedHashMap}, storing multiple values in a {@link LinkedList}.
29+
*
30+
* <p>This Map implementation is generally not thread-safe. It is primarily designed
31+
* for data structures exposed from request objects, for use in a single thread only.
32+
*
33+
* @author Arjen Poutsma
34+
* @author Juergen Hoeller
35+
* @since 3.0
36+
*/
37+
public class LinkedMultiValueMap<K, V> implements MultiValueMap<K, V> {
38+
39+
private final Map<K, List<V>> targetMap;
40+
41+
42+
/**
43+
* Create a new SimpleMultiValueMap that wraps the given target Map.
44+
* @param wrappee the target Map to wrap
45+
*/
46+
public LinkedMultiValueMap() {
47+
this.targetMap = new LinkedHashMap<K, List<V>>();
48+
}
49+
50+
/**
51+
* Create a new SimpleMultiValueMap that wraps the given target Map.
52+
* <p>Note: The given Map will be used as active underlying Map.
53+
* Any changes in the underlying map will be reflected in the
54+
* MultiValueMap object, and vice versa.
55+
* @param targetMap the target Map to wrap
56+
*/
57+
public LinkedMultiValueMap(Map<K, List<V>> targetMap) {
58+
Assert.notNull(targetMap, "'targetMap' must not be null");
59+
this.targetMap = targetMap;
60+
}
61+
62+
// MultiValueMap implementation
63+
64+
public void add(K key, V value) {
65+
List<V> values = this.targetMap.get(key);
66+
if (values == null) {
67+
values = new LinkedList<V>();
68+
this.targetMap.put(key, values);
69+
}
70+
values.add(value);
71+
}
72+
73+
public V getFirst(K key) {
74+
List<V> values = this.targetMap.get(key);
75+
return (values != null ? values.get(0) : null);
76+
}
77+
78+
public void set(K key, V value) {
79+
List<V> values = new LinkedList<V>();
80+
values.add(value);
81+
this.targetMap.put(key, values);
82+
}
83+
84+
85+
// Map implementation
86+
87+
public int size() {
88+
return this.targetMap.size();
89+
}
90+
91+
public boolean isEmpty() {
92+
return this.targetMap.isEmpty();
93+
}
94+
95+
public boolean containsKey(Object key) {
96+
return this.targetMap.containsKey(key);
97+
}
98+
99+
public boolean containsValue(Object value) {
100+
return this.targetMap.containsValue(value);
101+
}
102+
103+
public List<V> get(Object key) {
104+
return this.targetMap.get(key);
105+
}
106+
107+
public List<V> put(K key, List<V> value) {
108+
return this.targetMap.put(key, value);
109+
}
110+
111+
public List<V> remove(Object key) {
112+
return this.targetMap.remove(key);
113+
}
114+
115+
public void putAll(Map<? extends K, ? extends List<V>> m) {
116+
this.targetMap.putAll(m);
117+
}
118+
119+
public void clear() {
120+
this.targetMap.clear();
121+
}
122+
123+
public Set<K> keySet() {
124+
return this.targetMap.keySet();
125+
}
126+
127+
public Collection<List<V>> values() {
128+
return this.targetMap.values();
129+
}
130+
131+
public Set<Entry<K, List<V>>> entrySet() {
132+
return this.targetMap.entrySet();
133+
}
134+
135+
@Override
136+
public boolean equals(Object obj) {
137+
return this.targetMap.equals(obj);
138+
}
139+
140+
@Override
141+
public int hashCode() {
142+
return this.targetMap.hashCode();
143+
}
144+
145+
@Override
146+
public String toString() {
147+
return this.targetMap.toString();
148+
}
149+
150+
}

org.springframework.core/src/main/java/org/springframework/util/MultiValueMap.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,22 @@
2828
public interface MultiValueMap<K, V> extends Map<K, List<V>> {
2929

3030
/**
31-
* Adds the given single value to the current list of values for the given key.
32-
*
33-
* @param key the key
34-
* @param value the value to be added
31+
* Return the first value for the given key.
32+
* @param key the key
33+
* @return the first value for the specified key, or <code>null</code>
3534
*/
36-
void add(K key, V value);
35+
V getFirst(K key);
3736

3837
/**
39-
* Returns the first value for the given key.
40-
*
38+
* Add the given single value to the current list of values for the given key.
4139
* @param key the key
42-
* @return the first value for the specified key, or <code>null</code>
40+
* @param value the value to be added
4341
*/
44-
V getFirst(K key);
42+
void add(K key, V value);
4543

4644
/**
47-
* Sets the given single value under the given key.
48-
*
49-
* @param key the key
45+
* Set the given single value under the given key.
46+
* @param key the key
5047
* @param value the value to set
5148
*/
5249
void set(K key, V value);

org.springframework.core/src/test/java/org/springframework/util/DefaultMultiValueMapTests.java renamed to org.springframework.core/src/test/java/org/springframework/util/LinkedMultiValueMapTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
/**
3030
* @author Arjen Poutsma
3131
*/
32-
public class DefaultMultiValueMapTests {
32+
public class LinkedMultiValueMapTests {
3333

34-
private DefaultMultiValueMap<String, String> map;
34+
private LinkedMultiValueMap<String, String> map;
3535

3636
@Before
3737
public void setUp() {
38-
map = new DefaultMultiValueMap<String, String>();
38+
map = new LinkedMultiValueMap<String, String>();
3939
}
4040

4141
@Test
@@ -71,7 +71,7 @@ public void set() {
7171
public void equals() {
7272
map.set("key1", "value1");
7373
assertEquals(map, map);
74-
MultiValueMap<String, String> o1 = new DefaultMultiValueMap<String, String>();
74+
MultiValueMap<String, String> o1 = new LinkedMultiValueMap<String, String>();
7575
o1.set("key1", "value1");
7676
assertEquals(map, o1);
7777
assertEquals(o1, map);
@@ -80,4 +80,5 @@ public void equals() {
8080
assertEquals(map, o2);
8181
assertEquals(o2, map);
8282
}
83+
8384
}

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import org.springframework.core.io.Resource;
4040
import org.springframework.util.Assert;
4141
import org.springframework.util.ClassUtils;
42-
import org.springframework.util.MediaType;
42+
import org.springframework.http.MediaType;
4343
import org.springframework.util.StringUtils;
4444
import org.springframework.web.context.request.RequestAttributes;
4545
import org.springframework.web.context.request.RequestContextHolder;

org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolverTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.junit.Test;
2929

3030
import org.springframework.mock.web.MockHttpServletRequest;
31-
import org.springframework.util.MediaType;
31+
import org.springframework.http.MediaType;
3232
import org.springframework.web.context.request.RequestContextHolder;
3333
import org.springframework.web.context.request.ServletRequestAttributes;
3434
import org.springframework.web.servlet.View;

0 commit comments

Comments
 (0)