source: AnnotationManagerN4J/src/main/java/de/mpiwg/itgroup/annotations/restlet/utils/JSONObjectComparator.java @ 63:9f8c9611848a

Last change on this file since 63:9f8c9611848a was 63:9f8c9611848a, checked in by casties, 11 years ago

fixed bug with new rectangle shapes. added limit, offset and sortBy parameters to annotator/ and annotator/search.

File size: 1.1 KB
Line 
1package de.mpiwg.itgroup.annotations.restlet.utils;
2
3import java.util.Comparator;
4import java.util.List;
5
6import org.json.JSONException;
7import org.json.JSONObject;
8
9public class JSONObjectComparator implements Comparator<JSONObject>{
10   
11        private String attributeToSort;
12        public JSONObjectComparator(String attribute){
13                this.attributeToSort=attribute;
14        }
15       
16        public int compare( JSONObject a, JSONObject b ) {
17        // je quadratischer, desto grösser
18                String sortA;
19                try {
20                        sortA = a.getString(attributeToSort);
21                } catch (JSONException e) {
22                        sortA ="";
23                }
24                String sortB;
25                try {
26                        sortB = b.getString(attributeToSort);
27                } catch (JSONException e) {
28                        sortB="";
29                }
30       
31               
32        return sortA.compareToIgnoreCase(sortB);
33    }
34       
35        /**
36         * Sortiere array nach einem Parameter in den Annotationen
37         * @param results
38         * @return
39         */
40        public static void sortAnnotations(List<JSONObject> results,String attribute) {
41                JSONObjectComparator comp = new JSONObjectComparator(attribute);
42               
43               
44       
45                java.util.Collections.sort( results, comp);
46               
47               
48
49        }       
50       
51}
Note: See TracBrowser for help on using the repository browser.