Line | |
---|
1 | package de.mpiwg.itgroup.annotations.restlet.utils; |
---|
2 | |
---|
3 | import java.util.Comparator; |
---|
4 | |
---|
5 | import de.mpiwg.itgroup.annotations.Annotation; |
---|
6 | |
---|
7 | import org.json.JSONException; |
---|
8 | import org.json.JSONObject; |
---|
9 | |
---|
10 | public 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.