20
20
import java .util .Arrays ;
21
21
import java .util .Collections ;
22
22
import java .util .HashSet ;
23
+ import java .util .LinkedHashMap ;
23
24
import java .util .List ;
24
25
import java .util .ListIterator ;
26
+ import java .util .Map ;
25
27
import java .util .Set ;
26
28
27
- import org .springframework .util .CollectionUtils ;
28
- import org .springframework .util .LinkedMultiValueMap ;
29
- import org .springframework .util .MultiValueMap ;
30
- import org .springframework .util .ObjectUtils ;
31
-
32
29
/**
33
30
* Configuration meta-data.
34
31
*
@@ -46,34 +43,34 @@ public class ConfigurationMetadata {
46
43
SEPARATORS = Collections .unmodifiableSet (new HashSet <Character >(chars ));
47
44
}
48
45
49
- private final MultiValueMap <String , ItemMetadata > items ;
46
+ private final Map <String , List < ItemMetadata > > items ;
50
47
51
- private final MultiValueMap <String , ItemHint > hints ;
48
+ private final Map <String , List < ItemHint > > hints ;
52
49
53
50
public ConfigurationMetadata () {
54
- this .items = new LinkedMultiValueMap <String , ItemMetadata >();
55
- this .hints = new LinkedMultiValueMap <String , ItemHint >();
51
+ this .items = new LinkedHashMap <String , List < ItemMetadata > >();
52
+ this .hints = new LinkedHashMap <String , List < ItemHint > >();
56
53
}
57
54
58
55
public ConfigurationMetadata (ConfigurationMetadata metadata ) {
59
- this .items = new LinkedMultiValueMap <String , ItemMetadata >(metadata .items );
60
- this .hints = new LinkedMultiValueMap <String , ItemHint >(metadata .hints );
56
+ this .items = new LinkedHashMap <String , List < ItemMetadata > >(metadata .items );
57
+ this .hints = new LinkedHashMap <String , List < ItemHint > >(metadata .hints );
61
58
}
62
59
63
60
/**
64
61
* Add item meta-data.
65
62
* @param itemMetadata the meta-data to add
66
63
*/
67
64
public void add (ItemMetadata itemMetadata ) {
68
- this .items . add ( itemMetadata .getName (), itemMetadata );
65
+ add ( this .items , itemMetadata .getName (), itemMetadata );
69
66
}
70
67
71
68
/**
72
69
* Add item hint.
73
70
* @param itemHint the item hint to add
74
71
*/
75
72
public void add (ItemHint itemHint ) {
76
- this .hints . add ( itemHint .getName (), itemHint );
73
+ add ( this .hints , itemHint .getName (), itemHint );
77
74
}
78
75
79
76
/**
@@ -131,13 +128,22 @@ protected void mergeItemMetadata(ItemMetadata metadata) {
131
128
}
132
129
}
133
130
else {
134
- this .items .add (metadata .getName (), metadata );
131
+ add (this .items , metadata .getName (), metadata );
132
+ }
133
+ }
134
+
135
+ private <K , V > void add (Map <K , List <V >> map , K key , V value ) {
136
+ List <V > values = map .get (key );
137
+ if (values == null ) {
138
+ values = new ArrayList <V >();
139
+ map .put (key , values );
135
140
}
141
+ values .add (value );
136
142
}
137
143
138
144
private ItemMetadata findMatchingItemMetadata (ItemMetadata metadata ) {
139
145
List <ItemMetadata > candidates = this .items .get (metadata .getName ());
140
- if (CollectionUtils .isEmpty (candidates )) {
146
+ if (candidates == null || candidates .isEmpty ()) {
141
147
return null ;
142
148
}
143
149
ListIterator <ItemMetadata > it = candidates .listIterator ();
@@ -150,14 +156,20 @@ private ItemMetadata findMatchingItemMetadata(ItemMetadata metadata) {
150
156
return candidates .get (0 );
151
157
}
152
158
for (ItemMetadata candidate : candidates ) {
153
- if (ObjectUtils .nullSafeEquals (candidate .getSourceType (),
154
- metadata .getSourceType ())) {
159
+ if (nullSafeEquals (candidate .getSourceType (), metadata .getSourceType ())) {
155
160
return candidate ;
156
161
}
157
162
}
158
163
return null ;
159
164
}
160
165
166
+ private boolean nullSafeEquals (Object o1 , Object o2 ) {
167
+ if (o1 == o2 ) {
168
+ return true ;
169
+ }
170
+ return o1 != null && o2 != null && o1 .equals (o2 );
171
+ }
172
+
161
173
public static String nestedPrefix (String prefix , String name ) {
162
174
String nestedPrefix = (prefix == null ? "" : prefix );
163
175
String dashedName = toDashedCase (name );
@@ -185,8 +197,7 @@ else if (Character.isUpperCase(current) && previous != null
185
197
return dashed .toString ().toLowerCase ();
186
198
}
187
199
188
- private static <T extends Comparable <T >> List <T > flattenValues (
189
- MultiValueMap <?, T > map ) {
200
+ private static <T extends Comparable <T >> List <T > flattenValues (Map <?, List <T >> map ) {
190
201
List <T > content = new ArrayList <T >();
191
202
for (List <T > values : map .values ()) {
192
203
content .addAll (values );
0 commit comments