1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.exoplatform.services.portletcache;
21
22 import java.util.Arrays;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.Iterator;
26 import java.util.Map;
27
28
29
30
31
32 class Util
33 {
34
35 static Map<String, String[]> clone(Map<String, String[]> map)
36 {
37 if (map.isEmpty())
38 {
39 return Collections.emptyMap();
40 }
41 Map<String, String[]> copy = new HashMap<String, String[]>(map);
42 for (Map.Entry<String, String[]> entry : copy.entrySet())
43 {
44 entry.setValue(entry.getValue().clone());
45 }
46 return copy;
47 }
48
49 static int hashCode(Map<String, String[]> map)
50 {
51 int hashCode = 0;
52 if (map.size() > 0)
53 {
54 for (Map.Entry<String, String[]> parameter : map.entrySet())
55 {
56 int parameterHashCode = parameter.getKey().hashCode();
57 for (String parameterValue : parameter.getValue())
58 {
59 parameterHashCode = parameterHashCode * 43 + parameterValue.hashCode();
60 }
61 hashCode = hashCode * 43 + parameterHashCode;
62 }
63 }
64 return hashCode;
65 }
66
67 static boolean equals(Map<String, String[]> map1, Map<String, String[]> map2)
68 {
69 if (map1.keySet().equals(map2.keySet()))
70 {
71 for (Map.Entry<String, String[]> parameter : map1.entrySet())
72 {
73 String[] thatParameterValues = map2.get(parameter.getKey());
74 if (thatParameterValues != null)
75 {
76 if (!Arrays.equals(parameter.getValue(), thatParameterValues))
77 {
78 return false;
79 }
80 }
81 }
82 return true;
83 }
84 return false;
85 }
86
87 static void toString(Map<String, String[]> map, StringBuilder sb)
88 {
89 sb.append('{');
90 for (Iterator<Map.Entry<String, String[]>> i = map.entrySet().iterator();i.hasNext();)
91 {
92 Map.Entry<String, String[]> entry = i.next();
93 sb.append(entry.getKey()).append('=').append('[');
94 String[] value = entry.getValue();
95 for (int j = 0;j < value.length;j++)
96 {
97 if (j > 0)
98 {
99 sb.append(',');
100 }
101 sb.append(value[j]);
102 }
103 sb.append(']');
104 if (i.hasNext())
105 {
106 sb.append(',');
107 }
108 }
109 sb.append('}');
110 }
111 }