source: AnnotationManagerN4J/src/main/java/de/mpiwg/itgroup/annotations/restlet/utils/JSONObjectComparator.java @ 28:f4ed2ed33e5b

Last change on this file since 28:f4ed2ed33e5b was 28:f4ed2ed33e5b, checked in by dwinter, 12 years ago

Restinterface zur Anzeige von Tags hinzugefuegt-

File size: 788 bytes
Line 
1package de.mpiwg.itgroup.annotations.restlet.utils;
2
3import java.util.Comparator;
4
5import de.mpiwg.itgroup.annotations.Annotation;
6
7import org.json.JSONException;
8import org.json.JSONObject;
9
10public class JSONObjectComparator implements Comparator<JSONObject>{
11   
12        private String attributeToSort;
13        public JSONObjectComparator(String attribute){
14                this.attributeToSort=attribute;
15        }
16       
17        public int compare( JSONObject a, JSONObject b ) {
18        // je quadratischer, desto grösser
19                String sortA;
20                try {
21                        sortA = a.getString(attributeToSort);
22                } catch (JSONException e) {
23                        sortA ="";
24                }
25                String sortB;
26                try {
27                        sortB = b.getString(attributeToSort);
28                } catch (JSONException e) {
29                        sortB="";
30                }
31       
32               
33        return sortA.compareToIgnoreCase(sortB);
34    }
35       
36 
37       
38}
Note: See TracBrowser for help on using the repository browser.