Skip to content

Commit 3ffaf15

Browse files
committed
Removes the commons-collections dependency and changes the org.json:json dependency to the same version included with Android. This makes including this as a library in an Android project cleaner/easier.
1 parent 2d13407 commit 3ffaf15

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

pom.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,8 @@
5252
<dependency>
5353
<groupId>org.json</groupId>
5454
<artifactId>json</artifactId>
55-
<version>20090211</version>
55+
<version>20080701</version>
5656
</dependency>
57-
<dependency>
58-
<groupId>commons-collections</groupId>
59-
<artifactId>commons-collections</artifactId>
60-
<version>3.0</version>
61-
</dependency>
62-
6357
<dependency>
6458
<groupId>junit</groupId>
6559
<artifactId>junit</artifactId>

src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package org.skyscreamer.jsonassert.comparator;
22

3-
import org.apache.commons.collections.CollectionUtils;
43
import org.json.JSONArray;
54
import org.json.JSONException;
65
import org.json.JSONObject;
76
import org.skyscreamer.jsonassert.JSONCompareResult;
87

9-
import java.util.HashSet;
10-
import java.util.Map;
11-
import java.util.Set;
8+
import java.util.*;
129

1310
import static org.skyscreamer.jsonassert.comparator.JSONCompareUtil.*;
1411

@@ -94,10 +91,8 @@ protected void compareJSONArrayOfJsonObjects(String key, JSONArray expected, JSO
9491
}
9592

9693
protected void compareJSONArrayOfSimpleValues(String key, JSONArray expected, JSONArray actual, JSONCompareResult result) throws JSONException {
97-
@SuppressWarnings("unchecked")
98-
Map<Object, Integer> expectedCount = CollectionUtils.getCardinalityMap(jsonArrayToList(expected));
99-
@SuppressWarnings("unchecked")
100-
Map<Object, Integer> actualCount = CollectionUtils.getCardinalityMap(jsonArrayToList(actual));
94+
Map<Object, Integer> expectedCount = JSONCompareUtil.getCardinalityMap(jsonArrayToList(expected));
95+
Map<Object, Integer> actualCount = JSONCompareUtil.getCardinalityMap(jsonArrayToList(actual));
10196
for (Object o : expectedCount.keySet()) {
10297
if (!actualCount.containsKey(o)) {
10398
result.missing(key + "[]", o);

src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* Utility class that contains Json manipulation methods
1111
*/
1212
public final class JSONCompareUtil {
13+
private static Integer INTEGER_ONE = new Integer(1);
14+
1315
private JSONCompareUtil() {}
1416

1517
public static Map<Object,JSONObject> arrayOfJsonObjectToMap(JSONArray array, String uniqueKey) throws JSONException {
@@ -116,5 +118,16 @@ public static String formatUniqueKey(String key, String uniqueKey, Object value)
116118
return key + "[" + uniqueKey + "=" + value + "]";
117119
}
118120

119-
121+
public static <T> Map<T, Integer> getCardinalityMap(final Collection<T> coll) {
122+
Map count = new HashMap<T, Integer>();
123+
for (T item : coll) {
124+
Integer c = (Integer) (count.get(item));
125+
if (c == null) {
126+
count.put(item, INTEGER_ONE);
127+
} else {
128+
count.put(item, new Integer(c.intValue() + 1));
129+
}
130+
}
131+
return count;
132+
}
120133
}

0 commit comments

Comments
 (0)