Code example for Comparator

Methods: compare

0
        return !equals(o1, o2);
    } 
 
    public static boolean equals(Object o1, Object o2) {
        if (o1 instanceof JSONObject && o2 instanceof JSONObject) {
            return JSON_OBJECT_COMPARATOR.compare((JSONObject) o1, (JSONObject) o2) == 0;
        } 
        if (o1 instanceof JSONArray && o2 instanceof JSONArray) {
            return JSON_ARRAY_COMPARATOR.compare((JSONArray) o1, (JSONArray) o2) == 0;
        } 
        return o1 == null ? o2 == null : o1.equals(o2);
    } 
 
    public static JSONObject makeRandomJson() {
        try { 
            Random random = new Random();
            JSONObject json = new JSONObject();
            final int size = random.nextInt(20) + 5;
            for (int i = 0; i < size; i++) {
                json.put("id:" + i, random.nextInt(100000) + 500);
            }