forked from scribejava/scribejava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapUtils.java
More file actions
43 lines (36 loc) · 1.09 KB
/
MapUtils.java
File metadata and controls
43 lines (36 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package org.scribe.utils;
import java.util.*;
public class MapUtils
{
public static final Map<String, List<String>> sort(Map<String, List<String>> map)
{
Preconditions.checkNotNull(map, "Cannot sort a null object.");
Map<String, List<String>> sorted = new LinkedHashMap<String, List<String>>();
for (String key : getSortedKeys(map))
{
if(map.get(key).size() > 1)
{
Collections.sort(map.get(key));
}
sorted.put(key, map.get(key));
}
return sorted;
}
private static List<String> getSortedKeys(Map<String, List<String>> map)
{
List<String> keys = new ArrayList<String>(map.keySet());
Collections.sort(keys);
return keys;
}
@SuppressWarnings("unchecked")
public static final <T> Map<String, List<T>> toListMap(Map<String, T> map)
{
Preconditions.checkNotNull(map, "Cannot sort a null object.");
Map<String, List<T>> result = new HashMap<String, List<T>>();
for (Map.Entry<String, T> entry : map.entrySet())
{
result.put(entry.getKey(), Arrays.asList(entry.getValue()));
}
return result;
}
}